OLD | NEW |
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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 bool TemplateURLRef::SupportsReplacementUsingTermsData( | 114 bool TemplateURLRef::SupportsReplacementUsingTermsData( |
115 const SearchTermsData& search_terms_data) const { | 115 const SearchTermsData& search_terms_data) const { |
116 ParseIfNecessaryUsingTermsData(search_terms_data); | 116 ParseIfNecessaryUsingTermsData(search_terms_data); |
117 return valid_ && supports_replacements_; | 117 return valid_ && supports_replacements_; |
118 } | 118 } |
119 | 119 |
120 std::string TemplateURLRef::ReplaceSearchTerms( | 120 std::string TemplateURLRef::ReplaceSearchTerms( |
121 const string16& terms, | 121 const string16& terms, |
122 int accepted_suggestion, | 122 int accepted_suggestion, |
123 const string16& original_query_for_suggestion) const { | 123 const string16& original_query_for_suggestion) const { |
124 return ReplaceSearchTermsUsingProfile(NULL, terms, accepted_suggestion, | |
125 original_query_for_suggestion); | |
126 } | |
127 | |
128 std::string TemplateURLRef::ReplaceSearchTermsUsingProfile( | |
129 Profile* profile, | |
130 const string16& terms, | |
131 int accepted_suggestion, | |
132 const string16& original_query_for_suggestion) const { | |
133 UIThreadSearchTermsData search_terms_data; | 124 UIThreadSearchTermsData search_terms_data; |
134 search_terms_data.set_profile(profile); | 125 search_terms_data.set_profile(owner_->profile()); |
135 return ReplaceSearchTermsUsingTermsData(terms, accepted_suggestion, | 126 return ReplaceSearchTermsUsingTermsData(terms, accepted_suggestion, |
136 original_query_for_suggestion, search_terms_data); | 127 original_query_for_suggestion, search_terms_data); |
137 } | 128 } |
138 | 129 |
139 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( | 130 std::string TemplateURLRef::ReplaceSearchTermsUsingTermsData( |
140 const string16& terms, | 131 const string16& terms, |
141 int accepted_suggestion, | 132 int accepted_suggestion, |
142 const string16& original_query_for_suggestion, | 133 const string16& original_query_for_suggestion, |
143 const SearchTermsData& search_terms_data) const { | 134 const SearchTermsData& search_terms_data) const { |
144 ParseIfNecessaryUsingTermsData(search_terms_data); | 135 ParseIfNecessaryUsingTermsData(search_terms_data); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 } | 607 } |
617 | 608 |
618 void TemplateURLData::SetURL(const std::string& url) { | 609 void TemplateURLData::SetURL(const std::string& url) { |
619 DCHECK(!url.empty()); | 610 DCHECK(!url.empty()); |
620 url_ = url; | 611 url_ = url; |
621 } | 612 } |
622 | 613 |
623 | 614 |
624 // TemplateURL ---------------------------------------------------------------- | 615 // TemplateURL ---------------------------------------------------------------- |
625 | 616 |
626 TemplateURL::TemplateURL(const TemplateURLData& data) | 617 TemplateURL::TemplateURL(Profile* profile, const TemplateURLData& data) |
627 : data_(data), | 618 : profile_(profile), |
| 619 data_(data), |
628 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH), | 620 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH), |
629 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 621 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
630 TemplateURLRef::SUGGEST), | 622 TemplateURLRef::SUGGEST), |
631 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 623 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
632 TemplateURLRef::INSTANT) { | 624 TemplateURLRef::INSTANT) { |
633 SetPrepopulateId(data_.prepopulate_id); | 625 SetPrepopulateId(data_.prepopulate_id); |
634 } | 626 } |
635 | 627 |
636 TemplateURL::TemplateURL(const TemplateURL& other) | 628 TemplateURL::TemplateURL(const TemplateURL& other) |
637 : data_(other.data_), | 629 : profile_(other.profile_), |
| 630 data_(other.data_), |
638 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH), | 631 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH), |
639 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 632 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
640 TemplateURLRef::SUGGEST), | 633 TemplateURLRef::SUGGEST), |
641 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), | 634 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), |
642 TemplateURLRef::INSTANT) { | 635 TemplateURLRef::INSTANT) { |
643 SetPrepopulateId(data_.prepopulate_id); | 636 SetPrepopulateId(data_.prepopulate_id); |
644 } | 637 } |
645 | 638 |
646 TemplateURL& TemplateURL::operator=(const TemplateURL& other) { | 639 TemplateURL& TemplateURL::operator=(const TemplateURL& other) { |
647 if (this == &other) | 640 if (this == &other) |
648 return *this; | 641 return *this; |
649 | 642 |
| 643 profile_ = other.profile_; |
650 data_ = other.data_; | 644 data_ = other.data_; |
651 url_ref_.InvalidateCachedValues(); | 645 url_ref_.InvalidateCachedValues(); |
652 suggestions_url_ref_.InvalidateCachedValues(); | 646 suggestions_url_ref_.InvalidateCachedValues(); |
653 instant_url_ref_.InvalidateCachedValues(); | 647 instant_url_ref_.InvalidateCachedValues(); |
654 SetPrepopulateId(data_.prepopulate_id); | 648 SetPrepopulateId(data_.prepopulate_id); |
655 return *this; | 649 return *this; |
656 } | 650 } |
657 | 651 |
658 TemplateURL::~TemplateURL() { | 652 TemplateURL::~TemplateURL() { |
659 } | 653 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 suggestions_url_ref_.prepopulated_ = prepopulated; | 709 suggestions_url_ref_.prepopulated_ = prepopulated; |
716 instant_url_ref_.prepopulated_ = prepopulated; | 710 instant_url_ref_.prepopulated_ = prepopulated; |
717 } | 711 } |
718 | 712 |
719 void TemplateURL::InvalidateCachedValues() { | 713 void TemplateURL::InvalidateCachedValues() { |
720 url_ref_.InvalidateCachedValues(); | 714 url_ref_.InvalidateCachedValues(); |
721 suggestions_url_ref_.InvalidateCachedValues(); | 715 suggestions_url_ref_.InvalidateCachedValues(); |
722 instant_url_ref_.InvalidateCachedValues(); | 716 instant_url_ref_.InvalidateCachedValues(); |
723 data_.SetAutogenerateKeyword(data_.autogenerate_keyword()); | 717 data_.SetAutogenerateKeyword(data_.autogenerate_keyword()); |
724 } | 718 } |
OLD | NEW |