OLD | NEW |
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 Loading... |
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 |
75 } // namespace | 77 } // namespace |
76 | 78 |
77 // URLFetcher ID, only used for tests: we only have one kind of fetcher. | 79 // URLFetcher ID, only used for tests: we only have one kind of fetcher. |
78 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; | 80 const int ContextualSearchDelegate::kContextualSearchURLFetcherID = 1; |
79 | 81 |
80 // Handles tasks for the ContextualSearchManager in a separable, testable way. | 82 // Handles tasks for the ContextualSearchManager in a separable, testable way. |
81 ContextualSearchDelegate::ContextualSearchDelegate( | 83 ContextualSearchDelegate::ContextualSearchDelegate( |
82 net::URLRequestContextGetter* url_request_context, | 84 net::URLRequestContextGetter* url_request_context, |
83 TemplateURLService* template_url_service, | 85 TemplateURLService* template_url_service, |
84 const ContextualSearchDelegate::SearchTermResolutionCallback& | 86 const ContextualSearchDelegate::SearchTermResolutionCallback& |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 TemplateURLRef::SearchTermsArgs(base::string16()); | 230 TemplateURLRef::SearchTermsArgs(base::string16()); |
229 | 231 |
230 int contextual_cards_version = kContextualCardsNoIntegration; | 232 int contextual_cards_version = kContextualCardsNoIntegration; |
231 if (field_trial_->IsContextualCardsBarIntegrationEnabled()) | 233 if (field_trial_->IsContextualCardsBarIntegrationEnabled()) |
232 contextual_cards_version = kContextualCardsBarIntegration; | 234 contextual_cards_version = kContextualCardsBarIntegration; |
233 if (base::FeatureList::IsEnabled( | 235 if (base::FeatureList::IsEnabled( |
234 chrome::android::kContextualSearchSingleActions)) { | 236 chrome::android::kContextualSearchSingleActions)) { |
235 contextual_cards_version = kContextualCardsSingleAction; | 237 contextual_cards_version = kContextualCardsSingleAction; |
236 } | 238 } |
237 | 239 |
| 240 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 241 kContextualCardsVersionOverride)){ |
| 242 contextual_cards_version = |
| 243 std::stoi(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 244 kContextualCardsVersionOverride), nullptr); |
| 245 } |
| 246 |
238 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( | 247 TemplateURLRef::SearchTermsArgs::ContextualSearchParams params( |
239 kContextualSearchRequestVersion, selected_text, std::string(), | 248 kContextualSearchRequestVersion, selected_text, std::string(), |
240 contextual_cards_version); | 249 contextual_cards_version); |
241 | 250 |
242 search_terms_args.contextual_search_params = params; | 251 search_terms_args.contextual_search_params = params; |
243 | 252 |
244 std::string request( | 253 std::string request( |
245 template_url->contextual_search_url_ref().ReplaceSearchTerms( | 254 template_url->contextual_search_url_ref().ReplaceSearchTerms( |
246 search_terms_args, | 255 search_terms_args, |
247 template_url_service_->search_terms_data(), | 256 template_url_service_->search_terms_data(), |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 end_offset -= trim; | 607 end_offset -= trim; |
599 } | 608 } |
600 if (result_text.length() > end_offset + padding_each_side_pinned) { | 609 if (result_text.length() > end_offset + padding_each_side_pinned) { |
601 // Trim the end. | 610 // Trim the end. |
602 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); | 611 result_text = result_text.substr(0, end_offset + padding_each_side_pinned); |
603 } | 612 } |
604 *start = start_offset; | 613 *start = start_offset; |
605 *end = end_offset; | 614 *end = end_offset; |
606 return result_text; | 615 return result_text; |
607 } | 616 } |
OLD | NEW |