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

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

Issue 1983773002: Cache SearchEngineType of TemplateURL (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@refactor-extracting-terms-from-template-url
Patch Set: Fix typo Created 4 years, 6 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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/gtest_prod_util.h" 15 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/metrics/proto/omnibox_event.pb.h" 18 #include "components/metrics/proto/omnibox_event.pb.h"
19 #include "components/metrics/proto/omnibox_input_type.pb.h" 19 #include "components/metrics/proto/omnibox_input_type.pb.h"
20 #include "components/search_engines/search_engine_type.h"
20 #include "components/search_engines/template_url_data.h" 21 #include "components/search_engines/template_url_data.h"
21 #include "components/search_engines/template_url_id.h" 22 #include "components/search_engines/template_url_id.h"
22 #include "ui/gfx/geometry/size.h" 23 #include "ui/gfx/geometry/size.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 #include "url/third_party/mozilla/url_parse.h" 25 #include "url/third_party/mozilla/url_parse.h"
25 26
26 class SearchTermsData; 27 class SearchTermsData;
27 class TemplateURL; 28 class TemplateURL;
28 29
29 30
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 bool HasSameKeywordAs(const TemplateURLData& other, 638 bool HasSameKeywordAs(const TemplateURLData& other,
638 const SearchTermsData& search_terms_data) const; 639 const SearchTermsData& search_terms_data) const;
639 640
640 Type GetType() const; 641 Type GetType() const;
641 642
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
648 // Returns the type of this search engine, or SEARCH_ENGINE_OTHER if no
649 // engines match.
650 SearchEngineType GetEngineType(
651 const SearchTermsData& search_terms_data) const;
652
647 // Use the alternate URLs and the search URL to match the provided |url| 653 // Use the alternate URLs and the search URL to match the provided |url|
648 // and extract |search_terms| from it. Returns false and an empty 654 // and extract |search_terms| from it. Returns false and an empty
649 // |search_terms| if no search terms can be matched. The order in which the 655 // |search_terms| if no search terms can be matched. The order in which the
650 // alternate URLs are listed dictates their priority, the URL at index 0 is 656 // alternate URLs are listed dictates their priority, the URL at index 0 is
651 // treated as the highest priority and the primary search URL is treated as 657 // treated as the highest priority and the primary search URL is treated as
652 // the lowest priority. For example, if a TemplateURL has alternate URL 658 // the lowest priority. For example, if a TemplateURL has alternate URL
653 // "http://foo/#q={searchTerms}" and search URL "http://foo/?q={searchTerms}", 659 // "http://foo/#q={searchTerms}" and search URL "http://foo/?q={searchTerms}",
654 // and the URL to be decoded is "http://foo/?q=a#q=b", the alternate URL will 660 // and the URL to be decoded is "http://foo/?q=a#q=b", the alternate URL will
655 // match first and the decoded search term will be "b". 661 // match first and the decoded search term will be "b".
656 bool ExtractSearchTermsFromURL(const GURL& url, 662 bool ExtractSearchTermsFromURL(const GURL& url,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 // URL. 748 // URL.
743 TemplateURLRef* url_ref_; 749 TemplateURLRef* url_ref_;
744 750
745 TemplateURLRef suggestions_url_ref_; 751 TemplateURLRef suggestions_url_ref_;
746 TemplateURLRef instant_url_ref_; 752 TemplateURLRef instant_url_ref_;
747 TemplateURLRef image_url_ref_; 753 TemplateURLRef image_url_ref_;
748 TemplateURLRef new_tab_url_ref_; 754 TemplateURLRef new_tab_url_ref_;
749 TemplateURLRef contextual_search_url_ref_; 755 TemplateURLRef contextual_search_url_ref_;
750 std::unique_ptr<AssociatedExtensionInfo> extension_info_; 756 std::unique_ptr<AssociatedExtensionInfo> extension_info_;
751 757
758 // Caches the computed engine type across successive calls to GetEngineType().
759 mutable SearchEngineType engine_type_;
760
752 // TODO(sky): Add date last parsed OSD file. 761 // TODO(sky): Add date last parsed OSD file.
753 762
754 DISALLOW_COPY_AND_ASSIGN(TemplateURL); 763 DISALLOW_COPY_AND_ASSIGN(TemplateURL);
755 }; 764 };
756 765
757 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_ 766 #endif // COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698