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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::UpdateGoogleBaseURLs( | 62 void SearchHostToURLsMap::UpdateGoogleBaseURLs( |
63 const SearchTermsData& search_terms_data) { | 63 const SearchTermsData& search_terms_data) { |
64 DCHECK(initialized_); | 64 DCHECK(initialized_); |
65 | 65 |
66 // Create a list of the the TemplateURLs to update. | 66 // Create a list of the the TemplateURLs to update. |
67 std::vector<const TemplateURL*> t_urls_using_base_url; | 67 std::vector<const TemplateURL*> t_urls_using_base_url; |
68 for (HostToURLsMap::iterator host_map_iterator = host_to_urls_map_.begin(); | 68 for (HostToURLsMap::iterator i(host_to_urls_map_.begin()); |
69 host_map_iterator != host_to_urls_map_.end(); ++host_map_iterator) { | 69 i != host_to_urls_map_.end(); ++i) { |
70 const TemplateURLSet& urls = host_map_iterator->second; | 70 for (TemplateURLSet::const_iterator j(i->second.begin()); |
71 for (TemplateURLSet::const_iterator url_set_iterator = urls.begin(); | 71 j != i->second.end(); ++j) { |
72 url_set_iterator != urls.end(); ++url_set_iterator) { | 72 if ((*j)->url_ref().HasGoogleBaseURLs() || |
73 const TemplateURL* t_url = *url_set_iterator; | 73 (*j)->suggestions_url_ref().HasGoogleBaseURLs()) |
74 if (t_url->url_ref().HasGoogleBaseURLs() || | 74 t_urls_using_base_url.push_back(*j); |
75 t_url->suggestions_url_ref().HasGoogleBaseURLs()) { | |
76 t_urls_using_base_url.push_back(t_url); | |
77 } | |
78 } | 75 } |
79 } | 76 } |
80 | 77 |
81 for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) | 78 for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) |
82 RemoveByPointer(t_urls_using_base_url[i]); | 79 RemoveByPointer(t_urls_using_base_url[i]); |
83 | 80 |
84 for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) | 81 for (size_t i = 0; i < t_urls_using_base_url.size(); ++i) |
85 Add(t_urls_using_base_url[i], search_terms_data); | 82 Add(t_urls_using_base_url[i], search_terms_data); |
86 } | 83 } |
87 | 84 |
(...skipping 25 matching lines...) Expand all Loading... |
113 if (url_set_iterator != i->second.end()) { | 110 if (url_set_iterator != i->second.end()) { |
114 i->second.erase(url_set_iterator); | 111 i->second.erase(url_set_iterator); |
115 if (i->second.empty()) | 112 if (i->second.empty()) |
116 host_to_urls_map_.erase(i); | 113 host_to_urls_map_.erase(i); |
117 // A given TemplateURL only occurs once in the map. As soon as we find the | 114 // A given TemplateURL only occurs once in the map. As soon as we find the |
118 // entry, stop. | 115 // entry, stop. |
119 return; | 116 return; |
120 } | 117 } |
121 } | 118 } |
122 } | 119 } |
OLD | NEW |