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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // is made a friend so that it can be the exception to this pattern. | 491 // is made a friend so that it can be the exception to this pattern. |
492 class TemplateURL { | 492 class TemplateURL { |
493 public: | 493 public: |
494 enum Type { | 494 enum Type { |
495 // Regular search engine. | 495 // Regular search engine. |
496 NORMAL, | 496 NORMAL, |
497 // Installed by extension through Override Settings API. | 497 // Installed by extension through Override Settings API. |
498 NORMAL_CONTROLLED_BY_EXTENSION, | 498 NORMAL_CONTROLLED_BY_EXTENSION, |
499 // The keyword associated with an extension that uses the Omnibox API. | 499 // The keyword associated with an extension that uses the Omnibox API. |
500 OMNIBOX_API_EXTENSION, | 500 OMNIBOX_API_EXTENSION, |
| 501 // Installed only on this device. Should not be synced. |
| 502 LOCAL, |
501 }; | 503 }; |
502 | 504 |
503 // An AssociatedExtensionInfo represents information about the extension that | 505 // An AssociatedExtensionInfo represents information about the extension that |
504 // added the search engine. | 506 // added the search engine. |
505 struct AssociatedExtensionInfo { | 507 struct AssociatedExtensionInfo { |
506 AssociatedExtensionInfo(Type type, const std::string& extension_id); | 508 explicit AssociatedExtensionInfo(const std::string& extension_id); |
507 ~AssociatedExtensionInfo(); | 509 ~AssociatedExtensionInfo(); |
508 | 510 |
509 Type type; | |
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 | 515 |
516 // Used to resolve conflicts when there are multiple extensions specifying | 516 // Used to resolve conflicts when there are multiple extensions specifying |
517 // the default search engine. The most recently-installed wins. | 517 // the default search engine. The most recently-installed wins. |
518 base::Time install_time; | 518 base::Time install_time; |
519 }; | 519 }; |
520 | 520 |
521 explicit TemplateURL(const TemplateURLData& data); | 521 explicit TemplateURL(const TemplateURLData& data, Type type = NORMAL); |
522 ~TemplateURL(); | 522 ~TemplateURL(); |
523 | 523 |
524 // Generates a suitable keyword for the specified url, which must be valid. | 524 // 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 | 525 // This is guaranteed not to return an empty string, since TemplateURLs should |
526 // never have an empty keyword. | 526 // never have an empty keyword. |
527 static base::string16 GenerateKeyword(const GURL& url); | 527 static base::string16 GenerateKeyword(const GURL& url); |
528 | 528 |
529 // Generates a favicon URL from the specified url. | 529 // Generates a favicon URL from the specified url. |
530 static GURL GenerateFaviconURL(const GURL& url); | 530 static GURL GenerateFaviconURL(const GURL& url); |
531 | 531 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 const TemplateURLRef& suggestions_url_ref() const { | 605 const TemplateURLRef& suggestions_url_ref() const { |
606 return suggestions_url_ref_; | 606 return suggestions_url_ref_; |
607 } | 607 } |
608 const TemplateURLRef& instant_url_ref() const { return instant_url_ref_; } | 608 const TemplateURLRef& instant_url_ref() const { return instant_url_ref_; } |
609 const TemplateURLRef& image_url_ref() const { return image_url_ref_; } | 609 const TemplateURLRef& image_url_ref() const { return image_url_ref_; } |
610 const TemplateURLRef& new_tab_url_ref() const { return new_tab_url_ref_; } | 610 const TemplateURLRef& new_tab_url_ref() const { return new_tab_url_ref_; } |
611 const TemplateURLRef& contextual_search_url_ref() const { | 611 const TemplateURLRef& contextual_search_url_ref() const { |
612 return contextual_search_url_ref_; | 612 return contextual_search_url_ref_; |
613 } | 613 } |
614 | 614 |
| 615 Type type() const { return type_; } |
| 616 // TODO(ianwen): remove set_type() once RestoreExtensionInfoIfNecessary() no |
| 617 // longer needs it. |
| 618 void set_type(Type type) { type_ = type; } |
| 619 |
615 // This setter shouldn't be used except by TemplateURLService and | 620 // This setter shouldn't be used except by TemplateURLService and |
616 // TemplateURLServiceClient implementations. | 621 // TemplateURLServiceClient implementations. |
617 void set_extension_info( | 622 void set_extension_info( |
618 std::unique_ptr<AssociatedExtensionInfo> extension_info) { | 623 std::unique_ptr<AssociatedExtensionInfo> extension_info) { |
619 extension_info_ = std::move(extension_info); | 624 extension_info_ = std::move(extension_info); |
620 } | 625 } |
621 | 626 |
622 // Returns true if |url| supports replacement. | 627 // Returns true if |url| supports replacement. |
623 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; | 628 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; |
624 | 629 |
625 // Returns true if any URLRefs use Googe base URLs. | 630 // Returns true if any URLRefs use Googe base URLs. |
626 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; | 631 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; |
627 | 632 |
628 // Returns true if this TemplateURL uses Google base URLs and has a keyword | 633 // Returns true if this TemplateURL uses Google base URLs and has a keyword |
629 // of "google.TLD". We use this to decide whether we can automatically | 634 // of "google.TLD". We use this to decide whether we can automatically |
630 // update the keyword to reflect the current Google base URL TLD. | 635 // update the keyword to reflect the current Google base URL TLD. |
631 bool IsGoogleSearchURLWithReplaceableKeyword( | 636 bool IsGoogleSearchURLWithReplaceableKeyword( |
632 const SearchTermsData& search_terms_data) const; | 637 const SearchTermsData& search_terms_data) const; |
633 | 638 |
634 // Returns true if the keywords match or if | 639 // Returns true if the keywords match or if |
635 // IsGoogleSearchURLWithReplaceableKeyword() is true for both |this| and | 640 // IsGoogleSearchURLWithReplaceableKeyword() is true for both |this| and |
636 // |other|. | 641 // |other|. |
637 bool HasSameKeywordAs(const TemplateURLData& other, | 642 bool HasSameKeywordAs(const TemplateURLData& other, |
638 const SearchTermsData& search_terms_data) const; | 643 const SearchTermsData& search_terms_data) const; |
639 | 644 |
640 Type GetType() const; | |
641 | |
642 // Returns the id of the extension that added this search engine. Only call | 645 // Returns the id of the extension that added this search engine. Only call |
643 // this for TemplateURLs of type NORMAL_CONTROLLED_BY_EXTENSION or | 646 // this for TemplateURLs of type NORMAL_CONTROLLED_BY_EXTENSION or |
644 // OMNIBOX_API_EXTENSION. | 647 // OMNIBOX_API_EXTENSION. |
645 std::string GetExtensionId() const; | 648 std::string GetExtensionId() const; |
646 | 649 |
647 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no | 650 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no |
648 // engines match. | 651 // engines match. |
649 SearchEngineType GetEngineType( | 652 SearchEngineType GetEngineType( |
650 const SearchTermsData& search_terms_data) const; | 653 const SearchTermsData& search_terms_data) const; |
651 | 654 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // URL. | 750 // URL. |
748 TemplateURLRef* url_ref_; | 751 TemplateURLRef* url_ref_; |
749 | 752 |
750 TemplateURLRef suggestions_url_ref_; | 753 TemplateURLRef suggestions_url_ref_; |
751 TemplateURLRef instant_url_ref_; | 754 TemplateURLRef instant_url_ref_; |
752 TemplateURLRef image_url_ref_; | 755 TemplateURLRef image_url_ref_; |
753 TemplateURLRef new_tab_url_ref_; | 756 TemplateURLRef new_tab_url_ref_; |
754 TemplateURLRef contextual_search_url_ref_; | 757 TemplateURLRef contextual_search_url_ref_; |
755 std::unique_ptr<AssociatedExtensionInfo> extension_info_; | 758 std::unique_ptr<AssociatedExtensionInfo> extension_info_; |
756 | 759 |
| 760 Type type_; |
| 761 |
757 // Caches the computed engine type across successive calls to GetEngineType(). | 762 // Caches the computed engine type across successive calls to GetEngineType(). |
758 mutable SearchEngineType engine_type_; | 763 mutable SearchEngineType engine_type_; |
759 | 764 |
760 // TODO(sky): Add date last parsed OSD file. | 765 // TODO(sky): Add date last parsed OSD file. |
761 | 766 |
762 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 767 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
763 }; | 768 }; |
764 | 769 |
765 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 770 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |