Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / search_engines / search_host_to_urls_map.h
blob1c086b6dddb361400290b231872a09b318c9b7e0
1 // Copyright (c) 2012 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 CHROME_BROWSER_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_
6 #define CHROME_BROWSER_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "chrome/browser/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,
36 const SearchTermsData& search_terms_data);
38 // Returns the first TemplateURL found with a URL using the specified |host|,
39 // or NULL if there are no such TemplateURLs
40 TemplateURL* GetTemplateURLForHost(const std::string& host);
42 // Return the TemplateURLSet for the given the |host| or NULL if there are
43 // none.
44 TemplateURLSet* GetURLsForHost(const std::string& host);
46 private:
47 friend class SearchHostToURLsMapTest;
49 typedef std::map<std::string, TemplateURLSet> HostToURLsMap;
51 // Adds many URLs to the map.
52 void Add(const TemplateURLService::TemplateURLVector& template_urls,
53 const SearchTermsData& search_terms_data);
55 // Removes the given template_url using only the pointer instead of the value.
56 // This is useful when the value may have changed before being updated in the
57 // map. (Specifically when the GoogleBaseURLValue changes.)
58 void RemoveByPointer(TemplateURL* template_url);
60 // Maps from host to set of TemplateURLs whose search url host is host.
61 HostToURLsMap host_to_urls_map_;
63 // The security origin for the default search provider.
64 std::string default_search_origin_;
66 // Has Init been called?
67 bool initialized_;
69 DISALLOW_COPY_AND_ASSIGN(SearchHostToURLsMap);
72 #endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_HOST_TO_URLS_MAP_H_