OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
505 // An AssociatedExtensionInfo represents information about the extension that | 505 // An AssociatedExtensionInfo represents information about the extension that |
506 // added the search engine. | 506 // added the search engine. |
507 struct AssociatedExtensionInfo { | 507 struct AssociatedExtensionInfo { |
508 explicit AssociatedExtensionInfo(const std::string& extension_id); | 508 explicit AssociatedExtensionInfo(const std::string& extension_id); |
509 ~AssociatedExtensionInfo(); | 509 ~AssociatedExtensionInfo(); |
510 | 510 |
511 std::string extension_id; | 511 std::string extension_id; |
512 | 512 |
513 // Whether the search engine is supposed to be default. | 513 // Whether the search engine is supposed to be default. |
514 bool wants_to_be_default_engine; | 514 bool wants_to_be_default_engine; |
515 | |
516 // Used to resolve conflicts when there are multiple extensions specifying | |
517 // the default search engine. The most recently-installed wins. | |
518 base::Time install_time; | |
519 }; | 515 }; |
520 | 516 |
521 explicit TemplateURL(const TemplateURLData& data, Type type = NORMAL); | 517 explicit TemplateURL(const TemplateURLData& data, Type type = NORMAL); |
522 ~TemplateURL(); | 518 ~TemplateURL(); |
523 | 519 |
524 // Generates a suitable keyword for the specified url, which must be valid. | 520 // Generates a suitable keyword for the specified url, which must be valid. |
525 // This is guaranteed not to return an empty string, since TemplateURLs should | 521 // This is guaranteed not to return an empty string, since TemplateURLs should |
526 // never have an empty keyword. | 522 // never have an empty keyword. |
527 static base::string16 GenerateKeyword(const GURL& url); | 523 static base::string16 GenerateKeyword(const GURL& url); |
528 | 524 |
529 // Generates a favicon URL from the specified url. | 525 // Generates a favicon URL from the specified url. |
530 static GURL GenerateFaviconURL(const GURL& url); | 526 static GURL GenerateFaviconURL(const GURL& url); |
531 | 527 |
532 // Returns true if |t_url| and |data| are equal in all meaningful respects. | 528 // Returns true if |t_url| and |data| are equal in all meaningful respects. |
533 // Static to allow either or both params to be NULL. | 529 // Static to allow either or both params to be NULL. |
534 static bool MatchesData(const TemplateURL* t_url, | 530 static bool MatchesData(const TemplateURL* t_url, |
535 const TemplateURLData* data, | 531 const TemplateURLData* data, |
536 const SearchTermsData& search_terms_data); | 532 const SearchTermsData& search_terms_data); |
537 | 533 |
534 // Special case for search_terms_replacement_key comparison, because of | |
535 // its special initialization in TemplateUrl constructor. | |
536 static bool SearchTermsReplacementKeysMatch( | |
537 const std::string& search_terms_replacement_key1, | |
538 const std::string& search_terms_replacement_key2); | |
539 | |
538 const TemplateURLData& data() const { return data_; } | 540 const TemplateURLData& data() const { return data_; } |
539 | 541 |
540 const base::string16& short_name() const { return data_.short_name(); } | 542 const base::string16& short_name() const { return data_.short_name(); } |
541 // An accessor for the short_name, but adjusted so it can be appropriately | 543 // An accessor for the short_name, but adjusted so it can be appropriately |
542 // displayed even if it is LTR and the UI is RTL. | 544 // displayed even if it is LTR and the UI is RTL. |
543 base::string16 AdjustedShortNameForLocaleDirection() const; | 545 base::string16 AdjustedShortNameForLocaleDirection() const; |
544 | 546 |
545 const base::string16& keyword() const { return data_.keyword(); } | 547 const base::string16& keyword() const { return data_.keyword(); } |
546 | 548 |
547 const std::string& url() const { return data_.url(); } | 549 const std::string& url() const { return data_.url(); } |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 | 611 |
610 Type type() const { return type_; } | 612 Type type() const { return type_; } |
611 | 613 |
612 // This setter shouldn't be used except by TemplateURLService and | 614 // This setter shouldn't be used except by TemplateURLService and |
613 // TemplateURLServiceClient implementations. | 615 // TemplateURLServiceClient implementations. |
614 void set_extension_info( | 616 void set_extension_info( |
615 std::unique_ptr<AssociatedExtensionInfo> extension_info) { | 617 std::unique_ptr<AssociatedExtensionInfo> extension_info) { |
616 extension_info_ = std::move(extension_info); | 618 extension_info_ = std::move(extension_info); |
617 } | 619 } |
618 | 620 |
621 const AssociatedExtensionInfo* extension_info_for_tests() { | |
vasilii
2016/12/06 19:16:42
Use either ForTesting suffix or #if defined(UNIT_T
Alexander Yashkin
2016/12/09 08:19:52
Fixed
| |
622 return extension_info_.get(); | |
623 } | |
624 | |
619 // Returns true if |url| supports replacement. | 625 // Returns true if |url| supports replacement. |
620 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; | 626 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; |
621 | 627 |
622 // Returns true if any URLRefs use Googe base URLs. | 628 // Returns true if any URLRefs use Googe base URLs. |
623 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; | 629 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; |
624 | 630 |
625 // Returns true if this TemplateURL uses Google base URLs and has a keyword | 631 // Returns true if this TemplateURL uses Google base URLs and has a keyword |
626 // of "google.TLD". We use this to decide whether we can automatically | 632 // of "google.TLD". We use this to decide whether we can automatically |
627 // update the keyword to reflect the current Google base URL TLD. | 633 // update the keyword to reflect the current Google base URL TLD. |
628 bool IsGoogleSearchURLWithReplaceableKeyword( | 634 bool IsGoogleSearchURLWithReplaceableKeyword( |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 | 759 |
754 // Caches the computed engine type across successive calls to GetEngineType(). | 760 // Caches the computed engine type across successive calls to GetEngineType(). |
755 mutable SearchEngineType engine_type_; | 761 mutable SearchEngineType engine_type_; |
756 | 762 |
757 // TODO(sky): Add date last parsed OSD file. | 763 // TODO(sky): Add date last parsed OSD file. |
758 | 764 |
759 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 765 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
760 }; | 766 }; |
761 | 767 |
762 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 768 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |