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

Side by Side Diff: components/search_engines/template_url.h

Issue 2347973002: Enable Chrome to tweak search engines for some locales (Closed)
Patch Set: fix compile Created 4 years, 3 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
OLDNEW
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
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 AssociatedExtensionInfo(const std::string& extension_id);
Peter Kasting 2016/09/21 21:45:08 Nit: explicit
Ian Wen 2016/09/21 23:12:38 Done.
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 TemplateURL(const TemplateURLData& data, Type type = NORMAL);
Peter Kasting 2016/09/21 21:45:08 Nit: I think this still needs "explicit"? Or does
Ian Wen 2016/09/21 23:12:38 Compiler allows it. Yet I agree explicit should be
Peter Kasting 2016/09/23 01:28:36 What I meant was, if the compiler allows it, we de
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
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 void set_type(Type type) { type_ = type; }
617
615 // This setter shouldn't be used except by TemplateURLService and 618 // This setter shouldn't be used except by TemplateURLService and
616 // TemplateURLServiceClient implementations. 619 // TemplateURLServiceClient implementations.
617 void set_extension_info( 620 void set_extension_info(
618 std::unique_ptr<AssociatedExtensionInfo> extension_info) { 621 std::unique_ptr<AssociatedExtensionInfo> extension_info) {
619 extension_info_ = std::move(extension_info); 622 extension_info_ = std::move(extension_info);
620 } 623 }
621 624
622 // Returns true if |url| supports replacement. 625 // Returns true if |url| supports replacement.
623 bool SupportsReplacement(const SearchTermsData& search_terms_data) const; 626 bool SupportsReplacement(const SearchTermsData& search_terms_data) const;
624 627
625 // Returns true if any URLRefs use Googe base URLs. 628 // Returns true if any URLRefs use Googe base URLs.
626 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const; 629 bool HasGoogleBaseURLs(const SearchTermsData& search_terms_data) const;
627 630
628 // 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
629 // 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
630 // update the keyword to reflect the current Google base URL TLD. 633 // update the keyword to reflect the current Google base URL TLD.
631 bool IsGoogleSearchURLWithReplaceableKeyword( 634 bool IsGoogleSearchURLWithReplaceableKeyword(
632 const SearchTermsData& search_terms_data) const; 635 const SearchTermsData& search_terms_data) const;
633 636
634 // Returns true if the keywords match or if 637 // Returns true if the keywords match or if
635 // IsGoogleSearchURLWithReplaceableKeyword() is true for both |this| and 638 // IsGoogleSearchURLWithReplaceableKeyword() is true for both |this| and
636 // |other|. 639 // |other|.
637 bool HasSameKeywordAs(const TemplateURLData& other, 640 bool HasSameKeywordAs(const TemplateURLData& other,
638 const SearchTermsData& search_terms_data) const; 641 const SearchTermsData& search_terms_data) const;
639 642
640 Type GetType() const;
641
642 // Returns the id of the extension that added this search engine. Only call 643 // Returns the id of the extension that added this search engine. Only call
643 // this for TemplateURLs of type NORMAL_CONTROLLED_BY_EXTENSION or 644 // this for TemplateURLs of type NORMAL_CONTROLLED_BY_EXTENSION or
644 // OMNIBOX_API_EXTENSION. 645 // OMNIBOX_API_EXTENSION.
645 std::string GetExtensionId() const; 646 std::string GetExtensionId() const;
646 647
647 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no 648 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no
648 // engines match. 649 // engines match.
649 SearchEngineType GetEngineType( 650 SearchEngineType GetEngineType(
650 const SearchTermsData& search_terms_data) const; 651 const SearchTermsData& search_terms_data) const;
651 652
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 TemplateURLRef suggestions_url_ref_; 751 TemplateURLRef suggestions_url_ref_;
751 TemplateURLRef instant_url_ref_; 752 TemplateURLRef instant_url_ref_;
752 TemplateURLRef image_url_ref_; 753 TemplateURLRef image_url_ref_;
753 TemplateURLRef new_tab_url_ref_; 754 TemplateURLRef new_tab_url_ref_;
754 TemplateURLRef contextual_search_url_ref_; 755 TemplateURLRef contextual_search_url_ref_;
755 std::unique_ptr<AssociatedExtensionInfo> extension_info_; 756 std::unique_ptr<AssociatedExtensionInfo> extension_info_;
756 757
757 // Caches the computed engine type across successive calls to GetEngineType(). 758 // Caches the computed engine type across successive calls to GetEngineType().
758 mutable SearchEngineType engine_type_; 759 mutable SearchEngineType engine_type_;
759 760
761 Type type_;
Peter Kasting 2016/09/21 21:45:08 Nit: I'd probably place this above |engine_type_|.
Ian Wen 2016/09/21 23:12:38 Done.
762
760 // TODO(sky): Add date last parsed OSD file. 763 // TODO(sky): Add date last parsed OSD file.
761 764
762 DISALLOW_COPY_AND_ASSIGN(TemplateURL); 765 DISALLOW_COPY_AND_ASSIGN(TemplateURL);
763 }; 766 };
764 767
765 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ 768 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698