Update activity log owners
[chromium-blink-merge.git] / components / search_engines / search_host_to_urls_map.h
blob6c580b5abbc30dcab4f6c4f15bbfe45ce85330ba
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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_
6 #define COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "components/search_engines/template_url_service.h"
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
17 // caller to ensure the right lifetime of them.
18 class SearchHostToURLsMap {
19 public:
20 typedef std::set<TemplateURL*> TemplateURLSet;
22 SearchHostToURLsMap();
23 ~SearchHostToURLsMap();
25 // Initializes the map.
26 void Init(const TemplateURLService::TemplateURLVector& template_urls,
27 const SearchTermsData& search_terms_data);
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.
31 void Add(TemplateURL* template_url,
32 const SearchTermsData& search_terms_data);
34 // Removes the TemplateURL from the lookup.
35 void Remove(TemplateURL* template_url);
37 // Returns the first TemplateURL found with a URL using the specified |host|,
38 // or NULL if there are no such TemplateURLs
39 TemplateURL* GetTemplateURLForHost(const std::string& host);
41 // Return the TemplateURLSet for the given the |host| or NULL if there are
42 // none.
43 TemplateURLSet* GetURLsForHost(const std::string& host);
45 private:
46 friend class SearchHostToURLsMapTest;
48 typedef std::map<std::string, TemplateURLSet> HostToURLsMap;
50 // Adds many URLs to the map.
51 void Add(const TemplateURLService::TemplateURLVector& template_urls,
52 const SearchTermsData& search_terms_data);
54 // Maps from host to set of TemplateURLs whose search url host is host.
55 HostToURLsMap host_to_urls_map_;
57 // The security origin for the default search provider.
58 std::string default_search_origin_;
60 // Has Init been called?
61 bool initialized_;
63 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMap);
66 #endif // COMPONENTS_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_