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 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); | 52 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); |
53 | 53 |
54 TemplateURLSet& urls = host_to_urls_map_[host]; | 54 TemplateURLSet& urls = host_to_urls_map_[host]; |
55 DCHECK(urls.find(template_url) != urls.end()); | 55 DCHECK(urls.find(template_url) != urls.end()); |
56 | 56 |
57 urls.erase(urls.find(template_url)); | 57 urls.erase(urls.find(template_url)); |
58 if (urls.empty()) | 58 if (urls.empty()) |
59 host_to_urls_map_.erase(host_to_urls_map_.find(host)); | 59 host_to_urls_map_.erase(host_to_urls_map_.find(host)); |
60 } | 60 } |
61 | 61 |
62 void SearchHostToURLsMap::Update(const TemplateURL* existing_turl, | |
63 const TemplateURL& new_values, | |
64 const SearchTermsData& search_terms_data) { | |
65 DCHECK(initialized_); | |
66 DCHECK(existing_turl); | |
67 | |
68 Remove(existing_turl); | |
69 | |
70 // Use the information from new_values but preserve existing_turl's id. | |
71 TemplateURLID previous_id = existing_turl->id(); | |
72 TemplateURL* modifiable_turl = const_cast<TemplateURL*>(existing_turl); | |
73 *modifiable_turl = new_values; | |
74 modifiable_turl->set_id(previous_id); | |
75 | |
76 Add(existing_turl, search_terms_data); | |
77 } | |
78 | |
79 void SearchHostToURLsMap::UpdateGoogleBaseURLs( | 62 void SearchHostToURLsMap::UpdateGoogleBaseURLs( |
80 const SearchTermsData& search_terms_data) { | 63 const SearchTermsData& search_terms_data) { |
81 DCHECK(initialized_); | 64 DCHECK(initialized_); |
82 | 65 |
83 // Create a list of the the TemplateURLs to update. | 66 // Create a list of the the TemplateURLs to update. |
84 std::vector<const TemplateURL*> t_urls_using_base_url; | 67 std::vector<const TemplateURL*> t_urls_using_base_url; |
85 for (HostToURLsMap::iterator host_map_iterator = host_to_urls_map_.begin(); | 68 for (HostToURLsMap::iterator host_map_iterator = host_to_urls_map_.begin(); |
86 host_map_iterator != host_to_urls_map_.end(); ++host_map_iterator) { | 69 host_map_iterator != host_to_urls_map_.end(); ++host_map_iterator) { |
87 const TemplateURLSet& urls = host_map_iterator->second; | 70 const TemplateURLSet& urls = host_map_iterator->second; |
88 for (TemplateURLSet::const_iterator url_set_iterator = urls.begin(); | 71 for (TemplateURLSet::const_iterator url_set_iterator = urls.begin(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (url_set_iterator != i->second.end()) { | 113 if (url_set_iterator != i->second.end()) { |
131 i->second.erase(url_set_iterator); | 114 i->second.erase(url_set_iterator); |
132 if (i->second.empty()) | 115 if (i->second.empty()) |
133 host_to_urls_map_.erase(i); | 116 host_to_urls_map_.erase(i); |
134 // A given TemplateURL only occurs once in the map. As soon as we find the | 117 // A given TemplateURL only occurs once in the map. As soon as we find the |
135 // entry, stop. | 118 // entry, stop. |
136 return; | 119 return; |
137 } | 120 } |
138 } | 121 } |
139 } | 122 } |
OLD | NEW |