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_SEARCH_HOST_TO_URLS_MAP_H_ | 5 #ifndef COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_ |
6 #define COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_ | 6 #define COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "components/search_engines/template_url_service.h" | 13 #include "components/search_engines/template_url_service.h" |
14 | 14 |
15 // Holds the host to template url mappings for the search providers. WARNING: | 15 // Holds the host to template url mappings for the search providers. WARNING: |
16 // This class does not own any TemplateURLs passed to it and it is up to the | 16 // This class does not own any TemplateURLs passed to it and it is up to the |
17 // caller to ensure the right lifetime of them. | 17 // caller to ensure the right lifetime of them. |
18 class SearchHostToURLsMap { | 18 class SearchHostToURLsMap { |
19 public: | 19 public: |
20 typedef std::set<TemplateURL*> TemplateURLSet; | 20 typedef std::set<TemplateURL*> TemplateURLSet; |
21 | 21 |
22 SearchHostToURLsMap(); | 22 SearchHostToURLsMap(); |
23 ~SearchHostToURLsMap(); | 23 ~SearchHostToURLsMap(); |
24 | 24 |
25 // Initializes the map. | 25 // Initializes the map. |
26 void Init(const TemplateURLService::TemplateURLVector& template_urls, | 26 void Init(const TemplateURLService::OwnedTemplateURLVector& template_urls, |
27 const SearchTermsData& search_terms_data); | 27 const SearchTermsData& search_terms_data); |
28 | 28 |
29 // Adds a new TemplateURL to the map. Since |template_url| is owned | 29 // Adds a new TemplateURL to the map. Since |template_url| is owned |
30 // externally, Remove or RemoveAll should be called if it becomes invalid. | 30 // externally, Remove or RemoveAll should be called if it becomes invalid. |
31 void Add(TemplateURL* template_url, | 31 void Add(TemplateURL* template_url, |
32 const SearchTermsData& search_terms_data); | 32 const SearchTermsData& search_terms_data); |
33 | 33 |
34 // Removes the TemplateURL from the lookup. | 34 // Removes the TemplateURL from the lookup. |
35 void Remove(TemplateURL* template_url); | 35 void Remove(TemplateURL* template_url); |
36 | 36 |
37 // Returns the first TemplateURL found with a URL using the specified |host|, | 37 // Returns the first TemplateURL found with a URL using the specified |host|, |
38 // or NULL if there are no such TemplateURLs | 38 // or NULL if there are no such TemplateURLs |
39 TemplateURL* GetTemplateURLForHost(const std::string& host); | 39 TemplateURL* GetTemplateURLForHost(const std::string& host); |
40 | 40 |
41 // Return the TemplateURLSet for the given the |host| or NULL if there are | 41 // Return the TemplateURLSet for the given the |host| or NULL if there are |
42 // none. | 42 // none. |
43 TemplateURLSet* GetURLsForHost(const std::string& host); | 43 TemplateURLSet* GetURLsForHost(const std::string& host); |
44 | 44 |
45 private: | 45 private: |
46 friend class SearchHostToURLsMapTest; | 46 friend class SearchHostToURLsMapTest; |
47 | 47 |
48 typedef std::map<std::string, TemplateURLSet> HostToURLsMap; | 48 typedef std::map<std::string, TemplateURLSet> HostToURLsMap; |
49 | 49 |
50 // Adds many URLs to the map. | 50 // Adds many URLs to the map. |
51 void Add(const TemplateURLService::TemplateURLVector& template_urls, | 51 void Add(const TemplateURLService::OwnedTemplateURLVector& template_urls, |
52 const SearchTermsData& search_terms_data); | 52 const SearchTermsData& search_terms_data); |
53 | 53 |
54 // Maps from host to set of TemplateURLs whose search url host is host. | 54 // Maps from host to set of TemplateURLs whose search url host is host. |
55 HostToURLsMap host_to_urls_map_; | 55 HostToURLsMap host_to_urls_map_; |
56 | 56 |
57 // The security origin for the default search provider. | 57 // The security origin for the default search provider. |
58 std::string default_search_origin_; | 58 std::string default_search_origin_; |
59 | 59 |
60 // Has Init been called? | 60 // Has Init been called? |
61 bool initialized_; | 61 bool initialized_; |
62 | 62 |
63 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMap); | 63 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMap); |
64 }; | 64 }; |
65 | 65 |
66 #endif // COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_ | 66 #endif // COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_ |
OLD | NEW |