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

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

Issue 10381016: Remove the "autogenerate keyword" bit on TemplateURL. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/autocomplete/autocomplete_field_trial.h" 15 #include "chrome/browser/autocomplete/autocomplete_field_trial.h"
16 #include "chrome/browser/google/google_util.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/guid.h" 19 #include "chrome/common/guid.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "net/base/escape.h" 21 #include "net/base/escape.h"
21 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
22 23
23 // The TemplateURLRef has any number of terms that need to be replaced. Each of 24 // The TemplateURLRef has any number of terms that need to be replaced. Each of
24 // the terms is enclosed in braces. If the character preceeding the final 25 // the terms is enclosed in braces. If the character preceeding the final
25 // brace is a ?, it indicates the term is optional and can be replaced with 26 // brace is a ?, it indicates the term is optional and can be replaced with
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 TemplateURLData::TemplateURLData() 529 TemplateURLData::TemplateURLData()
529 : show_in_default_list(false), 530 : show_in_default_list(false),
530 safe_for_autoreplace(false), 531 safe_for_autoreplace(false),
531 id(0), 532 id(0),
532 date_created(base::Time::Now()), 533 date_created(base::Time::Now()),
533 last_modified(base::Time::Now()), 534 last_modified(base::Time::Now()),
534 created_by_policy(false), 535 created_by_policy(false),
535 usage_count(0), 536 usage_count(0),
536 prepopulate_id(0), 537 prepopulate_id(0),
537 sync_guid(guid::GenerateGUID()), 538 sync_guid(guid::GenerateGUID()),
538 url_("x"), 539 keyword_(ASCIIToUTF16("dummy")),
SteveT 2012/05/07 18:17:47 Kind of curious if we're guaranteed to replace thi
Peter Kasting 2012/05/07 19:39:14 We should be, just like with the URL field. It's
539 autogenerate_keyword_(false), 540 url_("x") {
540 keyword_generated_(false) {
541 } 541 }
542 542
543 TemplateURLData::~TemplateURLData() { 543 TemplateURLData::~TemplateURLData() {
544 } 544 }
545 545
546 void TemplateURLData::SetKeyword(const string16& keyword) { 546 void TemplateURLData::SetKeyword(const string16& keyword) {
547 DCHECK(!keyword.empty());
548
547 // Case sensitive keyword matching is confusing. As such, we force all 549 // Case sensitive keyword matching is confusing. As such, we force all
548 // keywords to be lower case. 550 // keywords to be lower case.
549 keyword_ = base::i18n::ToLower(keyword); 551 keyword_ = base::i18n::ToLower(keyword);
550 autogenerate_keyword_ = false;
551 }
552
553 const string16& TemplateURLData::keyword(TemplateURL* t_url) const {
554 EnsureKeyword(t_url);
555 return keyword_;
556 }
557
558 void TemplateURLData::SetAutogenerateKeyword(bool autogenerate_keyword) {
559 autogenerate_keyword_ = autogenerate_keyword;
560 if (autogenerate_keyword_) {
561 keyword_.clear();
562 keyword_generated_ = false;
563 }
564 }
565
566 void TemplateURLData::EnsureKeyword(TemplateURL* t_url) const {
567 if (autogenerate_keyword_ && !keyword_generated_) {
568 // Generate a keyword and cache it.
569 keyword_ = base::i18n::ToLower(TemplateURLService::GenerateKeyword(
570 TemplateURLService::GenerateSearchURL(t_url).GetWithEmptyPath(), true));
571 keyword_generated_ = true;
572 }
573 } 552 }
574 553
575 void TemplateURLData::SetURL(const std::string& url) { 554 void TemplateURLData::SetURL(const std::string& url) {
576 DCHECK(!url.empty()); 555 DCHECK(!url.empty());
577 url_ = url; 556 url_ = url;
578 } 557 }
579 558
580 559
581 // TemplateURL ---------------------------------------------------------------- 560 // TemplateURL ----------------------------------------------------------------
582 561
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 bool TemplateURL::SupportsReplacement() const { 626 bool TemplateURL::SupportsReplacement() const {
648 UIThreadSearchTermsData search_terms_data; 627 UIThreadSearchTermsData search_terms_data;
649 return SupportsReplacementUsingTermsData(search_terms_data); 628 return SupportsReplacementUsingTermsData(search_terms_data);
650 } 629 }
651 630
652 bool TemplateURL::SupportsReplacementUsingTermsData( 631 bool TemplateURL::SupportsReplacementUsingTermsData(
653 const SearchTermsData& search_terms_data) const { 632 const SearchTermsData& search_terms_data) const {
654 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); 633 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data);
655 } 634 }
656 635
636 bool TemplateURL::IsGoogleSearchURLWithReplaceableKeyword() const {
637 return !IsExtensionKeyword() && url_ref_.HasGoogleBaseURLs() &&
638 google_util::IsGoogleHostname(UTF16ToUTF8(data_.keyword()),
639 google_util::DISALLOW_SUBDOMAIN);
640 }
641
657 std::string TemplateURL::GetExtensionId() const { 642 std::string TemplateURL::GetExtensionId() const {
658 DCHECK(IsExtensionKeyword()); 643 DCHECK(IsExtensionKeyword());
659 return GURL(data_.url()).host(); 644 return GURL(data_.url()).host();
660 } 645 }
661 646
662 bool TemplateURL::IsExtensionKeyword() const { 647 bool TemplateURL::IsExtensionKeyword() const {
663 return GURL(data_.url()).SchemeIs(chrome::kExtensionScheme); 648 return GURL(data_.url()).SchemeIs(chrome::kExtensionScheme);
664 } 649 }
665 650
666 void TemplateURL::SetURL(const std::string& url) { 651 void TemplateURL::SetURL(const std::string& url) {
667 data_.SetURL(url); 652 data_.SetURL(url);
668 url_ref_.InvalidateCachedValues(); 653 url_ref_.InvalidateCachedValues();
669 } 654 }
670 655
671 void TemplateURL::SetPrepopulateId(int id) { 656 void TemplateURL::SetPrepopulateId(int id) {
672 data_.prepopulate_id = id; 657 data_.prepopulate_id = id;
673 const bool prepopulated = id > 0; 658 const bool prepopulated = id > 0;
674 url_ref_.prepopulated_ = prepopulated; 659 url_ref_.prepopulated_ = prepopulated;
675 suggestions_url_ref_.prepopulated_ = prepopulated; 660 suggestions_url_ref_.prepopulated_ = prepopulated;
676 instant_url_ref_.prepopulated_ = prepopulated; 661 instant_url_ref_.prepopulated_ = prepopulated;
677 } 662 }
678 663
664 void TemplateURL::ResetKeywordIfNecessary(bool force) {
665 if (IsGoogleSearchURLWithReplaceableKeyword() || force) {
666 DCHECK(!IsExtensionKeyword());
667 GURL url(TemplateURLService::GenerateSearchURL(this));
668 if (url.is_valid())
669 data_.SetKeyword(TemplateURLService::GenerateKeyword(url));
670 }
671 }
672
679 void TemplateURL::InvalidateCachedValues() { 673 void TemplateURL::InvalidateCachedValues() {
680 url_ref_.InvalidateCachedValues(); 674 url_ref_.InvalidateCachedValues();
681 suggestions_url_ref_.InvalidateCachedValues(); 675 suggestions_url_ref_.InvalidateCachedValues();
682 instant_url_ref_.InvalidateCachedValues(); 676 instant_url_ref_.InvalidateCachedValues();
683 data_.SetAutogenerateKeyword(data_.autogenerate_keyword()); 677 ResetKeywordIfNecessary(false);
684 } 678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698