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

Side by Side Diff: chrome/browser/search_engines/template_url.cc

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/search_engines/template_url.h" 5 #include "chrome/browser/search_engines/template_url.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/field_trial.h" 11 #include "base/metrics/field_trial.h"
12 #include "base/stringprintf.h" 12 #include "base/stringprintf.h"
13 #include "base/string_number_conversions.h" 13 #include "base/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/instant/instant_field_trial.h"
15 #include "chrome/browser/search_engines/search_engine_type.h" 16 #include "chrome/browser/search_engines/search_engine_type.h"
16 #include "chrome/browser/search_engines/search_terms_data.h" 17 #include "chrome/browser/search_engines/search_terms_data.h"
17 #include "chrome/browser/search_engines/template_url_service.h" 18 #include "chrome/browser/search_engines/template_url_service.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "chrome/installer/util/google_update_settings.h" 20 #include "chrome/installer/util/google_update_settings.h"
20 #include "content/browser/user_metrics.h" 21 #include "content/browser/user_metrics.h"
21 #include "net/base/escape.h" 22 #include "net/base/escape.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/favicon_size.h" 24 #include "ui/gfx/favicon_size.h"
24 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the 25 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the
(...skipping 30 matching lines...) Expand all
55 static const char kGoogleOriginalQueryForSuggestionParameter[] = 56 static const char kGoogleOriginalQueryForSuggestionParameter[] =
56 "google:originalQueryForSuggestion"; 57 "google:originalQueryForSuggestion";
57 static const char kGoogleRLZParameter[] = "google:RLZ"; 58 static const char kGoogleRLZParameter[] = "google:RLZ";
58 // Same as kSearchTermsParameter, with no escaping. 59 // Same as kSearchTermsParameter, with no escaping.
59 static const char kGoogleSearchFieldtrialParameter[] = 60 static const char kGoogleSearchFieldtrialParameter[] =
60 "google:searchFieldtrialParameter"; 61 "google:searchFieldtrialParameter";
61 static const char kGoogleUnescapedSearchTermsParameter[] = 62 static const char kGoogleUnescapedSearchTermsParameter[] =
62 "google:unescapedSearchTerms"; 63 "google:unescapedSearchTerms";
63 static const char kGoogleUnescapedSearchTermsParameterFull[] = 64 static const char kGoogleUnescapedSearchTermsParameterFull[] =
64 "{google:unescapedSearchTerms}"; 65 "{google:unescapedSearchTerms}";
66 static const char kInstantFieldTrialGroupParameter[] =
67 "instantFieldTrialGroupParameter";
sky 2011/08/08 23:37:23 Since this is google specific, use google:
sreeram 2011/08/09 16:24:01 Done. Will reflect it in the next patch.
65 68
66 // Display value for kSearchTermsParameter. 69 // Display value for kSearchTermsParameter.
67 static const char kDisplaySearchTerms[] = "%s"; 70 static const char kDisplaySearchTerms[] = "%s";
68 71
69 // Display value for kGoogleUnescapedSearchTermsParameter. 72 // Display value for kGoogleUnescapedSearchTermsParameter.
70 static const char kDisplayUnescapedSearchTerms[] = "%S"; 73 static const char kDisplayUnescapedSearchTerms[] = "%S";
71 74
72 // Used if the count parameter is not optional. Indicates we want 10 search 75 // Used if the count parameter is not optional. Indicates we want 10 search
73 // results. 76 // results.
74 static const char kDefaultCount[] = "10"; 77 static const char kDefaultCount[] = "10";
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start)); 151 replacements->push_back(Replacement(GOOGLE_BASE_SUGGEST_URL, start));
149 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) { 152 } else if (parameter == kGoogleOriginalQueryForSuggestionParameter) {
150 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION, 153 replacements->push_back(Replacement(GOOGLE_ORIGINAL_QUERY_FOR_SUGGESTION,
151 start)); 154 start));
152 } else if (parameter == kGoogleRLZParameter) { 155 } else if (parameter == kGoogleRLZParameter) {
153 replacements->push_back(Replacement(GOOGLE_RLZ, start)); 156 replacements->push_back(Replacement(GOOGLE_RLZ, start));
154 } else if (parameter == kGoogleSearchFieldtrialParameter) { 157 } else if (parameter == kGoogleSearchFieldtrialParameter) {
155 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start)); 158 replacements->push_back(Replacement(GOOGLE_SEARCH_FIELDTRIAL_GROUP, start));
156 } else if (parameter == kGoogleUnescapedSearchTermsParameter) { 159 } else if (parameter == kGoogleUnescapedSearchTermsParameter) {
157 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start)); 160 replacements->push_back(Replacement(GOOGLE_UNESCAPED_SEARCH_TERMS, start));
161 } else if (parameter == kInstantFieldTrialGroupParameter) {
162 replacements->push_back(Replacement(INSTANT_FIELD_TRIAL_GROUP, start));
158 } else { 163 } else {
159 // If it's a prepopulated URL, we know that it's safe to remove unknown 164 // If it's a prepopulated URL, we know that it's safe to remove unknown
160 // parameters. Otherwise it could be some garbage but can also be a 165 // parameters. Otherwise it could be some garbage but can also be a
161 // javascript block. Put it back. 166 // javascript block. Put it back.
162 if (!prepopulated_) 167 if (!prepopulated_)
163 url->insert(start, full_parameter); 168 url->insert(start, full_parameter);
164 return false; 169 return false;
165 } 170 }
166 return true; 171 return true;
167 } 172 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 274 }
270 } 275 }
271 } 276 }
272 277
273 // static 278 // static
274 void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) { 279 void TemplateURLRef::SetGoogleBaseURL(std::string* google_base_url) {
275 UIThreadSearchTermsData::SetGoogleBaseURL(google_base_url); 280 UIThreadSearchTermsData::SetGoogleBaseURL(google_base_url);
276 } 281 }
277 282
278 std::string TemplateURLRef::ReplaceSearchTerms( 283 std::string TemplateURLRef::ReplaceSearchTerms(
284 Profile* profile,
279 const TemplateURL& host, 285 const TemplateURL& host,
280 const string16& terms, 286 const string16& terms,
281 int accepted_suggestion, 287 int accepted_suggestion,
282 const string16& original_query_for_suggestion) const { 288 const string16& original_query_for_suggestion) const {
283 UIThreadSearchTermsData search_terms_data; 289 UIThreadSearchTermsData search_terms_data;
284 return ReplaceSearchTermsUsingTermsData(host, 290 return ReplaceSearchTermsUsingTermsData(profile,
291 host,
285 terms, 292 terms,
286 accepted_suggestion, 293 accepted_suggestion,
287 original_query_for_suggestion, 294 original_query_for_suggestion,
288 search_terms_data); 295 search_terms_data);
289 } 296 }
290 297
291 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( 298 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData(
299 Profile* profile,
292 const TemplateURL& host, 300 const TemplateURL& host,
293 const string16& terms, 301 const string16& terms,
294 int accepted_suggestion, 302 int accepted_suggestion,
295 const string16& original_query_for_suggestion, 303 const string16& original_query_for_suggestion,
296 const SearchTermsData& search_terms_data) const { 304 const SearchTermsData& search_terms_data) const {
297 ParseIfNecessaryUsingTermsData(search_terms_data); 305 ParseIfNecessaryUsingTermsData(search_terms_data);
298 if (!valid_) 306 if (!valid_)
299 return std::string(); 307 return std::string();
300 308
301 if (replacements_.empty()) 309 if (replacements_.empty())
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 case GOOGLE_UNESCAPED_SEARCH_TERMS: { 418 case GOOGLE_UNESCAPED_SEARCH_TERMS: {
411 std::string unescaped_terms; 419 std::string unescaped_terms;
412 base::UTF16ToCodepage(terms, input_encoding.c_str(), 420 base::UTF16ToCodepage(terms, input_encoding.c_str(),
413 base::OnStringConversionError::SKIP, 421 base::OnStringConversionError::SKIP,
414 &unescaped_terms); 422 &unescaped_terms);
415 url.insert(i->index, std::string(unescaped_terms.begin(), 423 url.insert(i->index, std::string(unescaped_terms.begin(),
416 unescaped_terms.end())); 424 unescaped_terms.end()));
417 break; 425 break;
418 } 426 }
419 427
428 case INSTANT_FIELD_TRIAL_GROUP:
429 if (profile != NULL)
430 url.insert(i->index, InstantFieldTrial::GetGroupAsUrlParam(profile));
431 break;
432
420 case LANGUAGE: 433 case LANGUAGE:
421 url.insert(i->index, search_terms_data.GetApplicationLocale()); 434 url.insert(i->index, search_terms_data.GetApplicationLocale());
422 break; 435 break;
423 436
424 case SEARCH_TERMS: 437 case SEARCH_TERMS:
425 url.insert(i->index, UTF16ToUTF8(encoded_terms)); 438 url.insert(i->index, UTF16ToUTF8(encoded_terms));
426 break; 439 break;
427 440
428 default: 441 default:
429 NOTREACHED(); 442 NOTREACHED();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 671
659 string16 TemplateURL::keyword() const { 672 string16 TemplateURL::keyword() const {
660 EnsureKeyword(); 673 EnsureKeyword();
661 return keyword_; 674 return keyword_;
662 } 675 }
663 676
664 void TemplateURL::EnsureKeyword() const { 677 void TemplateURL::EnsureKeyword() const {
665 if (autogenerate_keyword_ && !keyword_generated_) { 678 if (autogenerate_keyword_ && !keyword_generated_) {
666 // Generate a keyword and cache it. 679 // Generate a keyword and cache it.
667 keyword_ = TemplateURLService::GenerateKeyword( 680 keyword_ = TemplateURLService::GenerateKeyword(
668 TemplateURLService::GenerateSearchURL(this).GetWithEmptyPath(), true); 681 TemplateURLService::GenerateSearchURL(NULL, this).GetWithEmptyPath(),
682 true);
669 keyword_generated_ = true; 683 keyword_generated_ = true;
670 } 684 }
671 } 685 }
672 686
673 bool TemplateURL::ShowInDefaultList() const { 687 bool TemplateURL::ShowInDefaultList() const {
674 return show_in_default_list() && url() && url()->SupportsReplacement(); 688 return show_in_default_list() && url() && url()->SupportsReplacement();
675 } 689 }
676 690
677 void TemplateURL::SetFaviconURL(const GURL& url) { 691 void TemplateURL::SetFaviconURL(const GURL& url) {
678 for (std::vector<ImageRef>::iterator i = image_refs_.begin(); 692 for (std::vector<ImageRef>::iterator i = image_refs_.begin();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 } 743 }
730 744
731 std::string TemplateURL::GetExtensionId() const { 745 std::string TemplateURL::GetExtensionId() const {
732 DCHECK(IsExtensionKeyword()); 746 DCHECK(IsExtensionKeyword());
733 return GURL(url_.url()).host(); 747 return GURL(url_.url()).host();
734 } 748 }
735 749
736 bool TemplateURL::IsExtensionKeyword() const { 750 bool TemplateURL::IsExtensionKeyword() const {
737 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); 751 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme);
738 } 752 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698