| Index: chrome/browser/search_engines/template_url.cc
|
| ===================================================================
|
| --- chrome/browser/search_engines/template_url.cc (revision 130285)
|
| +++ chrome/browser/search_engines/template_url.cc (working copy)
|
| @@ -86,21 +86,26 @@
|
|
|
| // TemplateURLRef -------------------------------------------------------------
|
|
|
| -TemplateURLRef::TemplateURLRef(TemplateURL* owner)
|
| +TemplateURLRef::TemplateURLRef(TemplateURL* owner, Type type)
|
| : owner_(owner),
|
| + type_(type),
|
| + parsed_(false),
|
| + valid_(false),
|
| + supports_replacements_(false),
|
| prepopulated_(false) {
|
| DCHECK(owner_);
|
| - Set(std::string());
|
| }
|
|
|
| -TemplateURLRef::TemplateURLRef(TemplateURL* owner, const std::string& url)
|
| - : owner_(owner),
|
| - prepopulated_(false) {
|
| - DCHECK(owner_);
|
| - Set(url);
|
| +TemplateURLRef::~TemplateURLRef() {
|
| }
|
|
|
| -TemplateURLRef::~TemplateURLRef() {
|
| +std::string TemplateURLRef::GetURL() const {
|
| + switch (type_) {
|
| + case SEARCH: return owner_->url();
|
| + case SUGGEST: return owner_->suggestions_url();
|
| + case INSTANT: return owner_->instant_url();
|
| + default: NOTREACHED(); return std::string();
|
| + }
|
| }
|
|
|
| bool TemplateURLRef::SupportsReplacement() const {
|
| @@ -287,19 +292,15 @@
|
|
|
| string16 TemplateURLRef::DisplayURL() const {
|
| ParseIfNecessary();
|
| - if (!valid_ || replacements_.empty())
|
| - return UTF8ToUTF16(url_);
|
| -
|
| - string16 result = UTF8ToUTF16(url_);
|
| - ReplaceSubstringsAfterOffset(&result, 0,
|
| - ASCIIToUTF16(kSearchTermsParameterFull),
|
| - ASCIIToUTF16(kDisplaySearchTerms));
|
| -
|
| - ReplaceSubstringsAfterOffset(
|
| - &result, 0,
|
| - ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull),
|
| - ASCIIToUTF16(kDisplayUnescapedSearchTerms));
|
| -
|
| + string16 result(UTF8ToUTF16(GetURL()));
|
| + if (valid_ && !replacements_.empty()) {
|
| + ReplaceSubstringsAfterOffset(&result, 0,
|
| + ASCIIToUTF16(kSearchTermsParameterFull),
|
| + ASCIIToUTF16(kDisplaySearchTerms));
|
| + ReplaceSubstringsAfterOffset(&result, 0,
|
| + ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull),
|
| + ASCIIToUTF16(kDisplayUnescapedSearchTerms));
|
| + }
|
| return result;
|
| }
|
|
|
| @@ -368,12 +369,6 @@
|
| return false;
|
| }
|
|
|
| -// static
|
| -bool TemplateURLRef::SameUrlRefs(const TemplateURLRef* ref1,
|
| - const TemplateURLRef* ref2) {
|
| - return ref1 == ref2 || (ref1 && ref2 && ref1->url() == ref2->url());
|
| -}
|
| -
|
| void TemplateURLRef::CollectRLZMetrics() const {
|
| #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
|
| ParseIfNecessary();
|
| @@ -404,11 +399,6 @@
|
| replacements_.clear();
|
| }
|
|
|
| -void TemplateURLRef::Set(const std::string& url) {
|
| - url_ = url;
|
| - InvalidateCachedValues();
|
| -}
|
| -
|
| bool TemplateURLRef::ParseParameter(size_t start,
|
| size_t end,
|
| std::string* url,
|
| @@ -518,7 +508,7 @@
|
| const SearchTermsData& search_terms_data) const {
|
| if (!parsed_) {
|
| parsed_ = true;
|
| - parsed_url_ = ParseURL(url_, &replacements_, &valid_);
|
| + parsed_url_ = ParseURL(GetURL(), &replacements_, &valid_);
|
| supports_replacements_ = false;
|
| if (valid_) {
|
| bool has_only_one_search_term = false;
|
| @@ -544,7 +534,7 @@
|
|
|
| void TemplateURLRef::ParseHostAndSearchTermKey(
|
| const SearchTermsData& search_terms_data) const {
|
| - std::string url_string = url_;
|
| + std::string url_string(GetURL());
|
| ReplaceSubstringsAfterOffset(&url_string, 0,
|
| kGoogleBaseURLParameterFull,
|
| search_terms_data.GoogleBaseURLValue());
|
| @@ -583,10 +573,7 @@
|
| // TemplateURL ----------------------------------------------------------------
|
|
|
| TemplateURL::TemplateURL()
|
| - : url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - suggestions_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - instant_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - autogenerate_keyword_(false),
|
| + : autogenerate_keyword_(false),
|
| keyword_generated_(false),
|
| show_in_default_list_(false),
|
| safe_for_autoreplace_(false),
|
| @@ -596,14 +583,19 @@
|
| created_by_policy_(false),
|
| usage_count_(0),
|
| prepopulate_id_(0),
|
| - sync_guid_(guid::GenerateGUID()) {
|
| + sync_guid_(guid::GenerateGUID()),
|
| + url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
|
| + suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
|
| + TemplateURLRef::SUGGEST),
|
| + instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
|
| + TemplateURLRef::INSTANT) {
|
| }
|
|
|
| TemplateURL::TemplateURL(const TemplateURL& other)
|
| : short_name_(other.short_name_),
|
| - url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - suggestions_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| - instant_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
|
| + url_(other.url_),
|
| + suggestions_url_(other.suggestions_url_),
|
| + instant_url_(other.instant_url_),
|
| originating_url_(other.originating_url_),
|
| keyword_(other.keyword_),
|
| autogenerate_keyword_(other.autogenerate_keyword_),
|
| @@ -617,7 +609,12 @@
|
| last_modified_(other.last_modified_),
|
| created_by_policy_(other.created_by_policy_),
|
| usage_count_(other.usage_count_),
|
| - sync_guid_(other.sync_guid_) {
|
| + sync_guid_(other.sync_guid_),
|
| + url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
|
| + suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
|
| + TemplateURLRef::SUGGEST),
|
| + instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
|
| + TemplateURLRef::INSTANT) {
|
| CopyURLRefs(other);
|
| }
|
|
|
| @@ -626,7 +623,9 @@
|
| return *this;
|
|
|
| short_name_ = other.short_name_;
|
| - CopyURLRefs(other);
|
| + url_ = other.url_;
|
| + suggestions_url_ = other.suggestions_url_;
|
| + instant_url_ = other.instant_url_;
|
| originating_url_ = other.originating_url_;
|
| keyword_ = other.keyword_;
|
| autogenerate_keyword_ = other.autogenerate_keyword_;
|
| @@ -641,6 +640,7 @@
|
| created_by_policy_ = other.created_by_policy_;
|
| usage_count_ = other.usage_count_;
|
| sync_guid_ = other.sync_guid_;
|
| + CopyURLRefs(other);
|
| return *this;
|
| }
|
|
|
| @@ -670,15 +670,18 @@
|
| }
|
|
|
| void TemplateURL::SetURL(const std::string& url) {
|
| - url_.Set(url);
|
| + url_ = url;
|
| + url_ref_.InvalidateCachedValues();
|
| }
|
|
|
| void TemplateURL::SetSuggestionsURL(const std::string& url) {
|
| - suggestions_url_.Set(url);
|
| + suggestions_url_ = url;
|
| + suggestions_url_ref_.InvalidateCachedValues();
|
| }
|
|
|
| void TemplateURL::SetInstantURL(const std::string& url) {
|
| - instant_url_.Set(url);
|
| + instant_url_ = url;
|
| + instant_url_ref_.InvalidateCachedValues();
|
| }
|
|
|
| void TemplateURL::set_keyword(const string16& keyword) {
|
| @@ -703,27 +706,28 @@
|
| }
|
|
|
| bool TemplateURL::ShowInDefaultList() const {
|
| - return show_in_default_list() && url() && url()->SupportsReplacement();
|
| + return show_in_default_list() && url_ref_.SupportsReplacement();
|
| }
|
|
|
| void TemplateURL::CopyURLRefs(const TemplateURL& other) {
|
| - suggestions_url_.Set(other.suggestions_url_.url_);
|
| - url_.Set(other.url_.url_);
|
| - instant_url_.Set(other.instant_url_.url_);
|
| + url_ref_.InvalidateCachedValues();
|
| + suggestions_url_ref_.InvalidateCachedValues();
|
| + instant_url_ref_.InvalidateCachedValues();
|
| SetPrepopulateId(other.prepopulate_id_);
|
| }
|
|
|
| void TemplateURL::SetPrepopulateId(int id) {
|
| prepopulate_id_ = id;
|
| const bool prepopulated = id > 0;
|
| - suggestions_url_.prepopulated_ = prepopulated;
|
| - url_.prepopulated_ = prepopulated;
|
| - instant_url_.prepopulated_ = prepopulated;
|
| + suggestions_url_ref_.prepopulated_ = prepopulated;
|
| + url_ref_.prepopulated_ = prepopulated;
|
| + instant_url_ref_.prepopulated_ = prepopulated;
|
| }
|
|
|
| void TemplateURL::InvalidateCachedValues() const {
|
| - url_.InvalidateCachedValues();
|
| - suggestions_url_.InvalidateCachedValues();
|
| + url_ref_.InvalidateCachedValues();
|
| + suggestions_url_ref_.InvalidateCachedValues();
|
| + instant_url_ref_.InvalidateCachedValues();
|
| if (autogenerate_keyword_) {
|
| keyword_.clear();
|
| keyword_generated_ = false;
|
| @@ -737,14 +741,14 @@
|
|
|
| bool TemplateURL::SupportsReplacementUsingTermsData(
|
| const SearchTermsData& search_terms_data) const {
|
| - return url_.SupportsReplacementUsingTermsData(search_terms_data);
|
| + return url_ref_.SupportsReplacementUsingTermsData(search_terms_data);
|
| }
|
|
|
| std::string TemplateURL::GetExtensionId() const {
|
| DCHECK(IsExtensionKeyword());
|
| - return GURL(url_.url()).host();
|
| + return GURL(url_).host();
|
| }
|
|
|
| bool TemplateURL::IsExtensionKeyword() const {
|
| - return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme);
|
| + return GURL(url_).SchemeIs(chrome::kExtensionScheme);
|
| }
|
|
|