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
3 // found in the LICENSE file.
5 #include "chrome/browser/prerender/prerender_field_trial.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/net/prediction_options.h"
10 #include "chrome/browser/predictors/autocomplete_action_predictor.h"
11 #include "chrome/browser/prerender/prerender_manager.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/sync/profile_sync_service.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/common/chrome_switches.h"
23 const char kDefaultPrerenderServiceURLPrefix
[] =
24 "https://clients4.google.com/prerenderservice/?q=";
25 const int kDefaultPrerenderServiceTimeoutMs
= 1000;
26 const int kDefaultPrefetchListTimeoutSeconds
= 300;
30 void ConfigurePrerender(const base::CommandLine
& command_line
) {
31 PrerenderManager::PrerenderManagerMode mode
=
32 PrerenderManager::PRERENDER_MODE_ENABLED
;
33 if (command_line
.HasSwitch(switches::kPrerenderMode
)) {
34 const string switch_value
=
35 command_line
.GetSwitchValueASCII(switches::kPrerenderMode
);
37 if (switch_value
== switches::kPrerenderModeSwitchValueDisabled
) {
38 mode
= PrerenderManager::PRERENDER_MODE_DISABLED
;
39 } else if (switch_value
.empty() ||
40 switch_value
== switches::kPrerenderModeSwitchValueEnabled
) {
41 // The empty string means the option was provided with no value, and that
43 mode
= PrerenderManager::PRERENDER_MODE_ENABLED
;
45 mode
= PrerenderManager::PRERENDER_MODE_DISABLED
;
46 LOG(ERROR
) << "Invalid --prerender option received on command line: "
48 LOG(ERROR
) << "Disabling prerendering!";
52 PrerenderManager::SetMode(mode
);
55 bool IsOmniboxEnabled(Profile
* profile
) {
59 if (!PrerenderManager::IsPrerenderingPossible())
62 // Override any field trial groups if the user has set a command line flag.
63 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
64 switches::kPrerenderFromOmnibox
)) {
65 const string switch_value
=
66 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
67 switches::kPrerenderFromOmnibox
);
69 if (switch_value
== switches::kPrerenderFromOmniboxSwitchValueEnabled
)
72 if (switch_value
== switches::kPrerenderFromOmniboxSwitchValueDisabled
)
75 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto
, switch_value
);
78 return (base::FieldTrialList::FindFullName("PrerenderFromOmnibox") !=
79 "OmniboxPrerenderDisabled");
82 bool IsUnencryptedSyncEnabled(Profile
* profile
) {
83 ProfileSyncService
* service
= ProfileSyncServiceFactory::GetInstance()->
84 GetForProfile(profile
);
85 return service
&& service
->GetOpenTabsUIDelegate() &&
86 !service
->EncryptEverythingEnabled();
89 // Indicates whether the Local Predictor is enabled based on field trial
91 bool IsLocalPredictorEnabled() {
95 bool ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(Profile
* profile
) {
99 bool ShouldDisableLocalPredictorDueToPreferencesAndNetwork(Profile
* profile
) {
103 bool IsLoggedInPredictorEnabled() {
104 return IsLocalPredictorEnabled();
107 bool IsSideEffectFreeWhitelistEnabled() {
108 return IsLocalPredictorEnabled();
111 bool IsLocalPredictorPrerenderLaunchEnabled() {
115 bool IsLocalPredictorPrerenderAlwaysControlEnabled() {
116 // If we prefetch rather than prerender, we automatically also prerender
117 // as a control group only.
118 return IsLocalPredictorPrerenderPrefetchEnabled();
121 bool IsLocalPredictorPrerenderPrefetchEnabled() {
125 bool ShouldQueryPrerenderService(Profile
* profile
) {
129 bool ShouldQueryPrerenderServiceForCurrentURL() {
133 bool ShouldQueryPrerenderServiceForCandidateURLs() {
137 string
GetPrerenderServiceURLPrefix() {
138 return kDefaultPrerenderServiceURLPrefix
;
141 int GetPrerenderServiceBehaviorID() {
145 int GetPrerenderServiceFetchTimeoutMs() {
146 return kDefaultPrerenderServiceTimeoutMs
;
149 int GetPrerenderPrefetchListTimeoutSeconds() {
150 return kDefaultPrefetchListTimeoutSeconds
;
153 int GetLocalPredictorTTLSeconds() {
154 // Use a default value of 180s.
158 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() {
162 int GetLocalPredictorMaxConcurrentPrerenders() {
166 int GetLocalPredictorMaxLaunchPrerenders() {
170 bool SkipLocalPredictorFragment() {
174 bool SkipLocalPredictorHTTPS() {
178 bool SkipLocalPredictorWhitelist() {
182 bool SkipLocalPredictorServiceWhitelist() {
186 bool SkipLocalPredictorLoggedIn() {
190 bool SkipLocalPredictorDefaultNoPrerender() {
194 bool SkipLocalPredictorLocalCandidates() {
198 bool SkipLocalPredictorServiceCandidates() {
202 } // namespace prerender