| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/task.h" | 8 #include "base/task.h" |
| 9 #include "chrome/browser/search_engines/template_url.h" | 9 #include "chrome/browser/search_engines/template_url.h" |
| 10 #include "chrome/browser/search_engines/template_url_service.h" | 10 #include "chrome/browser/search_engines/template_url_service.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 for (size_t i = 0; i < template_urls.size(); ++i) | 27 for (size_t i = 0; i < template_urls.size(); ++i) |
| 28 Add(template_urls[i], search_terms_data); | 28 Add(template_urls[i], search_terms_data); |
| 29 } | 29 } |
| 30 | 30 |
| 31 void SearchHostToURLsMap::Add(const TemplateURL* template_url, | 31 void SearchHostToURLsMap::Add(const TemplateURL* template_url, |
| 32 const SearchTermsData& search_terms_data) { | 32 const SearchTermsData& search_terms_data) { |
| 33 DCHECK(initialized_); | 33 DCHECK(initialized_); |
| 34 DCHECK(template_url); | 34 DCHECK(template_url); |
| 35 | 35 |
| 36 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( | 36 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( |
| 37 template_url, search_terms_data)); | 37 NULL, template_url, search_terms_data)); |
| 38 if (!url.is_valid() || !url.has_host()) | 38 if (!url.is_valid() || !url.has_host()) |
| 39 return; | 39 return; |
| 40 | 40 |
| 41 host_to_urls_map_[url.host()].insert(template_url); | 41 host_to_urls_map_[url.host()].insert(template_url); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SearchHostToURLsMap::Remove(const TemplateURL* template_url) { | 44 void SearchHostToURLsMap::Remove(const TemplateURL* template_url) { |
| 45 DCHECK(initialized_); | 45 DCHECK(initialized_); |
| 46 DCHECK(template_url); | 46 DCHECK(template_url); |
| 47 | 47 |
| 48 const GURL url(TemplateURLService::GenerateSearchURL(template_url)); | 48 const GURL url(TemplateURLService::GenerateSearchURL(NULL, template_url)); |
| 49 if (!url.is_valid() || !url.has_host()) | 49 if (!url.is_valid() || !url.has_host()) |
| 50 return; | 50 return; |
| 51 | 51 |
| 52 const std::string host(url.host()); | 52 const std::string host(url.host()); |
| 53 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); | 53 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); |
| 54 | 54 |
| 55 TemplateURLSet& urls = host_to_urls_map_[host]; | 55 TemplateURLSet& urls = host_to_urls_map_[host]; |
| 56 DCHECK(urls.find(template_url) != urls.end()); | 56 DCHECK(urls.find(template_url) != urls.end()); |
| 57 | 57 |
| 58 urls.erase(urls.find(template_url)); | 58 urls.erase(urls.find(template_url)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (url_set_iterator != i->second.end()) { | 132 if (url_set_iterator != i->second.end()) { |
| 133 i->second.erase(url_set_iterator); | 133 i->second.erase(url_set_iterator); |
| 134 if (i->second.empty()) | 134 if (i->second.empty()) |
| 135 host_to_urls_map_.erase(i); | 135 host_to_urls_map_.erase(i); |
| 136 // A given TemplateURL only occurs once in the map. As soon as we find the | 136 // A given TemplateURL only occurs once in the map. As soon as we find the |
| 137 // entry, stop. | 137 // entry, stop. |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 } | 141 } |
| OLD | NEW |