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

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

Issue 9965143: Revert 130431 - Move the URL string from TemplateURLRef onto the owning TemplateURL. This will mak… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Used if the count parameter is not optional. Indicates we want 10 search 79 // Used if the count parameter is not optional. Indicates we want 10 search
80 // results. 80 // results.
81 static const char kDefaultCount[] = "10"; 81 static const char kDefaultCount[] = "10";
82 82
83 // Used if the parameter kOutputEncodingParameter is required. 83 // Used if the parameter kOutputEncodingParameter is required.
84 static const char kOutputEncodingType[] = "UTF-8"; 84 static const char kOutputEncodingType[] = "UTF-8";
85 85
86 86
87 // TemplateURLRef ------------------------------------------------------------- 87 // TemplateURLRef -------------------------------------------------------------
88 88
89 TemplateURLRef::TemplateURLRef(TemplateURL* owner, Type type) 89 TemplateURLRef::TemplateURLRef(TemplateURL* owner)
90 : owner_(owner), 90 : owner_(owner),
91 type_(type),
92 parsed_(false),
93 valid_(false),
94 supports_replacements_(false),
95 prepopulated_(false) { 91 prepopulated_(false) {
96 DCHECK(owner_); 92 DCHECK(owner_);
93 Set(std::string());
94 }
95
96 TemplateURLRef::TemplateURLRef(TemplateURL* owner, const std::string& url)
97 : owner_(owner),
98 prepopulated_(false) {
99 DCHECK(owner_);
100 Set(url);
97 } 101 }
98 102
99 TemplateURLRef::~TemplateURLRef() { 103 TemplateURLRef::~TemplateURLRef() {
100 } 104 }
101 105
102 std::string TemplateURLRef::GetURL() const {
103 switch (type_) {
104 case SEARCH: return owner_->url();
105 case SUGGEST: return owner_->suggestions_url();
106 case INSTANT: return owner_->instant_url();
107 default: NOTREACHED(); return std::string();
108 }
109 }
110
111 bool TemplateURLRef::SupportsReplacement() const { 106 bool TemplateURLRef::SupportsReplacement() const {
112 UIThreadSearchTermsData search_terms_data; 107 UIThreadSearchTermsData search_terms_data;
113 return SupportsReplacementUsingTermsData(search_terms_data); 108 return SupportsReplacementUsingTermsData(search_terms_data);
114 } 109 }
115 110
116 bool TemplateURLRef::SupportsReplacementUsingTermsData( 111 bool TemplateURLRef::SupportsReplacementUsingTermsData(
117 const SearchTermsData& search_terms_data) const { 112 const SearchTermsData& search_terms_data) const {
118 ParseIfNecessaryUsingTermsData(search_terms_data); 113 ParseIfNecessaryUsingTermsData(search_terms_data);
119 return valid_ && supports_replacements_; 114 return valid_ && supports_replacements_;
120 } 115 }
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 280 }
286 281
287 bool TemplateURLRef::IsValidUsingTermsData( 282 bool TemplateURLRef::IsValidUsingTermsData(
288 const SearchTermsData& search_terms_data) const { 283 const SearchTermsData& search_terms_data) const {
289 ParseIfNecessaryUsingTermsData(search_terms_data); 284 ParseIfNecessaryUsingTermsData(search_terms_data);
290 return valid_; 285 return valid_;
291 } 286 }
292 287
293 string16 TemplateURLRef::DisplayURL() const { 288 string16 TemplateURLRef::DisplayURL() const {
294 ParseIfNecessary(); 289 ParseIfNecessary();
295 string16 result(UTF8ToUTF16(GetURL())); 290 if (!valid_ || replacements_.empty())
296 if (valid_ && !replacements_.empty()) { 291 return UTF8ToUTF16(url_);
297 ReplaceSubstringsAfterOffset(&result, 0, 292
298 ASCIIToUTF16(kSearchTermsParameterFull), 293 string16 result = UTF8ToUTF16(url_);
299 ASCIIToUTF16(kDisplaySearchTerms)); 294 ReplaceSubstringsAfterOffset(&result, 0,
300 ReplaceSubstringsAfterOffset(&result, 0, 295 ASCIIToUTF16(kSearchTermsParameterFull),
301 ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull), 296 ASCIIToUTF16(kDisplaySearchTerms));
302 ASCIIToUTF16(kDisplayUnescapedSearchTerms)); 297
303 } 298 ReplaceSubstringsAfterOffset(
299 &result, 0,
300 ASCIIToUTF16(kGoogleUnescapedSearchTermsParameterFull),
301 ASCIIToUTF16(kDisplayUnescapedSearchTerms));
302
304 return result; 303 return result;
305 } 304 }
306 305
307 // static 306 // static
308 std::string TemplateURLRef::DisplayURLToURLRef( 307 std::string TemplateURLRef::DisplayURLToURLRef(
309 const string16& display_url) { 308 const string16& display_url) {
310 string16 result = display_url; 309 string16 result = display_url;
311 ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16(kDisplaySearchTerms), 310 ReplaceSubstringsAfterOffset(&result, 0, ASCIIToUTF16(kDisplaySearchTerms),
312 ASCIIToUTF16(kSearchTermsParameterFull)); 311 ASCIIToUTF16(kSearchTermsParameterFull));
313 ReplaceSubstringsAfterOffset( 312 ReplaceSubstringsAfterOffset(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 bool TemplateURLRef::HasGoogleBaseURLs() const { 361 bool TemplateURLRef::HasGoogleBaseURLs() const {
363 ParseIfNecessary(); 362 ParseIfNecessary();
364 for (size_t i = 0; i < replacements_.size(); ++i) { 363 for (size_t i = 0; i < replacements_.size(); ++i) {
365 if ((replacements_[i].type == GOOGLE_BASE_URL) || 364 if ((replacements_[i].type == GOOGLE_BASE_URL) ||
366 (replacements_[i].type == GOOGLE_BASE_SUGGEST_URL)) 365 (replacements_[i].type == GOOGLE_BASE_SUGGEST_URL))
367 return true; 366 return true;
368 } 367 }
369 return false; 368 return false;
370 } 369 }
371 370
371 // static
372 bool TemplateURLRef::SameUrlRefs(const TemplateURLRef* ref1,
373 const TemplateURLRef* ref2) {
374 return ref1 == ref2 || (ref1 && ref2 && ref1->url() == ref2->url());
375 }
376
372 void TemplateURLRef::CollectRLZMetrics() const { 377 void TemplateURLRef::CollectRLZMetrics() const {
373 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) 378 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD)
374 ParseIfNecessary(); 379 ParseIfNecessary();
375 for (size_t i = 0; i < replacements_.size(); ++i) { 380 for (size_t i = 0; i < replacements_.size(); ++i) {
376 // We are interesed in searches that were supposed to send the RLZ token. 381 // We are interesed in searches that were supposed to send the RLZ token.
377 if (replacements_[i].type == GOOGLE_RLZ) { 382 if (replacements_[i].type == GOOGLE_RLZ) {
378 std::string brand; 383 std::string brand;
379 // We only have RLZ tocken on a branded browser version. 384 // We only have RLZ tocken on a branded browser version.
380 if (google_util::GetBrand(&brand) && !brand.empty() && 385 if (google_util::GetBrand(&brand) && !brand.empty() &&
381 !google_util::IsOrganic(brand)) { 386 !google_util::IsOrganic(brand)) {
(...skipping 10 matching lines...) Expand all
392 } 397 }
393 398
394 void TemplateURLRef::InvalidateCachedValues() const { 399 void TemplateURLRef::InvalidateCachedValues() const {
395 supports_replacements_ = valid_ = parsed_ = false; 400 supports_replacements_ = valid_ = parsed_ = false;
396 host_.clear(); 401 host_.clear();
397 path_.clear(); 402 path_.clear();
398 search_term_key_.clear(); 403 search_term_key_.clear();
399 replacements_.clear(); 404 replacements_.clear();
400 } 405 }
401 406
407 void TemplateURLRef::Set(const std::string& url) {
408 url_ = url;
409 InvalidateCachedValues();
410 }
411
402 bool TemplateURLRef::ParseParameter(size_t start, 412 bool TemplateURLRef::ParseParameter(size_t start,
403 size_t end, 413 size_t end,
404 std::string* url, 414 std::string* url,
405 Replacements* replacements) const { 415 Replacements* replacements) const {
406 DCHECK(start != std::string::npos && 416 DCHECK(start != std::string::npos &&
407 end != std::string::npos && end > start); 417 end != std::string::npos && end > start);
408 size_t length = end - start - 1; 418 size_t length = end - start - 1;
409 bool optional = false; 419 bool optional = false;
410 if ((*url)[end - 1] == kOptional) { 420 if ((*url)[end - 1] == kOptional) {
411 optional = true; 421 optional = true;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 511
502 void TemplateURLRef::ParseIfNecessary() const { 512 void TemplateURLRef::ParseIfNecessary() const {
503 UIThreadSearchTermsData search_terms_data; 513 UIThreadSearchTermsData search_terms_data;
504 ParseIfNecessaryUsingTermsData(search_terms_data); 514 ParseIfNecessaryUsingTermsData(search_terms_data);
505 } 515 }
506 516
507 void TemplateURLRef::ParseIfNecessaryUsingTermsData( 517 void TemplateURLRef::ParseIfNecessaryUsingTermsData(
508 const SearchTermsData& search_terms_data) const { 518 const SearchTermsData& search_terms_data) const {
509 if (!parsed_) { 519 if (!parsed_) {
510 parsed_ = true; 520 parsed_ = true;
511 parsed_url_ = ParseURL(GetURL(), &replacements_, &valid_); 521 parsed_url_ = ParseURL(url_, &replacements_, &valid_);
512 supports_replacements_ = false; 522 supports_replacements_ = false;
513 if (valid_) { 523 if (valid_) {
514 bool has_only_one_search_term = false; 524 bool has_only_one_search_term = false;
515 for (Replacements::const_iterator i = replacements_.begin(); 525 for (Replacements::const_iterator i = replacements_.begin();
516 i != replacements_.end(); ++i) { 526 i != replacements_.end(); ++i) {
517 if ((i->type == SEARCH_TERMS) || 527 if ((i->type == SEARCH_TERMS) ||
518 (i->type == GOOGLE_UNESCAPED_SEARCH_TERMS)) { 528 (i->type == GOOGLE_UNESCAPED_SEARCH_TERMS)) {
519 if (has_only_one_search_term) { 529 if (has_only_one_search_term) {
520 has_only_one_search_term = false; 530 has_only_one_search_term = false;
521 break; 531 break;
522 } 532 }
523 has_only_one_search_term = true; 533 has_only_one_search_term = true;
524 supports_replacements_ = true; 534 supports_replacements_ = true;
525 } 535 }
526 } 536 }
527 // Only parse the host/key if there is one search term. Technically there 537 // Only parse the host/key if there is one search term. Technically there
528 // could be more than one term, but it's uncommon; so we punt. 538 // could be more than one term, but it's uncommon; so we punt.
529 if (has_only_one_search_term) 539 if (has_only_one_search_term)
530 ParseHostAndSearchTermKey(search_terms_data); 540 ParseHostAndSearchTermKey(search_terms_data);
531 } 541 }
532 } 542 }
533 } 543 }
534 544
535 void TemplateURLRef::ParseHostAndSearchTermKey( 545 void TemplateURLRef::ParseHostAndSearchTermKey(
536 const SearchTermsData& search_terms_data) const { 546 const SearchTermsData& search_terms_data) const {
537 std::string url_string(GetURL()); 547 std::string url_string = url_;
538 ReplaceSubstringsAfterOffset(&url_string, 0, 548 ReplaceSubstringsAfterOffset(&url_string, 0,
539 kGoogleBaseURLParameterFull, 549 kGoogleBaseURLParameterFull,
540 search_terms_data.GoogleBaseURLValue()); 550 search_terms_data.GoogleBaseURLValue());
541 ReplaceSubstringsAfterOffset(&url_string, 0, 551 ReplaceSubstringsAfterOffset(&url_string, 0,
542 kGoogleBaseSuggestURLParameterFull, 552 kGoogleBaseSuggestURLParameterFull,
543 search_terms_data.GoogleBaseSuggestURLValue()); 553 search_terms_data.GoogleBaseSuggestURLValue());
544 554
545 GURL url(url_string); 555 GURL url(url_string);
546 if (!url.is_valid()) 556 if (!url.is_valid())
547 return; 557 return;
(...skipping 18 matching lines...) Expand all
566 break; 576 break;
567 } 577 }
568 } 578 }
569 } 579 }
570 } 580 }
571 581
572 582
573 // TemplateURL ---------------------------------------------------------------- 583 // TemplateURL ----------------------------------------------------------------
574 584
575 TemplateURL::TemplateURL() 585 TemplateURL::TemplateURL()
576 : autogenerate_keyword_(false), 586 : url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
587 suggestions_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
588 instant_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
589 autogenerate_keyword_(false),
577 keyword_generated_(false), 590 keyword_generated_(false),
578 show_in_default_list_(false), 591 show_in_default_list_(false),
579 safe_for_autoreplace_(false), 592 safe_for_autoreplace_(false),
580 id_(0), 593 id_(0),
581 date_created_(base::Time::Now()), 594 date_created_(base::Time::Now()),
582 last_modified_(base::Time::Now()), 595 last_modified_(base::Time::Now()),
583 created_by_policy_(false), 596 created_by_policy_(false),
584 usage_count_(0), 597 usage_count_(0),
585 prepopulate_id_(0), 598 prepopulate_id_(0),
586 sync_guid_(guid::GenerateGUID()), 599 sync_guid_(guid::GenerateGUID()) {
587 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
588 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
589 TemplateURLRef::SUGGEST),
590 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
591 TemplateURLRef::INSTANT) {
592 } 600 }
593 601
594 TemplateURL::TemplateURL(const TemplateURL& other) 602 TemplateURL::TemplateURL(const TemplateURL& other)
595 : short_name_(other.short_name_), 603 : short_name_(other.short_name_),
596 url_(other.url_), 604 url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
597 suggestions_url_(other.suggestions_url_), 605 suggestions_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
598 instant_url_(other.instant_url_), 606 instant_url_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
599 originating_url_(other.originating_url_), 607 originating_url_(other.originating_url_),
600 keyword_(other.keyword_), 608 keyword_(other.keyword_),
601 autogenerate_keyword_(other.autogenerate_keyword_), 609 autogenerate_keyword_(other.autogenerate_keyword_),
602 keyword_generated_(other.keyword_generated_), 610 keyword_generated_(other.keyword_generated_),
603 show_in_default_list_(other.show_in_default_list_), 611 show_in_default_list_(other.show_in_default_list_),
604 safe_for_autoreplace_(other.safe_for_autoreplace_), 612 safe_for_autoreplace_(other.safe_for_autoreplace_),
605 favicon_url_(other.favicon_url_), 613 favicon_url_(other.favicon_url_),
606 input_encodings_(other.input_encodings_), 614 input_encodings_(other.input_encodings_),
607 id_(other.id_), 615 id_(other.id_),
608 date_created_(other.date_created_), 616 date_created_(other.date_created_),
609 last_modified_(other.last_modified_), 617 last_modified_(other.last_modified_),
610 created_by_policy_(other.created_by_policy_), 618 created_by_policy_(other.created_by_policy_),
611 usage_count_(other.usage_count_), 619 usage_count_(other.usage_count_),
612 sync_guid_(other.sync_guid_), 620 sync_guid_(other.sync_guid_) {
613 url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this), TemplateURLRef::SEARCH),
614 suggestions_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
615 TemplateURLRef::SUGGEST),
616 instant_url_ref_(ALLOW_THIS_IN_INITIALIZER_LIST(this),
617 TemplateURLRef::INSTANT) {
618 CopyURLRefs(other); 621 CopyURLRefs(other);
619 } 622 }
620 623
621 TemplateURL& TemplateURL::operator=(const TemplateURL& other) { 624 TemplateURL& TemplateURL::operator=(const TemplateURL& other) {
622 if (this == &other) 625 if (this == &other)
623 return *this; 626 return *this;
624 627
625 short_name_ = other.short_name_; 628 short_name_ = other.short_name_;
626 url_ = other.url_; 629 CopyURLRefs(other);
627 suggestions_url_ = other.suggestions_url_;
628 instant_url_ = other.instant_url_;
629 originating_url_ = other.originating_url_; 630 originating_url_ = other.originating_url_;
630 keyword_ = other.keyword_; 631 keyword_ = other.keyword_;
631 autogenerate_keyword_ = other.autogenerate_keyword_; 632 autogenerate_keyword_ = other.autogenerate_keyword_;
632 keyword_generated_ = other.keyword_generated_; 633 keyword_generated_ = other.keyword_generated_;
633 show_in_default_list_ = other.show_in_default_list_; 634 show_in_default_list_ = other.show_in_default_list_;
634 safe_for_autoreplace_ = other.safe_for_autoreplace_; 635 safe_for_autoreplace_ = other.safe_for_autoreplace_;
635 favicon_url_ = other.favicon_url_; 636 favicon_url_ = other.favicon_url_;
636 input_encodings_ = other.input_encodings_; 637 input_encodings_ = other.input_encodings_;
637 id_ = other.id_; 638 id_ = other.id_;
638 date_created_ = other.date_created_; 639 date_created_ = other.date_created_;
639 last_modified_ = other.last_modified_; 640 last_modified_ = other.last_modified_;
640 created_by_policy_ = other.created_by_policy_; 641 created_by_policy_ = other.created_by_policy_;
641 usage_count_ = other.usage_count_; 642 usage_count_ = other.usage_count_;
642 sync_guid_ = other.sync_guid_; 643 sync_guid_ = other.sync_guid_;
643 CopyURLRefs(other);
644 return *this; 644 return *this;
645 } 645 }
646 646
647 TemplateURL::~TemplateURL() { 647 TemplateURL::~TemplateURL() {
648 } 648 }
649 649
650 // static 650 // static
651 GURL TemplateURL::GenerateFaviconURL(const GURL& url) { 651 GURL TemplateURL::GenerateFaviconURL(const GURL& url) {
652 DCHECK(url.is_valid()); 652 DCHECK(url.is_valid());
653 GURL::Replacements rep; 653 GURL::Replacements rep;
654 654
655 const char favicon_path[] = "/favicon.ico"; 655 const char favicon_path[] = "/favicon.ico";
656 int favicon_path_len = arraysize(favicon_path) - 1; 656 int favicon_path_len = arraysize(favicon_path) - 1;
657 657
658 rep.SetPath(favicon_path, url_parse::Component(0, favicon_path_len)); 658 rep.SetPath(favicon_path, url_parse::Component(0, favicon_path_len));
659 rep.ClearUsername(); 659 rep.ClearUsername();
660 rep.ClearPassword(); 660 rep.ClearPassword();
661 rep.ClearQuery(); 661 rep.ClearQuery();
662 rep.ClearRef(); 662 rep.ClearRef();
663 return url.ReplaceComponents(rep); 663 return url.ReplaceComponents(rep);
664 } 664 }
665 665
666 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 666 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
667 string16 bidi_safe_short_name = short_name_; 667 string16 bidi_safe_short_name = short_name_;
668 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 668 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
669 return bidi_safe_short_name; 669 return bidi_safe_short_name;
670 } 670 }
671 671
672 void TemplateURL::SetURL(const std::string& url) { 672 void TemplateURL::SetURL(const std::string& url) {
673 url_ = url; 673 url_.Set(url);
674 url_ref_.InvalidateCachedValues();
675 } 674 }
676 675
677 void TemplateURL::SetSuggestionsURL(const std::string& url) { 676 void TemplateURL::SetSuggestionsURL(const std::string& url) {
678 suggestions_url_ = url; 677 suggestions_url_.Set(url);
679 suggestions_url_ref_.InvalidateCachedValues();
680 } 678 }
681 679
682 void TemplateURL::SetInstantURL(const std::string& url) { 680 void TemplateURL::SetInstantURL(const std::string& url) {
683 instant_url_ = url; 681 instant_url_.Set(url);
684 instant_url_ref_.InvalidateCachedValues();
685 } 682 }
686 683
687 void TemplateURL::set_keyword(const string16& keyword) { 684 void TemplateURL::set_keyword(const string16& keyword) {
688 // Case sensitive keyword matching is confusing. As such, we force all 685 // Case sensitive keyword matching is confusing. As such, we force all
689 // keywords to be lower case. 686 // keywords to be lower case.
690 keyword_ = base::i18n::ToLower(keyword); 687 keyword_ = base::i18n::ToLower(keyword);
691 autogenerate_keyword_ = false; 688 autogenerate_keyword_ = false;
692 } 689 }
693 690
694 const string16& TemplateURL::keyword() const { 691 const string16& TemplateURL::keyword() const {
695 EnsureKeyword(); 692 EnsureKeyword();
696 return keyword_; 693 return keyword_;
697 } 694 }
698 695
699 void TemplateURL::EnsureKeyword() const { 696 void TemplateURL::EnsureKeyword() const {
700 if (autogenerate_keyword_ && !keyword_generated_) { 697 if (autogenerate_keyword_ && !keyword_generated_) {
701 // Generate a keyword and cache it. 698 // Generate a keyword and cache it.
702 keyword_ = TemplateURLService::GenerateKeyword( 699 keyword_ = TemplateURLService::GenerateKeyword(
703 TemplateURLService::GenerateSearchURL(this).GetWithEmptyPath(), true); 700 TemplateURLService::GenerateSearchURL(this).GetWithEmptyPath(), true);
704 keyword_generated_ = true; 701 keyword_generated_ = true;
705 } 702 }
706 } 703 }
707 704
708 bool TemplateURL::ShowInDefaultList() const { 705 bool TemplateURL::ShowInDefaultList() const {
709 return show_in_default_list() && url_ref_.SupportsReplacement(); 706 return show_in_default_list() && url() && url()->SupportsReplacement();
710 } 707 }
711 708
712 void TemplateURL::CopyURLRefs(const TemplateURL& other) { 709 void TemplateURL::CopyURLRefs(const TemplateURL& other) {
713 url_ref_.InvalidateCachedValues(); 710 suggestions_url_.Set(other.suggestions_url_.url_);
714 suggestions_url_ref_.InvalidateCachedValues(); 711 url_.Set(other.url_.url_);
715 instant_url_ref_.InvalidateCachedValues(); 712 instant_url_.Set(other.instant_url_.url_);
716 SetPrepopulateId(other.prepopulate_id_); 713 SetPrepopulateId(other.prepopulate_id_);
717 } 714 }
718 715
719 void TemplateURL::SetPrepopulateId(int id) { 716 void TemplateURL::SetPrepopulateId(int id) {
720 prepopulate_id_ = id; 717 prepopulate_id_ = id;
721 const bool prepopulated = id > 0; 718 const bool prepopulated = id > 0;
722 suggestions_url_ref_.prepopulated_ = prepopulated; 719 suggestions_url_.prepopulated_ = prepopulated;
723 url_ref_.prepopulated_ = prepopulated; 720 url_.prepopulated_ = prepopulated;
724 instant_url_ref_.prepopulated_ = prepopulated; 721 instant_url_.prepopulated_ = prepopulated;
725 } 722 }
726 723
727 void TemplateURL::InvalidateCachedValues() const { 724 void TemplateURL::InvalidateCachedValues() const {
728 url_ref_.InvalidateCachedValues(); 725 url_.InvalidateCachedValues();
729 suggestions_url_ref_.InvalidateCachedValues(); 726 suggestions_url_.InvalidateCachedValues();
730 instant_url_ref_.InvalidateCachedValues();
731 if (autogenerate_keyword_) { 727 if (autogenerate_keyword_) {
732 keyword_.clear(); 728 keyword_.clear();
733 keyword_generated_ = false; 729 keyword_generated_ = false;
734 } 730 }
735 } 731 }
736 732
737 bool TemplateURL::SupportsReplacement() const { 733 bool TemplateURL::SupportsReplacement() const {
738 UIThreadSearchTermsData search_terms_data; 734 UIThreadSearchTermsData search_terms_data;
739 return SupportsReplacementUsingTermsData(search_terms_data); 735 return SupportsReplacementUsingTermsData(search_terms_data);
740 } 736 }
741 737
742 bool TemplateURL::SupportsReplacementUsingTermsData( 738 bool TemplateURL::SupportsReplacementUsingTermsData(
743 const SearchTermsData& search_terms_data) const { 739 const SearchTermsData& search_terms_data) const {
744 return url_ref_.SupportsReplacementUsingTermsData(search_terms_data); 740 return url_.SupportsReplacementUsingTermsData(search_terms_data);
745 } 741 }
746 742
747 std::string TemplateURL::GetExtensionId() const { 743 std::string TemplateURL::GetExtensionId() const {
748 DCHECK(IsExtensionKeyword()); 744 DCHECK(IsExtensionKeyword());
749 return GURL(url_).host(); 745 return GURL(url_.url()).host();
750 } 746 }
751 747
752 bool TemplateURL::IsExtensionKeyword() const { 748 bool TemplateURL::IsExtensionKeyword() const {
753 return GURL(url_).SchemeIs(chrome::kExtensionScheme); 749 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme);
754 } 750 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/template_url.h ('k') | chrome/browser/search_engines/template_url_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698