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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 | 612 |
611 Type type() const { return type_; } | 613 Type type() const { return type_; } |
612 | 614 |
613 // This setter shouldn't be used except by TemplateURLService and | 615 // This setter shouldn't be used except by TemplateURLService and |
614 // TemplateURLServiceClient implementations. | 616 // TemplateURLServiceClient implementations. |
615 void set_extension_info( | 617 void set_extension_info( |
616 std::unique_ptr<AssociatedExtensionInfo> extension_info) { | 618 std::unique_ptr<AssociatedExtensionInfo> extension_info) { |
617 extension_info_ = std::move(extension_info); | 619 extension_info_ = std::move(extension_info); |
618 } | 620 } |
619 | 621 |
| 622 const AssociatedExtensionInfo* GetExtensionInfoForTesting() const { |
| 623 return extension_info_.get(); |
| 624 } |
| 625 |
620 // Returns true if |url| supports replacement. | 626 // Returns true if |url| supports replacement. |
621 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; | 627 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; |
622 | 628 |
623 // Returns true if any URLRefs use Googe base URLs. | 629 // Returns true if any URLRefs use Googe base URLs. |
624 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; | 630 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; |
625 | 631 |
626 // Returns true if this TemplateURL uses Google base URLs and has a keyword | 632 // Returns true if this TemplateURL uses Google base URLs and has a keyword |
627 // of "google.TLD". We use this to decide whether we can automatically | 633 // of "google.TLD". We use this to decide whether we can automatically |
628 // update the keyword to reflect the current Google base URL TLD. | 634 // update the keyword to reflect the current Google base URL TLD. |
629 bool IsGoogleSearchURLWithReplaceableKeyword( | 635 bool IsGoogleSearchURLWithReplaceableKeyword( |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 | 760 |
755 // Caches the computed engine type across successive calls to GetEngineType(). | 761 // Caches the computed engine type across successive calls to GetEngineType(). |
756 mutable SearchEngineType engine_type_; | 762 mutable SearchEngineType engine_type_; |
757 | 763 |
758 // TODO(sky): Add date last parsed OSD file. | 764 // TODO(sky): Add date last parsed OSD file. |
759 | 765 |
760 DISALLOW_COPY_AND_ASSIGN(TemplateURL); | 766 DISALLOW_COPY_AND_ASSIGN(TemplateURL); |
761 }; | 767 }; |
762 | 768 |
763 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ | 769 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ |
OLD | NEW |