diff options
author | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-30 17:07:02 +0000 |
---|---|---|
committer | noamsml@chromium.org <noamsml@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-30 17:07:02 +0000 |
commit | cb8575a08f269e9befb79dcf4bfd0c52bdce13da (patch) | |
tree | 18a5b1a7b181c39f6f4e4054225a573c4d5052b4 | |
parent | 094e6185cfed07992b594c073c37a57adc4bd3cb (diff) | |
download | chromium_src-cb8575a08f269e9befb79dcf4bfd0c52bdce13da.zip chromium_src-cb8575a08f269e9befb79dcf4bfd0c52bdce13da.tar.gz chromium_src-cb8575a08f269e9befb79dcf4bfd0c52bdce13da.tar.bz2 |
Send an empty Privet token with /privet/info always
Always send an empty X-Privet-Token with /privet/info requests.
BUG=
Review URL: https://codereview.chromium.org/215573003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260437 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 37 insertions, 12 deletions
diff --git a/chrome/browser/local_discovery/privet_http_impl.cc b/chrome/browser/local_discovery/privet_http_impl.cc index aa345be..0adfcfe 100644 --- a/chrome/browser/local_discovery/privet_http_impl.cc +++ b/chrome/browser/local_discovery/privet_http_impl.cc @@ -97,7 +97,7 @@ void PrivetInfoOperationImpl::Start() { CreatePrivetURL(kPrivetInfoPath), net::URLFetcher::GET, this); url_fetcher_->DoNotRetryOnTransientError(); - url_fetcher_->AllowEmptyPrivetToken(); + url_fetcher_->SendEmptyPrivetToken(); url_fetcher_->Start(); } diff --git a/chrome/browser/local_discovery/privet_url_fetcher.cc b/chrome/browser/local_discovery/privet_url_fetcher.cc index 9782893..cb51955 100644 --- a/chrome/browser/local_discovery/privet_url_fetcher.cc +++ b/chrome/browser/local_discovery/privet_url_fetcher.cc @@ -72,7 +72,7 @@ PrivetURLFetcher::PrivetURLFetcher( request_context_(request_context), delegate_(delegate), do_not_retry_on_transient_error_(false), - allow_empty_privet_token_(false), + send_empty_privet_token_(false), has_byte_range_(false), make_response_file_(false), byte_range_start_(0), @@ -99,12 +99,16 @@ void PrivetURLFetcher::DoNotRetryOnTransientError() { do_not_retry_on_transient_error_ = true; } -void PrivetURLFetcher::AllowEmptyPrivetToken() { +void PrivetURLFetcher::SendEmptyPrivetToken() { DCHECK(tries_ == 0); - allow_empty_privet_token_ = true; + send_empty_privet_token_ = true; } std::string PrivetURLFetcher::GetPrivetAccessToken() { + if (send_empty_privet_token_) { + return std::string(); + } + TokenMapHolder* token_map_holder = TokenMapHolder::GetInstance(); TokenMap::iterator found = token_map_holder->map.find(GetHostString()); return found != token_map_holder->map.end() ? found->second : std::string(); @@ -173,12 +177,16 @@ void PrivetURLFetcher::Try() { void PrivetURLFetcher::Start() { DCHECK_EQ(tries_, 0); // We haven't called |Start()| yet. - std::string privet_access_token = GetPrivetAccessToken(); - if (privet_access_token.empty() && !allow_empty_privet_token_) { - RequestTokenRefresh(); - } else { - Try(); + if (!send_empty_privet_token_) { + std::string privet_access_token; + privet_access_token = GetPrivetAccessToken(); + if (privet_access_token.empty()) { + RequestTokenRefresh(); + return; + } } + + Try(); } void PrivetURLFetcher::SetUploadData(const std::string& upload_content_type, diff --git a/chrome/browser/local_discovery/privet_url_fetcher.h b/chrome/browser/local_discovery/privet_url_fetcher.h index 06874ec..2bb31fa 100644 --- a/chrome/browser/local_discovery/privet_url_fetcher.h +++ b/chrome/browser/local_discovery/privet_url_fetcher.h @@ -76,7 +76,7 @@ class PrivetURLFetcher : public net::URLFetcherDelegate { void DoNotRetryOnTransientError(); - void AllowEmptyPrivetToken(); + void SendEmptyPrivetToken(); // Set the contents of the Range header. |OnRawData| must return true if this // is called. @@ -116,7 +116,7 @@ class PrivetURLFetcher : public net::URLFetcherDelegate { Delegate* delegate_; bool do_not_retry_on_transient_error_; - bool allow_empty_privet_token_; + bool send_empty_privet_token_; bool has_byte_range_; bool make_response_file_; diff --git a/chrome/browser/local_discovery/privet_url_fetcher_unittest.cc b/chrome/browser/local_discovery/privet_url_fetcher_unittest.cc index 2737755..bfa78a7 100644 --- a/chrome/browser/local_discovery/privet_url_fetcher_unittest.cc +++ b/chrome/browser/local_discovery/privet_url_fetcher_unittest.cc @@ -209,7 +209,24 @@ TEST_F(PrivetURLFetcherTest, Header2) { PrivetURLFetcher::SetTokenForHost(GURL(kSamplePrivetURL).GetOrigin().spec(), ""); - privet_urlfetcher_->AllowEmptyPrivetToken(); + privet_urlfetcher_->SendEmptyPrivetToken(); + privet_urlfetcher_->Start(); + + net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); + ASSERT_TRUE(fetcher != NULL); + net::HttpRequestHeaders headers; + fetcher->GetExtraRequestHeaders(&headers); + + std::string header_token; + ASSERT_TRUE(headers.GetHeader("X-Privet-Token", &header_token)); + EXPECT_EQ(kEmptyPrivetToken, header_token); +} + +TEST_F(PrivetURLFetcherTest, AlwaysSendEmpty) { + PrivetURLFetcher::SetTokenForHost(GURL(kSamplePrivetURL).GetOrigin().spec(), + "SampleToken"); + + privet_urlfetcher_->SendEmptyPrivetToken(); privet_urlfetcher_->Start(); net::TestURLFetcher* fetcher = fetcher_factory_.GetFetcherByID(0); |