Chromium Code Reviews| 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/ui/search/search.h" | 5 #include "chrome/browser/ui/search/search.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/string_split.h" | 9 #include "base/string_split.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Configuration options for Embedded Search. | 24 // Configuration options for Embedded Search. |
| 25 // InstantExtended field trials are named in such a way that we can parse out | 25 // InstantExtended field trials are named in such a way that we can parse out |
| 26 // the experiment configuration from the trial's group name in order to give | 26 // the experiment configuration from the trial's group name in order to give |
| 27 // us maximum flexability in running experiments. | 27 // us maximum flexability in running experiments. |
| 28 // Field trial groups should be named things like "Group7 espv:2 instant:1". | 28 // Field trial groups should be named things like "Group7 espv:2 instant:1". |
| 29 // The first token is always GroupN for some integer N, followed by a | 29 // The first token is always GroupN for some integer N, followed by a |
| 30 // space-delimited list of key:value pairs which correspond to these flags: | 30 // space-delimited list of key:value pairs which correspond to these flags: |
| 31 const char kEmbeddedPageVersionFlagName[] = "espv"; | 31 const char kEmbeddedPageVersionFlagName[] = "espv"; |
| 32 | |
| 33 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 34 const int kEmbeddedPageVersionDefault = 1; | |
| 35 #else | |
| 32 const int kEmbeddedPageVersionDefault = 2; | 36 const int kEmbeddedPageVersionDefault = 2; |
| 37 #endif | |
| 33 | 38 |
| 34 const char kInstantExtendedActivationName[] = "instant"; | 39 const char kInstantExtendedActivationName[] = "instant"; |
| 35 const chrome::search::InstantExtendedDefault kInstantExtendedActivationDefault = | 40 const chrome::search::InstantExtendedDefault kInstantExtendedActivationDefault = |
| 36 chrome::search::INSTANT_DEFAULT_ON; | 41 chrome::search::INSTANT_DEFAULT_ON; |
| 37 | 42 |
| 38 // Constants for the field trial name and group prefix. | 43 // Constants for the field trial name and group prefix. |
| 39 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; | 44 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; |
| 40 const char kGroupNumberPrefix[] = "Group"; | 45 const char kGroupNumberPrefix[] = "Group"; |
| 41 | 46 |
| 42 // If the field trial's group name ends with this string its configuration will | 47 // If the field trial's group name ends with this string its configuration will |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 kInstantExtendedActivationName, | 136 kInstantExtendedActivationName, |
| 132 kInstantExtendedActivationDefault, | 137 kInstantExtendedActivationDefault, |
| 133 flags); | 138 flags); |
| 134 return InstantExtendedDefaultFromInt64(trial_default); | 139 return InstantExtendedDefaultFromInt64(trial_default); |
| 135 } | 140 } |
| 136 | 141 |
| 137 return kInstantExtendedActivationDefault; | 142 return kInstantExtendedActivationDefault; |
| 138 } | 143 } |
| 139 | 144 |
| 140 bool IsInstantExtendedAPIEnabled(const Profile* profile) { | 145 bool IsInstantExtendedAPIEnabled(const Profile* profile) { |
| 146 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 147 return false; | |
| 148 #else | |
| 141 return EmbeddedSearchPageVersion(profile) != 0; | 149 return EmbeddedSearchPageVersion(profile) != 0; |
| 150 #endif // defined(OS_IOS) || defined(OS_ANDROID) | |
|
sreeram
2013/03/02 00:16:18
Nit: I meant two spaces _before_ the "//", not aft
Yusuf
2013/03/02 00:26:29
:) Sorry about that.Fixed now.
On 2013/03/02 00:1
| |
| 142 } | 151 } |
| 143 | 152 |
| 144 // Determine what embedded search page version to request from the user's | 153 // Determine what embedded search page version to request from the user's |
| 145 // default search provider. If 0, the embedded search UI should not be enabled. | 154 // default search provider. If 0, the embedded search UI should not be enabled. |
| 146 uint64 EmbeddedSearchPageVersion(const Profile* profile) { | 155 uint64 EmbeddedSearchPageVersion(const Profile* profile) { |
| 156 #if defined(OS_IOS) || defined(OS_ANDROID) | |
| 157 const CommandLine* cl = CommandLine::ForCurrentProcess(); | |
| 158 if (cl->HasSwitch(switches::kEnableQueryExtraction)) | |
| 159 return kEmbeddedPageVersionDefault; | |
| 160 #else | |
| 147 if (!profile || profile->IsOffTheRecord()) | 161 if (!profile || profile->IsOffTheRecord()) |
| 148 return 0; | 162 return 0; |
| 149 | 163 |
| 150 FieldTrialFlags flags; | 164 FieldTrialFlags flags; |
| 151 if (GetFieldTrialInfo( | 165 if (GetFieldTrialInfo( |
| 152 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), | 166 base::FieldTrialList::FindFullName(kInstantExtendedFieldTrialName), |
| 153 &flags, NULL)) { | 167 &flags, NULL)) { |
| 154 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, | 168 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, |
| 155 kEmbeddedPageVersionDefault, | 169 kEmbeddedPageVersionDefault, |
| 156 flags); | 170 flags); |
| 157 } | 171 } |
| 158 | 172 |
| 159 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 173 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 160 if (cl->HasSwitch(switches::kEnableInstantExtendedAPI)) { | 174 if (cl->HasSwitch(switches::kEnableInstantExtendedAPI)) { |
| 161 // The user has manually flipped the about:flags switch - give the default | 175 // The user has manually flipped the about:flags switch - give the default |
| 162 // UI version. | 176 // UI version. |
| 163 return kEmbeddedPageVersionDefault; | 177 return kEmbeddedPageVersionDefault; |
| 164 } | 178 } |
| 165 | 179 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 166 return 0; | 180 return 0; |
| 167 } | 181 } |
| 168 | 182 |
| 169 bool IsQueryExtractionEnabled(const Profile* profile) { | 183 bool IsQueryExtractionEnabled(const Profile* profile) { |
| 170 #if defined(OS_IOS) | 184 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 171 const CommandLine* cl = CommandLine::ForCurrentProcess(); | 185 const CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 172 return cl->HasSwitch(switches::kEnableQueryExtraction); | 186 return cl->HasSwitch(switches::kEnableQueryExtraction); |
| 173 #else | 187 #else |
| 174 // On desktop, query extraction is controlled by the instant-extended-api | 188 // On desktop, query extraction is controlled by the instant-extended-api |
| 175 // flag. | 189 // flag. |
| 176 return IsInstantExtendedAPIEnabled(profile); | 190 return IsInstantExtendedAPIEnabled(profile); |
| 177 #endif | 191 #endif // defined(OS_IOS) || defined(OS_ANDROID) |
| 178 } | 192 } |
| 179 | 193 |
| 180 string16 GetSearchTermsFromNavigationEntry( | 194 string16 GetSearchTermsFromNavigationEntry( |
| 181 const content::NavigationEntry* entry) { | 195 const content::NavigationEntry* entry) { |
| 182 string16 search_terms; | 196 string16 search_terms; |
| 183 if (entry) | 197 if (entry) |
| 184 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); | 198 entry->GetExtraData(kInstantExtendedSearchTermsKey, &search_terms); |
| 185 return search_terms; | 199 return search_terms; |
| 186 } | 200 } |
| 187 | 201 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 IsInstantExtendedAPIEnabled(profile), | 269 IsInstantExtendedAPIEnabled(profile), |
| 256 template_url); | 270 template_url); |
| 257 } | 271 } |
| 258 | 272 |
| 259 void EnableInstantExtendedAPIForTesting() { | 273 void EnableInstantExtendedAPIForTesting() { |
| 260 CommandLine* cl = CommandLine::ForCurrentProcess(); | 274 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 261 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); | 275 cl->AppendSwitch(switches::kEnableInstantExtendedAPI); |
| 262 } | 276 } |
| 263 | 277 |
| 264 void EnableQueryExtractionForTesting() { | 278 void EnableQueryExtractionForTesting() { |
| 265 #if defined(OS_IOS) | 279 #if defined(OS_IOS) || defined(OS_ANDROID) |
| 266 CommandLine* cl = CommandLine::ForCurrentProcess(); | 280 CommandLine* cl = CommandLine::ForCurrentProcess(); |
| 267 cl->AppendSwitch(switches::kEnableQueryExtraction); | 281 cl->AppendSwitch(switches::kEnableQueryExtraction); |
| 268 #else | 282 #else |
| 269 EnableInstantExtendedAPIForTesting(); | 283 EnableInstantExtendedAPIForTesting(); |
| 270 #endif | 284 #endif |
| 271 } | 285 } |
| 272 | 286 |
| 273 bool ShouldAssignURLToInstantRendererImpl(const GURL& url, | 287 bool ShouldAssignURLToInstantRendererImpl(const GURL& url, |
| 274 bool extended_api_enabled, | 288 bool extended_api_enabled, |
| 275 TemplateURL* template_url) { | 289 TemplateURL* template_url) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 // Given a FieldTrialFlags object, returns the boolean value of the provided | 379 // Given a FieldTrialFlags object, returns the boolean value of the provided |
| 366 // flag. | 380 // flag. |
| 367 bool GetBoolValueForFlagWithDefault(const std::string& flag, | 381 bool GetBoolValueForFlagWithDefault(const std::string& flag, |
| 368 bool default_value, | 382 bool default_value, |
| 369 const FieldTrialFlags& flags) { | 383 const FieldTrialFlags& flags) { |
| 370 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); | 384 return !!GetUInt64ValueForFlagWithDefault(flag, default_value ? 1 : 0, flags); |
| 371 } | 385 } |
| 372 | 386 |
| 373 } // namespace search | 387 } // namespace search |
| 374 } // namespace chrome | 388 } // namespace chrome |
| OLD | NEW |