Index: chrome/browser/search/suggestions/suggestions_service.cc |
diff --git a/chrome/browser/search/suggestions/suggestions_service.cc b/chrome/browser/search/suggestions/suggestions_service.cc |
index f6c0d5fc1dadc1dfdf0bc96347414c3ef277ef82..3aaf75daa0b9ba6d4f83b7eecefe135db42c1429 100644 |
--- a/chrome/browser/search/suggestions/suggestions_service.cc |
+++ b/chrome/browser/search/suggestions/suggestions_service.cc |
@@ -15,6 +15,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "components/variations/variations_associated_data.h" |
#include "content/public/browser/browser_thread.h" |
+#include "net/base/escape.h" |
#include "net/base/load_flags.h" |
#include "net/base/net_errors.h" |
#include "net/http/http_response_headers.h" |
@@ -64,13 +65,20 @@ void DispatchRequestsAndClear( |
const char kSuggestionsFieldTrialName[] = "ChromeSuggestions"; |
const char kSuggestionsFieldTrialURLParam[] = "url"; |
+const char kSuggestionsFieldTrialSuggestionsSuffixParam[] = |
+ "suggestions_suffix"; |
+const char kSuggestionsFieldTrialBlacklistSuffixParam[] = "blacklist_suffix"; |
const char kSuggestionsFieldTrialStateParam[] = "state"; |
const char kSuggestionsFieldTrialStateEnabled[] = "enabled"; |
SuggestionsService::SuggestionsService(Profile* profile) |
: profile_(profile) { |
// Obtain the URL to use to fetch suggestions data from the Variations param. |
- suggestions_url_ = GURL(GetExperimentParam(kSuggestionsFieldTrialURLParam)); |
+ suggestions_url_ = GURL( |
+ GetExperimentParam(kSuggestionsFieldTrialURLParam) + |
+ GetExperimentParam(kSuggestionsFieldTrialSuggestionsSuffixParam)); |
+ blacklist_url_prefix_ = GetExperimentParam(kSuggestionsFieldTrialURLParam) + |
+ GetExperimentParam(kSuggestionsFieldTrialBlacklistSuffixParam); |
} |
SuggestionsService::~SuggestionsService() { |
@@ -96,21 +104,38 @@ void SuggestionsService::FetchSuggestionsData( |
DCHECK(waiting_requestors_.empty()); |
waiting_requestors_.push_back(callback); |
- pending_request_.reset(net::URLFetcher::Create( |
- 0, suggestions_url_, net::URLFetcher::GET, this)); |
- pending_request_->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
- pending_request_->SetRequestContext(profile_->GetRequestContext()); |
- // Add Chrome experiment state to the request headers. |
- net::HttpRequestHeaders headers; |
- chrome_variations::VariationsHttpHeaderProvider::GetInstance()-> |
- AppendHeaders(pending_request_->GetOriginalURL(), |
- profile_->IsOffTheRecord(), false, &headers); |
- pending_request_->SetExtraRequestHeaders(headers.ToString()); |
+ pending_request_.reset(CreateSuggestionsRequest(suggestions_url_)); |
pending_request_->Start(); |
last_request_started_time_ = base::TimeTicks::Now(); |
} |
+void SuggestionsService::AddBlacklistedURL( |
+ const std::string& candidate_url, |
+ SuggestionsService::ResponseCallback callback) { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ waiting_requestors_.push_back(callback); |
+ |
+ if (pending_request_.get()) { |
+ if (IsBlacklistRequest(pending_request_.get())) { |
+ // Pending request is a blacklist request. Silently drop the new blacklist |
+ // request. TODO - handle this case. |
+ return; |
+ } else { |
+ // Pending request is not a blacklist request - cancel it and go on to |
+ // issueing a blacklist request. |
Mathieu
2014/05/22 21:50:49
*issuing
manzagop (departed)
2014/05/23 15:20:02
Done.
|
+ pending_request_.reset(); |
+ } |
+ } |
+ |
+ // Send blacklisting request. |
+ GURL url(blacklist_url_prefix_ + |
+ net::EscapeQueryParamValue(candidate_url, true)); |
+ pending_request_.reset(CreateSuggestionsRequest(url)); |
+ pending_request_->Start(); |
+ last_request_started_time_ = base::TimeTicks::Now(); |
+} |
+ |
void SuggestionsService::OnURLFetchComplete(const net::URLFetcher* source) { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
DCHECK_EQ(pending_request_.get(), source); |
@@ -169,4 +194,25 @@ void SuggestionsService::Shutdown() { |
DispatchRequestsAndClear(SuggestionsProfile(), &waiting_requestors_); |
} |
+bool SuggestionsService::IsBlacklistRequest(net::URLFetcher* request) const { |
+ DCHECK(request); |
+ return StartsWithASCII(request->GetOriginalURL().spec(), |
+ blacklist_url_prefix_, |
+ true); |
+} |
+ |
+net::URLFetcher* SuggestionsService::CreateSuggestionsRequest(const GURL& url) { |
+ net::URLFetcher* request = net::URLFetcher::Create( |
+ 0, url, net::URLFetcher::GET, this); |
+ request->SetLoadFlags(net::LOAD_DISABLE_CACHE); |
+ request->SetRequestContext(profile_->GetRequestContext()); |
+ // Add Chrome experiment state to the request headers. |
+ net::HttpRequestHeaders headers; |
+ chrome_variations::VariationsHttpHeaderProvider::GetInstance()-> |
+ AppendHeaders(request->GetOriginalURL(), profile_->IsOffTheRecord(), |
+ false, &headers); |
+ request->SetExtraRequestHeaders(headers.ToString()); |
+ return request; |
+} |
+ |
} // namespace suggestions |