diff options
author | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-09 20:29:36 +0000 |
---|---|---|
committer | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-09 20:29:36 +0000 |
commit | d68db3dceeb1a545aff1ea5db67d98271e266a4f (patch) | |
tree | d5d03c37d2f33e10ec44b5c4656360085dc80fe6 | |
parent | fd3f5aa7be219c9236d38a42185c3829f9f10759 (diff) | |
download | chromium_src-d68db3dceeb1a545aff1ea5db67d98271e266a4f.zip chromium_src-d68db3dceeb1a545aff1ea5db67d98271e266a4f.tar.gz chromium_src-d68db3dceeb1a545aff1ea5db67d98271e266a4f.tar.bz2 |
Add options to disable each of the two aspects of the prerender service
(current URL based hinting and candidate URL upload).
R=jam@chromium.org
Review URL: https://codereview.chromium.org/23506038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222082 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/prerender/prerender_field_trial.cc | 14 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_field_trial.h | 5 | ||||
-rw-r--r-- | chrome/browser/prerender/prerender_local_predictor.cc | 91 |
3 files changed, 70 insertions, 40 deletions
diff --git a/chrome/browser/prerender/prerender_field_trial.cc b/chrome/browser/prerender/prerender_field_trial.cc index d1a8ad3..94c7bcbc 100644 --- a/chrome/browser/prerender/prerender_field_trial.cc +++ b/chrome/browser/prerender/prerender_field_trial.cc @@ -47,6 +47,10 @@ const char kPrerenderLaunchKeyName[] = "PrerenderLaunch"; const char kPrerenderAlwaysControlKeyName[] = "PrerenderAlwaysControl"; const char kPrerenderQueryPrerenderServiceKeyName[] = "PrerenderQueryPrerenderService"; +const char kPrerenderQueryPrerenderServiceCurrentURLKeyName[] = + "PrerenderQueryPrerenderServiceCurrentURL"; +const char kPrerenderQueryPrerenderServiceCandidateURLsKeyName[] = + "PrerenderQueryPrerenderServiceCandidateURLs"; const char kPrerenderServiceBehaviorIDKeyName[] = "PrerenderServiceBehaviorID"; const char kPrerenderServiceFetchTimeoutKeyName[] = "PrerenderServiceFetchTimeoutMs"; @@ -373,6 +377,16 @@ bool ShouldQueryPrerenderService(Profile* profile) { kEnabledGroup; } +bool ShouldQueryPrerenderServiceForCurrentURL() { + return GetLocalPredictorSpecValue( + kPrerenderQueryPrerenderServiceCurrentURLKeyName) != kDisabledGroup; +} + +bool ShouldQueryPrerenderServiceForCandidateURLs() { + return GetLocalPredictorSpecValue( + kPrerenderQueryPrerenderServiceCandidateURLsKeyName) != kDisabledGroup; +} + string GetPrerenderServiceURLPrefix() { string prefix = chrome_variations::GetVariationParamValue( kLocalPredictorSpecTrialName, diff --git a/chrome/browser/prerender/prerender_field_trial.h b/chrome/browser/prerender/prerender_field_trial.h index 056fc9f..d19f067 100644 --- a/chrome/browser/prerender/prerender_field_trial.h +++ b/chrome/browser/prerender/prerender_field_trial.h @@ -42,6 +42,11 @@ bool IsLocalPredictorPrerenderAlwaysControlEnabled(); // provided. bool ShouldQueryPrerenderService(Profile* profile); +// Indicates whether we should query the prerender service for the current URL +// and candidate URLs, respectively. +bool ShouldQueryPrerenderServiceForCurrentURL(); +bool ShouldQueryPrerenderServiceForCandidateURLs(); + // Returns the URL prefix to be used for the prerender service. The only thing // that will be appended is the urlencoded query json. std::string GetPrerenderServiceURLPrefix(); diff --git a/chrome/browser/prerender/prerender_local_predictor.cc b/chrome/browser/prerender/prerender_local_predictor.cc index eea1230..32d64b5 100644 --- a/chrome/browser/prerender/prerender_local_predictor.cc +++ b/chrome/browser/prerender/prerender_local_predictor.cc @@ -642,7 +642,8 @@ void PrerenderLocalPredictor::DoPrerenderServiceCheck( DictionaryValue* req = new DictionaryValue(); req->SetInteger("version", 1); req->SetInteger("behavior_id", GetPrerenderServiceBehaviorID()); - if (info->source_url_.url_lookup_success) { + if (ShouldQueryPrerenderServiceForCurrentURL() && + info->source_url_.url_lookup_success) { ListValue* browse_history = new ListValue(); DictionaryValue* browse_item = new DictionaryValue(); browse_item->SetString("url", info->source_url_.url.spec()); @@ -656,7 +657,8 @@ void PrerenderLocalPredictor::DoPrerenderServiceCheck( if (info->candidate_urls_[i].url_lookup_success) num_candidate_urls++; } - if (num_candidate_urls > 0) { + if (ShouldQueryPrerenderServiceForCandidateURLs() && + num_candidate_urls > 0) { ListValue* candidates = new ListValue(); DictionaryValue* candidate; for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { @@ -757,8 +759,12 @@ bool PrerenderLocalPredictor::ApplyParsedPrerenderServiceResponse( } if (!dict->GetList("prerender_response.candidate_check_response.candidates", &list)) { - if (info->candidate_urls_.size() > 0) - return false; + if (ShouldQueryPrerenderServiceForCandidateURLs()) { + for (int i = 0; i < static_cast<int>(info->candidate_urls_.size()); i++) { + if (info->candidate_urls_[i].url_lookup_success) + return false; + } + } } else { for (size_t i = 0; i < list->GetSize(); i++) { DictionaryValue* d; @@ -791,47 +797,52 @@ bool PrerenderLocalPredictor::ApplyParsedPrerenderServiceResponse( } } for (size_t i = 0; i < info->candidate_urls_.size(); i++) { - if (!info->candidate_urls_[i].service_whitelist_reported) + if (info->candidate_urls_[i].url_lookup_success && + !info->candidate_urls_[i].service_whitelist_reported) { return false; + } } } - list = NULL; - if (dict->GetInteger("prerender_response.hint_response.hinting_timed_out", - &int_value) && - int_value == 1) { - *hinting_timed_out = true; - } else if (!dict->GetList("prerender_response.hint_response.candidates", - &list)) { - return false; - } else { - for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { - DictionaryValue* d; - if (!list->GetDictionary(i, &d)) - return false; - string url; - double priority; - if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) - || !GURL(url).is_valid()) { - return false; - } - int in_index_timed_out = 0; - int in_index = 0; - if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || - in_index_timed_out != 1) && - !d->GetInteger("in_index", &in_index)) { - return false; - } - if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || - in_index_timed_out < 0 || in_index_timed_out > 1) { - return false; + if (ShouldQueryPrerenderServiceForCurrentURL() && + info->source_url_.url_lookup_success) { + list = NULL; + if (dict->GetInteger("prerender_response.hint_response.hinting_timed_out", + &int_value) && + int_value == 1) { + *hinting_timed_out = true; + } else if (!dict->GetList("prerender_response.hint_response.candidates", + &list)) { + return false; + } else { + for (int i = 0; i < static_cast<int>(list->GetSize()); i++) { + DictionaryValue* d; + if (!list->GetDictionary(i, &d)) + return false; + string url; + double priority; + if (!d->GetString("url", &url) || !d->GetDouble("likelihood", &priority) + || !GURL(url).is_valid()) { + return false; + } + int in_index_timed_out = 0; + int in_index = 0; + if ((!d->GetInteger("in_index_timed_out", &in_index_timed_out) || + in_index_timed_out != 1) && + !d->GetInteger("in_index", &in_index)) { + return false; + } + if (priority < 0.0 || priority > 1.0 || in_index < 0 || in_index > 1 || + in_index_timed_out < 0 || in_index_timed_out > 1) { + return false; + } + if (in_index_timed_out == 1) + *hinting_url_lookup_timed_out = true; + info->MaybeAddCandidateURLFromService(GURL(url), + priority, + in_index == 1, + (1 - in_index_timed_out) == 1); } - if (in_index_timed_out == 1) - *hinting_url_lookup_timed_out = true; - info->MaybeAddCandidateURLFromService(GURL(url), - priority, - in_index == 1, - (1 - in_index_timed_out) == 1); } } |