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

Side by Side Diff: chrome/browser/android/contextualsearch/contextual_search_delegate.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 | « no previous file | chrome/browser/android/contextualsearch/contextual_search_field_trial.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_delegate.h" 5 #include "chrome/browser/android/contextualsearch/contextual_search_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 const char kDoPreventPreloadValue[] = "1"; 65 const char kDoPreventPreloadValue[] = "1";
66 66
67 // The number of characters that should be shown after the selected expression. 67 // The number of characters that should be shown after the selected expression.
68 const int kSurroundingSizeForUI = 60; 68 const int kSurroundingSizeForUI = 60;
69 69
70 // The version of the Contextual Cards API that we want to invoke. 70 // The version of the Contextual Cards API that we want to invoke.
71 const int kContextualCardsNoIntegration = 0; 71 const int kContextualCardsNoIntegration = 0;
72 const int kContextualCardsBarIntegration = 1; 72 const int kContextualCardsBarIntegration = 1;
73 const int kContextualCardsSingleAction = 2; 73 const int kContextualCardsSingleAction = 2;
74 74
75 const char kContextualCardsVersionOverride[] = "contextual_cards_version";
76
77 } // namespace 75 } // namespace
78 76
79 // URLFetcher ID, only used for tests: we only have one kind of fetcher. 77 // URLFetcher ID, only used for tests: we only have one kind of fetcher.
80 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; 78 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1;
81 79
82 // Handles tasks for the ContextualSearchManager in a separable, testable way. 80 // Handles tasks for the ContextualSearchManager in a separable, testable way.
83 ContextualSearchDelegate::ContextualSearchDelegate( 81 ContextualSearchDelegate::ContextualSearchDelegate(
84 net::URLRequestContextGetter* url_request_context, 82 net::URLRequestContextGetter* url_request_context,
85 TemplateURLService* template_url_service, 83 TemplateURLService* template_url_service,
86 const ContextualSearchDelegate::SearchTermResolutionCallback& 84 const ContextualSearchDelegate::SearchTermResolutionCallback&
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 TemplateURLRef::SearchTermsArgs(base::string16()); 231 TemplateURLRef::SearchTermsArgs(base::string16());
234 232
235 int contextual_cards_version = kContextualCardsNoIntegration; 233 int contextual_cards_version = kContextualCardsNoIntegration;
236 if (field_trial_->IsContextualCardsBarIntegrationEnabled()) 234 if (field_trial_->IsContextualCardsBarIntegrationEnabled())
237 contextual_cards_version = kContextualCardsBarIntegration; 235 contextual_cards_version = kContextualCardsBarIntegration;
238 if (base::FeatureList::IsEnabled( 236 if (base::FeatureList::IsEnabled(
239 chrome::android::kContextualSearchSingleActions)) { 237 chrome::android::kContextualSearchSingleActions)) {
240 contextual_cards_version = kContextualCardsSingleAction; 238 contextual_cards_version = kContextualCardsSingleAction;
241 } 239 }
242 240
243 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 241 if (field_trial_->GetContextualCardsVersion() != 0) {
244 kContextualCardsVersionOverride)){ 242 contextual_cards_version = field_trial_->GetContextualCardsVersion();
245 contextual_cards_version =
246 std::stoi(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
247 kContextualCardsVersionOverride), nullptr);
248 } 243 }
249 244
250 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( 245 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params(
251 kContextualSearchRequestVersion, contextual_cards_version, home_country); 246 kContextualSearchRequestVersion, contextual_cards_version, home_country);
252 247
253 search_terms_args.contextual_search_params = params; 248 search_terms_args.contextual_search_params = params;
254 249
255 std::string request( 250 std::string request(
256 template_url->contextual_search_url_ref().ReplaceSearchTerms( 251 template_url->contextual_search_url_ref().ReplaceSearchTerms(
257 search_terms_args, 252 search_terms_args,
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 end_offset -= trim; 600 end_offset -= trim;
606 } 601 }
607 if (result_text.length() > end_offset + padding_each_side_pinned) { 602 if (result_text.length() > end_offset + padding_each_side_pinned) {
608 // Trim the end. 603 // Trim the end.
609 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); 604 result_text = result_text.substr(0, end_offset + padding_each_side_pinned);
610 } 605 }
611 *start = start_offset; 606 *start = start_offset;
612 *end = end_offset; 607 *end = end_offset;
613 return result_text; 608 return result_text;
614 } 609 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/android/contextualsearch/contextual_search_field_trial.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698