| 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 10 matching lines...) Expand all Loading... |
| 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 | 30 |
| 31 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( | 31 const GURL url(TemplateURLService::GenerateSearchURL( |
| 32 template_url, search_terms_data)); | 32 template_url, search_terms_data)); |
| 33 if (!url.is_valid() || !url.has_host()) | 33 if (!url.is_valid() || !url.has_host()) |
| 34 return; | 34 return; |
| 35 | 35 |
| 36 host_to_urls_map_[url.host()].insert(template_url); | 36 host_to_urls_map_[url.host()].insert(template_url); |
| 37 } | 37 } |
| 38 | 38 |
| 39 void SearchHostToURLsMap::Remove(TemplateURL* template_url, | 39 void SearchHostToURLsMap::Remove(TemplateURL* template_url, |
| 40 const SearchTermsData& search_terms_data) { | 40 const SearchTermsData& search_terms_data) { |
| 41 DCHECK(initialized_); | 41 DCHECK(initialized_); |
| 42 DCHECK(template_url); | 42 DCHECK(template_url); |
| 43 | 43 |
| 44 const GURL url(TemplateURLService::GenerateSearchURLUsingTermsData( | 44 const GURL url(TemplateURLService::GenerateSearchURL( |
| 45 template_url, search_terms_data)); | 45 template_url, search_terms_data)); |
| 46 if (!url.is_valid() || !url.has_host()) | 46 if (!url.is_valid() || !url.has_host()) |
| 47 return; | 47 return; |
| 48 | 48 |
| 49 const std::string host(url.host()); | 49 const std::string host(url.host()); |
| 50 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()); |
| 51 | 51 |
| 52 TemplateURLSet& urls = host_to_urls_map_[host]; | 52 TemplateURLSet& urls = host_to_urls_map_[host]; |
| 53 DCHECK(urls.find(template_url) != urls.end()); | 53 DCHECK(urls.find(template_url) != urls.end()); |
| 54 | 54 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 if (url_set_iterator != i->second.end()) { | 92 if (url_set_iterator != i->second.end()) { |
| 93 i->second.erase(url_set_iterator); | 93 i->second.erase(url_set_iterator); |
| 94 if (i->second.empty()) | 94 if (i->second.empty()) |
| 95 host_to_urls_map_.erase(i); | 95 host_to_urls_map_.erase(i); |
| 96 // 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 |
| 97 // entry, stop. | 97 // entry, stop. |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 } | 101 } |
| OLD | NEW |