| OLD | NEW |
| 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_field_trial.h" | 5 #include "chrome/browser/prerender/prerender_field_trial.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/metrics/field_trial.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" | 9 #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" | 10 #include "chrome/common/chrome_switches.h" |
| 16 | 11 |
| 17 using std::string; | |
| 18 | |
| 19 namespace prerender { | 12 namespace prerender { |
| 20 | 13 |
| 21 namespace { | |
| 22 | |
| 23 const char kDefaultPrerenderServiceURLPrefix[] = | |
| 24 "https://clients4.google.com/prerenderservice/?q="; | |
| 25 const int kDefaultPrerenderServiceTimeoutMs = 1000; | |
| 26 const int kDefaultPrefetchListTimeoutSeconds = 300; | |
| 27 | |
| 28 } // end namespace | |
| 29 | |
| 30 void ConfigurePrerender(const base::CommandLine& command_line) { | 14 void ConfigurePrerender(const base::CommandLine& command_line) { |
| 31 PrerenderManager::PrerenderManagerMode mode = | 15 PrerenderManager::PrerenderManagerMode mode = |
| 32 PrerenderManager::PRERENDER_MODE_ENABLED; | 16 PrerenderManager::PRERENDER_MODE_ENABLED; |
| 33 if (command_line.HasSwitch(switches::kPrerenderMode)) { | 17 if (command_line.HasSwitch(switches::kPrerenderMode)) { |
| 34 const string switch_value = | 18 const std::string switch_value = |
| 35 command_line.GetSwitchValueASCII(switches::kPrerenderMode); | 19 command_line.GetSwitchValueASCII(switches::kPrerenderMode); |
| 36 | 20 |
| 37 if (switch_value == switches::kPrerenderModeSwitchValueDisabled) { | 21 if (switch_value == switches::kPrerenderModeSwitchValueDisabled) { |
| 38 mode = PrerenderManager::PRERENDER_MODE_DISABLED; | 22 mode = PrerenderManager::PRERENDER_MODE_DISABLED; |
| 39 } else if (switch_value.empty() || | 23 } else if (switch_value.empty() || |
| 40 switch_value == switches::kPrerenderModeSwitchValueEnabled) { | 24 switch_value == switches::kPrerenderModeSwitchValueEnabled) { |
| 41 // The empty string means the option was provided with no value, and that | 25 // The empty string means the option was provided with no value, and that |
| 42 // means enable. | 26 // means enable. |
| 43 mode = PrerenderManager::PRERENDER_MODE_ENABLED; | 27 mode = PrerenderManager::PRERENDER_MODE_ENABLED; |
| 44 } else { | 28 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 bool IsOmniboxEnabled(Profile* profile) { | 39 bool IsOmniboxEnabled(Profile* profile) { |
| 56 if (!profile) | 40 if (!profile) |
| 57 return false; | 41 return false; |
| 58 | 42 |
| 59 if (!PrerenderManager::IsPrerenderingPossible()) | 43 if (!PrerenderManager::IsPrerenderingPossible()) |
| 60 return false; | 44 return false; |
| 61 | 45 |
| 62 // Override any field trial groups if the user has set a command line flag. | 46 // Override any field trial groups if the user has set a command line flag. |
| 63 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 47 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 64 switches::kPrerenderFromOmnibox)) { | 48 switches::kPrerenderFromOmnibox)) { |
| 65 const string switch_value = | 49 const std::string switch_value = |
| 66 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 50 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 67 switches::kPrerenderFromOmnibox); | 51 switches::kPrerenderFromOmnibox); |
| 68 | 52 |
| 69 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) | 53 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueEnabled) |
| 70 return true; | 54 return true; |
| 71 | 55 |
| 72 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) | 56 if (switch_value == switches::kPrerenderFromOmniboxSwitchValueDisabled) |
| 73 return false; | 57 return false; |
| 74 | 58 |
| 75 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value); | 59 DCHECK_EQ(switches::kPrerenderFromOmniboxSwitchValueAuto, switch_value); |
| 76 } | 60 } |
| 77 | 61 |
| 78 return (base::FieldTrialList::FindFullName("PrerenderFromOmnibox") != | 62 return (base::FieldTrialList::FindFullName("PrerenderFromOmnibox") != |
| 79 "OmniboxPrerenderDisabled"); | 63 "OmniboxPrerenderDisabled"); |
| 80 } | 64 } |
| 81 | 65 |
| 82 bool IsUnencryptedSyncEnabled(Profile* profile) { | 66 bool IsSideEffectFreeWhitelistEnabled() { |
| 83 ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()-> | |
| 84 GetForProfile(profile); | |
| 85 return service && service->GetOpenTabsUIDelegate() && | |
| 86 !service->EncryptEverythingEnabled(); | |
| 87 } | |
| 88 | |
| 89 // Indicates whether the Local Predictor is enabled based on field trial | |
| 90 // selection. | |
| 91 bool IsLocalPredictorEnabled() { | |
| 92 return false; | 67 return false; |
| 93 } | 68 } |
| 94 | 69 |
| 95 bool ShouldDisableLocalPredictorBasedOnSyncAndConfiguration(Profile* profile) { | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 bool ShouldDisableLocalPredictorDueToPreferencesAndNetwork(Profile* profile) { | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 bool IsLoggedInPredictorEnabled() { | |
| 104 return IsLocalPredictorEnabled(); | |
| 105 } | |
| 106 | |
| 107 bool IsSideEffectFreeWhitelistEnabled() { | |
| 108 return IsLocalPredictorEnabled(); | |
| 109 } | |
| 110 | |
| 111 bool IsLocalPredictorPrerenderLaunchEnabled() { | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool IsLocalPredictorPrerenderAlwaysControlEnabled() { | |
| 116 // If we prefetch rather than prerender, we automatically also prerender | |
| 117 // as a control group only. | |
| 118 return IsLocalPredictorPrerenderPrefetchEnabled(); | |
| 119 } | |
| 120 | |
| 121 bool IsLocalPredictorPrerenderPrefetchEnabled() { | |
| 122 return false; | |
| 123 } | |
| 124 | |
| 125 bool ShouldQueryPrerenderService(Profile* profile) { | |
| 126 return false; | |
| 127 } | |
| 128 | |
| 129 bool ShouldQueryPrerenderServiceForCurrentURL() { | |
| 130 return true; | |
| 131 } | |
| 132 | |
| 133 bool ShouldQueryPrerenderServiceForCandidateURLs() { | |
| 134 return true; | |
| 135 } | |
| 136 | |
| 137 string GetPrerenderServiceURLPrefix() { | |
| 138 return kDefaultPrerenderServiceURLPrefix; | |
| 139 } | |
| 140 | |
| 141 int GetPrerenderServiceBehaviorID() { | |
| 142 return 0; | |
| 143 } | |
| 144 | |
| 145 int GetPrerenderServiceFetchTimeoutMs() { | |
| 146 return kDefaultPrerenderServiceTimeoutMs; | |
| 147 } | |
| 148 | |
| 149 int GetPrerenderPrefetchListTimeoutSeconds() { | |
| 150 return kDefaultPrefetchListTimeoutSeconds; | |
| 151 } | |
| 152 | |
| 153 int GetLocalPredictorTTLSeconds() { | |
| 154 // Use a default value of 180s. | |
| 155 return 180; | |
| 156 } | |
| 157 | |
| 158 int GetLocalPredictorPrerenderPriorityHalfLifeTimeSeconds() { | |
| 159 return 0; | |
| 160 } | |
| 161 | |
| 162 int GetLocalPredictorMaxConcurrentPrerenders() { | |
| 163 return 1; | |
| 164 } | |
| 165 | |
| 166 int GetLocalPredictorMaxLaunchPrerenders() { | |
| 167 return 1; | |
| 168 } | |
| 169 | |
| 170 bool SkipLocalPredictorFragment() { | |
| 171 return false; | |
| 172 } | |
| 173 | |
| 174 bool SkipLocalPredictorHTTPS() { | |
| 175 return false; | |
| 176 } | |
| 177 | |
| 178 bool SkipLocalPredictorWhitelist() { | |
| 179 return false; | |
| 180 } | |
| 181 | |
| 182 bool SkipLocalPredictorServiceWhitelist() { | |
| 183 return false; | |
| 184 } | |
| 185 | |
| 186 bool SkipLocalPredictorLoggedIn() { | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 bool SkipLocalPredictorDefaultNoPrerender() { | |
| 191 return false; | |
| 192 } | |
| 193 | |
| 194 bool SkipLocalPredictorLocalCandidates() { | |
| 195 return false; | |
| 196 } | |
| 197 | |
| 198 bool SkipLocalPredictorServiceCandidates() { | |
| 199 return false; | |
| 200 } | |
| 201 | |
| 202 } // namespace prerender | 70 } // namespace prerender |
| OLD | NEW |