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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_field_trial.cc

Issue 2697513005: [TTS] Add server control from a field_trial param. (Closed)
Patch Set: Created 3 years, 10 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 | « chrome/browser/android/contextualsearch/contextual_search_field_trial.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/android/contextualsearch/contextual_search_field_trial. h" 5 #include "chrome/browser/android/contextualsearch/contextual_search_field_trial. h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "components/variations/variations_associated_data.h" 10 #include "components/variations/variations_associated_data.h"
11 11
12 namespace { 12 namespace {
13 13
14 const char kContextualSearchFieldTrialName[] = "ContextualSearch"; 14 const char kContextualSearchFieldTrialName[] = "ContextualSearch";
15 const char kFalseValue[] = "false"; 15 const char kFalseValue[] = "false";
16 const char kAnyNonEmptyValue[] = "1"; 16 const char kAnyNonEmptyValue[] = "1";
17 const char kContextualSearchResolverUrl[] = "contextual-search-resolver-url"; 17 const char kContextualSearchResolverUrl[] = "contextual-search-resolver-url";
18 const char kContextualSearchSurroundingSizeParamName[] = "surrounding_size"; 18 const char kContextualSearchSurroundingSizeParamName[] = "surrounding_size";
19 const char kContextualSearchIcingSurroundingSizeParamName[] = 19 const char kContextualSearchIcingSurroundingSizeParamName[] =
20 "icing_surrounding_size"; 20 "icing_surrounding_size";
21 const char kContextualSearchSendURLDisabledParamName[] = "disable_send_url"; 21 const char kContextualSearchSendURLDisabledParamName[] = "disable_send_url";
22 const char kContextualSearchDecodeMentionsDisabledParamName[] = 22 const char kContextualSearchDecodeMentionsDisabledParamName[] =
23 "disable_decode_mentions"; 23 "disable_decode_mentions";
24 const char kContextualCardsVersionParamName[] = "contextual_cards_version";
25
24 // The default size of the content surrounding the selection to gather, allowing 26 // The default size of the content surrounding the selection to gather, allowing
25 // room for other parameters. 27 // room for other parameters.
26 const int kContextualSearchDefaultContentSize = 1536; 28 const int kContextualSearchDefaultContentSize = 1536;
27 29
28 } // namespace 30 } // namespace
29 31
30 // static 32 // static
31 const int 33 const int
32 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize = 34 ContextualSearchFieldTrial::kContextualSearchDefaultIcingSurroundingSize =
33 400; 35 400;
34 36
35 ContextualSearchFieldTrial::ContextualSearchFieldTrial() 37 ContextualSearchFieldTrial::ContextualSearchFieldTrial()
36 : is_resolver_url_prefix_cached_(false), 38 : is_resolver_url_prefix_cached_(false),
37 is_surrounding_size_cached_(false), 39 is_surrounding_size_cached_(false),
38 surrounding_size_(0), 40 surrounding_size_(0),
39 is_icing_surrounding_size_cached_(false), 41 is_icing_surrounding_size_cached_(false),
40 icing_surrounding_size_(0), 42 icing_surrounding_size_(0),
41 is_send_base_page_url_disabled_cached_(false), 43 is_send_base_page_url_disabled_cached_(false),
42 is_send_base_page_url_disabled_(false), 44 is_send_base_page_url_disabled_(false),
43 is_decode_mentions_disabled_cached_(false), 45 is_decode_mentions_disabled_cached_(false),
44 is_decode_mentions_disabled_(false), 46 is_decode_mentions_disabled_(false),
45 is_contextual_cards_bar_integration_enabled_cached_(false), 47 is_contextual_cards_bar_integration_enabled_cached_(false),
46 is_contextual_cards_bar_integration_enabled_(false) {} 48 is_contextual_cards_bar_integration_enabled_(false),
49 is_contextual_cards_version_cached_(false),
50 contextual_cards_version_(0) {}
47 51
48 ContextualSearchFieldTrial::~ContextualSearchFieldTrial() {} 52 ContextualSearchFieldTrial::~ContextualSearchFieldTrial() {}
49 53
50 std::string ContextualSearchFieldTrial::GetResolverURLPrefix() { 54 std::string ContextualSearchFieldTrial::GetResolverURLPrefix() {
51 if (!is_resolver_url_prefix_cached_) { 55 if (!is_resolver_url_prefix_cached_) {
52 is_resolver_url_prefix_cached_ = true; 56 is_resolver_url_prefix_cached_ = true;
53 resolver_url_prefix_ = GetSwitch(kContextualSearchResolverUrl); 57 resolver_url_prefix_ = GetSwitch(kContextualSearchResolverUrl);
54 if (resolver_url_prefix_.empty()) 58 if (resolver_url_prefix_.empty())
55 resolver_url_prefix_ = GetParam(kContextualSearchResolverUrl); 59 resolver_url_prefix_ = GetParam(kContextualSearchResolverUrl);
56 } 60 }
(...skipping 26 matching lines...) Expand all
83 &is_decode_mentions_disabled_); 87 &is_decode_mentions_disabled_);
84 } 88 }
85 89
86 bool ContextualSearchFieldTrial::IsContextualCardsBarIntegrationEnabled() { 90 bool ContextualSearchFieldTrial::IsContextualCardsBarIntegrationEnabled() {
87 return GetBooleanParam( 91 return GetBooleanParam(
88 switches::kEnableContextualSearchContextualCardsBarIntegration, 92 switches::kEnableContextualSearchContextualCardsBarIntegration,
89 &is_contextual_cards_bar_integration_enabled_cached_, 93 &is_contextual_cards_bar_integration_enabled_cached_,
90 &is_contextual_cards_bar_integration_enabled_); 94 &is_contextual_cards_bar_integration_enabled_);
91 } 95 }
92 96
97 int ContextualSearchFieldTrial::GetContextualCardsVersion() {
98 return GetIntParamValueOrDefault(kContextualCardsVersionParamName, 0,
99 &is_contextual_cards_version_cached_,
100 &contextual_cards_version_);
101 }
102
93 bool ContextualSearchFieldTrial::GetBooleanParam(const std::string& name, 103 bool ContextualSearchFieldTrial::GetBooleanParam(const std::string& name,
94 bool* is_value_cached, 104 bool* is_value_cached,
95 bool* cached_value) { 105 bool* cached_value) {
96 if (!*is_value_cached) { 106 if (!*is_value_cached) {
97 *is_value_cached = true; 107 *is_value_cached = true;
98 std::string string_value = GetSwitch(name); 108 std::string string_value = GetSwitch(name);
99 // A switch with an empty value is true. 109 // A switch with an empty value is true.
100 bool has_switch = HasSwitch(name); 110 bool has_switch = HasSwitch(name);
101 if (has_switch && string_value.empty()) 111 if (has_switch && string_value.empty())
102 string_value = kAnyNonEmptyValue; 112 string_value = kAnyNonEmptyValue;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (!HasSwitch(name)) 145 if (!HasSwitch(name))
136 return std::string(); 146 return std::string();
137 else 147 else
138 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(name); 148 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(name);
139 } 149 }
140 150
141 std::string ContextualSearchFieldTrial::GetParam(const std::string& name) { 151 std::string ContextualSearchFieldTrial::GetParam(const std::string& name) {
142 return variations::GetVariationParamValue(kContextualSearchFieldTrialName, 152 return variations::GetVariationParamValue(kContextualSearchFieldTrialName,
143 name); 153 name);
144 } 154 }
OLDNEW
« no previous file with comments | « chrome/browser/android/contextualsearch/contextual_search_field_trial.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698