OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/search_engines/search_host_to_urls_map.h" | 5 #include "chrome/browser/search_engines/search_host_to_urls_map.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "chrome/browser/search_engines/template_url.h" | 8 #include "chrome/browser/search_engines/template_url.h" |
9 #include "chrome/browser/search_engines/template_url_service.h" | 9 #include "chrome/browser/search_engines/template_url_service.h" |
10 | 10 |
11 SearchHostToURLsMap::SearchHostToURLsMap() | 11 SearchHostToURLsMap::SearchHostToURLsMap() |
12 : initialized_(false) { | 12 : initialized_(false) { |
13 } | 13 } |
14 | 14 |
15 SearchHostToURLsMap::~SearchHostToURLsMap() { | 15 SearchHostToURLsMap::~SearchHostToURLsMap() { |
16 } | 16 } |
17 | 17 |
18 void SearchHostToURLsMap::Init( | 18 void SearchHostToURLsMap::Init( |
19 const TemplateURLService::TemplateURLVector& template_urls, | 19 const TemplateURLService::TemplateURLVector& template_urls, |
20 const SearchTermsData& search_terms_data) { | 20 const SearchTermsData& search_terms_data) { |
21 DCHECK(!initialized_); | 21 DCHECK(!initialized_); |
22 initialized_ = true; // Set here so Add doesn't assert. | 22 initialized_ = true; // Set here so Add doesn't assert. |
23 Add(template_urls, search_terms_data); | 23 Add(template_urls, search_terms_data); |
24 } | 24 } |
25 | 25 |
26 void SearchHostToURLsMap::Add(TemplateURL* template_url, | 26 void SearchHostToURLsMap::Add(TemplateURL* template_url, |
27 const SearchTermsData& search_terms_data) { | 27 const SearchTermsData& search_terms_data) { |
28 DCHECK(initialized_); | 28 DCHECK(initialized_); |
29 DCHECK(template_url); | 29 DCHECK(template_url); |
30 DCHECK(!template_url->IsExtensionKeyword()); | |
31 | 30 |
32 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( | 31 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( |
33 template_url, search_terms_data)); | 32 template_url, search_terms_data)); |
34 if (!url.is_valid() || !url.has_host()) | 33 if (!url.is_valid() || !url.has_host()) |
35 return; | 34 return; |
36 | 35 |
37 host_to_urls_map_[url.host()].insert(template_url); | 36 host_to_urls_map_[url.host()].insert(template_url); |
38 } | 37 } |
39 | 38 |
40 void SearchHostToURLsMap::Remove(TemplateURL* template_url, | 39 void SearchHostToURLsMap::Remove(TemplateURL* template_url, |
41 const SearchTermsData& search_terms_data) { | 40 const SearchTermsData& search_terms_data) { |
42 DCHECK(initialized_); | 41 DCHECK(initialized_); |
43 DCHECK(template_url); | 42 DCHECK(template_url); |
44 DCHECK(!template_url->IsExtensionKeyword()); | |
45 | 43 |
46 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( | 44 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( |
47 template_url, search_terms_data)); | 45 template_url, search_terms_data)); |
48 if (!url.is_valid() || !url.has_host()) | 46 if (!url.is_valid() || !url.has_host()) |
49 return; | 47 return; |
50 | 48 |
51 const std::string host(url.host()); | 49 const std::string host(url.host()); |
52 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); | 50 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); |
53 | 51 |
54 TemplateURLSet& urls = host_to_urls_map_[host]; | 52 TemplateURLSet& urls = host_to_urls_map_[host]; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 if (url_set_iterator != i->second.end()) { | 92 if (url_set_iterator != i->second.end()) { |
95 i->second.erase(url_set_iterator); | 93 i->second.erase(url_set_iterator); |
96 if (i->second.empty()) | 94 if (i->second.empty()) |
97 host_to_urls_map_.erase(i); | 95 host_to_urls_map_.erase(i); |
98 // A given TemplateURL only occurs once in the map. As soon as we find the | 96 // A given TemplateURL only occurs once in the map. As soon as we find the |
99 // entry, stop. | 97 // entry, stop. |
100 return; | 98 return; |
101 } | 99 } |
102 } | 100 } |
103 } | 101 } |
OLD | NEW |