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