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

Side by Side Diff: components/search/search.cc

Issue 1551433002: Switch to standard integer types in components/, part 3 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 4 years, 12 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
« no previous file with comments | « components/search/search.h ('k') | components/search/search_switches.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/search/search.h" 5 #include "components/search/search.h"
6 6
7 #include <stddef.h>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h"
13 #include "components/google/core/browser/google_util.h" 16 #include "components/google/core/browser/google_util.h"
14 #include "components/search/search_switches.h" 17 #include "components/search/search_switches.h"
15 #include "components/search_engines/template_url.h" 18 #include "components/search_engines/template_url.h"
16 #include "url/gurl.h" 19 #include "url/gurl.h"
17 20
18 namespace search { 21 namespace search {
19 22
20 namespace { 23 namespace {
21 24
22 // Configuration options for Embedded Search. 25 // Configuration options for Embedded Search.
23 // EmbeddedSearch field trials are named in such a way that we can parse out 26 // EmbeddedSearch field trials are named in such a way that we can parse out
24 // the experiment configuration from the trial's group name in order to give 27 // the experiment configuration from the trial's group name in order to give
25 // us maximum flexability in running experiments. 28 // us maximum flexability in running experiments.
26 // Field trial groups should be named things like "Group7 espv:2 instant:1". 29 // Field trial groups should be named things like "Group7 espv:2 instant:1".
27 // The first token is always GroupN for some integer N, followed by a 30 // The first token is always GroupN for some integer N, followed by a
28 // space-delimited list of key:value pairs which correspond to these flags: 31 // space-delimited list of key:value pairs which correspond to these flags:
29 const char kEmbeddedPageVersionFlagName[] = "espv"; 32 const char kEmbeddedPageVersionFlagName[] = "espv";
30 33
31 #if defined(OS_IOS) 34 #if defined(OS_IOS)
32 const uint64 kEmbeddedPageVersionDefault = 1; 35 const uint64_t kEmbeddedPageVersionDefault = 1;
33 #elif defined(OS_ANDROID) 36 #elif defined(OS_ANDROID)
34 const uint64 kEmbeddedPageVersionDefault = 1; 37 const uint64_t kEmbeddedPageVersionDefault = 1;
35 // Use this variant to enable EmbeddedSearch SearchBox API in the results page. 38 // Use this variant to enable EmbeddedSearch SearchBox API in the results page.
36 const uint64 kEmbeddedSearchEnabledVersion = 2; 39 const uint64_t kEmbeddedSearchEnabledVersion = 2;
37 #else 40 #else
38 const uint64 kEmbeddedPageVersionDefault = 2; 41 const uint64_t kEmbeddedPageVersionDefault = 2;
39 #endif 42 #endif
40 43
41 // Constants for the field trial name and group prefix. 44 // Constants for the field trial name and group prefix.
42 // Note in M30 and below this field trial was named "InstantExtended" and in 45 // Note in M30 and below this field trial was named "InstantExtended" and in
43 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we 46 // M31 was renamed to EmbeddedSearch for clarity and cleanliness. Since we
44 // can't easilly sync up Finch configs with the pushing of this change to 47 // can't easilly sync up Finch configs with the pushing of this change to
45 // Dev & Canary, for now the code accepts both names. 48 // Dev & Canary, for now the code accepts both names.
46 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta 49 // TODO(dcblack): Remove the InstantExtended name once M31 hits the Beta
47 // channel. 50 // channel.
48 const char kInstantExtendedFieldTrialName[] = "InstantExtended"; 51 const char kInstantExtendedFieldTrialName[] = "InstantExtended";
(...skipping 27 matching lines...) Expand all
76 return false; 79 return false;
77 #elif defined(OS_ANDROID) 80 #elif defined(OS_ANDROID)
78 return EmbeddedSearchPageVersion() == kEmbeddedSearchEnabledVersion; 81 return EmbeddedSearchPageVersion() == kEmbeddedSearchEnabledVersion;
79 #else 82 #else
80 return true; 83 return true;
81 #endif // defined(OS_IOS) 84 #endif // defined(OS_IOS)
82 } 85 }
83 86
84 // Determine what embedded search page version to request from the user's 87 // Determine what embedded search page version to request from the user's
85 // default search provider. If 0, the embedded search UI should not be enabled. 88 // default search provider. If 0, the embedded search UI should not be enabled.
86 uint64 EmbeddedSearchPageVersion() { 89 uint64_t EmbeddedSearchPageVersion() {
87 #if defined(OS_ANDROID) 90 #if defined(OS_ANDROID)
88 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 91 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
89 switches::kEnableEmbeddedSearchAPI)) { 92 switches::kEnableEmbeddedSearchAPI)) {
90 return kEmbeddedSearchEnabledVersion; 93 return kEmbeddedSearchEnabledVersion;
91 } 94 }
92 #endif 95 #endif
93 96
94 FieldTrialFlags flags; 97 FieldTrialFlags flags;
95 if (GetFieldTrialInfo(&flags)) { 98 if (GetFieldTrialInfo(&flags)) {
96 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName, 99 return GetUInt64ValueForFlagWithDefault(kEmbeddedPageVersionFlagName,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 const std::string& default_value, 139 const std::string& default_value,
137 const FieldTrialFlags& flags) { 140 const FieldTrialFlags& flags) {
138 FieldTrialFlags::const_iterator i; 141 FieldTrialFlags::const_iterator i;
139 for (i = flags.begin(); i != flags.end(); i++) { 142 for (i = flags.begin(); i != flags.end(); i++) {
140 if (i->first == flag) 143 if (i->first == flag)
141 return i->second; 144 return i->second;
142 } 145 }
143 return default_value; 146 return default_value;
144 } 147 }
145 148
146 // Given a FieldTrialFlags object, returns the uint64 value of the provided 149 // Given a FieldTrialFlags object, returns the uint64_t value of the provided
147 // flag. 150 // flag.
148 uint64 GetUInt64ValueForFlagWithDefault(const std::string& flag, 151 uint64_t GetUInt64ValueForFlagWithDefault(const std::string& flag,
149 uint64 default_value, 152 uint64_t default_value,
150 const FieldTrialFlags& flags) { 153 const FieldTrialFlags& flags) {
151 uint64 value; 154 uint64_t value;
152 std::string str_value = 155 std::string str_value =
153 GetStringValueForFlagWithDefault(flag, std::string(), flags); 156 GetStringValueForFlagWithDefault(flag, std::string(), flags);
154 if (base::StringToUint64(str_value, &value)) 157 if (base::StringToUint64(str_value, &value))
155 return value; 158 return value;
156 return default_value; 159 return default_value;
157 } 160 }
158 161
159 // Given a FieldTrialFlags object, returns the boolean value of the provided 162 // Given a FieldTrialFlags object, returns the boolean value of the provided
160 // flag. 163 // flag.
161 bool GetBoolValueForFlagWithDefault(const std::string& flag, 164 bool GetBoolValueForFlagWithDefault(const std::string& flag,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 } 251 }
249 252
250 void EnableQueryExtractionForTesting() { 253 void EnableQueryExtractionForTesting() {
251 #if !defined(OS_IOS) && !defined(OS_ANDROID) 254 #if !defined(OS_IOS) && !defined(OS_ANDROID)
252 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); 255 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
253 cl->AppendSwitch(switches::kEnableQueryExtraction); 256 cl->AppendSwitch(switches::kEnableQueryExtraction);
254 #endif 257 #endif
255 } 258 }
256 259
257 } // namespace search 260 } // namespace search
OLDNEW
« no previous file with comments | « components/search/search.h ('k') | components/search/search_switches.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698