Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/prerender/prerender_manager.cc

Issue 2275933002: Experiment to disable Prerendering with fast wind-down (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove FRIEND_TEST_ALL_PREFIXES Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/prerender/prerender_manager.h" 5 #include "chrome/browser/prerender/prerender_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/location.h" 17 #include "base/location.h"
18 #include "base/logging.h" 18 #include "base/logging.h"
19 #include "base/macros.h" 19 #include "base/macros.h"
20 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
21 #include "base/metrics/field_trial.h"
21 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
22 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
23 #include "base/sys_info.h" 24 #include "base/sys_info.h"
24 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
25 #include "base/time/time.h" 26 #include "base/time/time.h"
26 #include "base/timer/elapsed_timer.h" 27 #include "base/timer/elapsed_timer.h"
27 #include "base/values.h" 28 #include "base/values.h"
28 #include "chrome/browser/chrome_notification_types.h" 29 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/net/prediction_options.h" 30 #include "chrome/browser/net/prediction_options.h"
30 #include "chrome/browser/prerender/prerender_contents.h" 31 #include "chrome/browser/prerender/prerender_contents.h"
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 // those prerenders is managed by the offliner. 876 // those prerenders is managed by the offliner.
876 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE) 877 if (IsLowEndDevice() && origin != ORIGIN_OFFLINE)
877 return nullptr; 878 return nullptr;
878 879
879 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN || 880 if ((origin == ORIGIN_LINK_REL_PRERENDER_CROSSDOMAIN ||
880 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) && 881 origin == ORIGIN_LINK_REL_PRERENDER_SAMEDOMAIN) &&
881 IsGoogleSearchResultURL(referrer.url)) { 882 IsGoogleSearchResultURL(referrer.url)) {
882 origin = ORIGIN_GWS_PRERENDER; 883 origin = ORIGIN_GWS_PRERENDER;
883 } 884 }
884 885
886 if (IsPrerenderSilenceExperiment(origin))
887 return nullptr;
888
885 GURL url = url_arg; 889 GURL url = url_arg;
886 GURL alias_url; 890 GURL alias_url;
887 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url)) 891 if (IsControlGroup() && MaybeGetQueryStringBasedAliasURL(url, &alias_url))
888 url = alias_url; 892 url = alias_url;
889 893
890 // From here on, we will record a FinalStatus so we need to register with the 894 // From here on, we will record a FinalStatus so we need to register with the
891 // histogram tracking. 895 // histogram tracking.
892 histograms_->RecordPrerender(origin, url_arg); 896 histograms_->RecordPrerender(origin, url_arg);
893 897
894 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) && 898 if (profile_->GetPrefs()->GetBoolean(prefs::kBlockThirdPartyCookies) &&
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 if (!ActuallyPrerendering()) 1237 if (!ActuallyPrerendering())
1234 return; 1238 return;
1235 int64_t recent_profile_bytes = 1239 int64_t recent_profile_bytes =
1236 profile_network_bytes_ - last_recorded_profile_network_bytes_; 1240 profile_network_bytes_ - last_recorded_profile_network_bytes_;
1237 last_recorded_profile_network_bytes_ = profile_network_bytes_; 1241 last_recorded_profile_network_bytes_ = profile_network_bytes_;
1238 DCHECK_GE(recent_profile_bytes, 0); 1242 DCHECK_GE(recent_profile_bytes, 0);
1239 histograms_->RecordNetworkBytes( 1243 histograms_->RecordNetworkBytes(
1240 origin, used, prerender_bytes, recent_profile_bytes); 1244 origin, used, prerender_bytes, recent_profile_bytes);
1241 } 1245 }
1242 1246
1247 bool PrerenderManager::IsPrerenderSilenceExperiment(Origin origin) const {
1248 if (origin == ORIGIN_OFFLINE)
1249 return false;
1250
1251 // The group name should contain expiration time formatted as:
1252 // "ExperimentYes_expires_YYYY-MM-DDTHH:MM:SSZ".
1253 std::string group_name =
1254 base::FieldTrialList::FindFullName("PrerenderSilence");
1255 const char kExperimentPrefix[] = "ExperimentYes";
1256 if (!base::StartsWith(group_name, kExperimentPrefix,
1257 base::CompareCase::INSENSITIVE_ASCII)) {
1258 return false;
1259 }
1260 const char kExperimentPrefixWithExpiration[] = "ExperimentYes_expires_";
1261 if (!base::StartsWith(group_name, kExperimentPrefixWithExpiration,
1262 base::CompareCase::INSENSITIVE_ASCII)) {
1263 // Without expiration day in the group name, behave as a normal experiment,
1264 // i.e. sticky to the Chrome session.
1265 return true;
1266 }
1267 base::Time expiration_time;
1268 if (!base::Time::FromString(
1269 group_name.c_str() + (arraysize(kExperimentPrefixWithExpiration) - 1),
1270 &expiration_time)) {
1271 DLOG(ERROR) << "Could not parse expiration date in group: " << group_name;
1272 return false;
1273 }
1274 return GetCurrentTime() < expiration_time;
1275 }
1276
1243 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const { 1277 NetworkPredictionStatus PrerenderManager::GetPredictionStatus() const {
1244 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1278 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1245 return CanPrefetchAndPrerenderUI(profile_->GetPrefs()); 1279 return CanPrefetchAndPrerenderUI(profile_->GetPrefs());
1246 } 1280 }
1247 1281
1248 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin( 1282 NetworkPredictionStatus PrerenderManager::GetPredictionStatusForOrigin(
1249 Origin origin) const { 1283 Origin origin) const {
1250 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1284 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1251 1285
1252 // <link rel=prerender> origins ignore the network state and the privacy 1286 // <link rel=prerender> origins ignore the network state and the privacy
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 DCHECK_EQ(1u, erased); 1341 DCHECK_EQ(1u, erased);
1308 } 1342 }
1309 1343
1310 void PrerenderManager::SetPrerenderContentsFactoryForTest( 1344 void PrerenderManager::SetPrerenderContentsFactoryForTest(
1311 PrerenderContents::Factory* prerender_contents_factory) { 1345 PrerenderContents::Factory* prerender_contents_factory) {
1312 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1346 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1313 prerender_contents_factory_.reset(prerender_contents_factory); 1347 prerender_contents_factory_.reset(prerender_contents_factory);
1314 } 1348 }
1315 1349
1316 } // namespace prerender 1350 } // namespace prerender
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698