Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: chrome/browser/search_engines/search_host_to_urls_map.cc

Issue 7558014: Add a URL param to indicate group selection in Instant field trial. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Thread safe handling of Profiles Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 23 matching lines...) Expand all
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 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 Profile* profile) {
45 DCHECK(initialized_); 46 DCHECK(initialized_);
46 DCHECK(template_url); 47 DCHECK(template_url);
47 48
48 const GURL url(TemplateURLService::GenerateSearchURL(template_url)); 49 const GURL url(TemplateURLService::GenerateSearchURL(template_url, profile));
49 if (!url.is_valid() || !url.has_host()) 50 if (!url.is_valid() || !url.has_host())
50 return; 51 return;
51 52
52 const std::string host(url.host()); 53 const std::string host(url.host());
53 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end()); 54 DCHECK(host_to_urls_map_.find(host) != host_to_urls_map_.end());
54 55
55 TemplateURLSet& urls = host_to_urls_map_[host]; 56 TemplateURLSet& urls = host_to_urls_map_[host];
56 DCHECK(urls.find(template_url) != urls.end()); 57 DCHECK(urls.find(template_url) != urls.end());
57 58
58 urls.erase(urls.find(template_url)); 59 urls.erase(urls.find(template_url));
59 if (urls.empty()) 60 if (urls.empty())
60 host_to_urls_map_.erase(host_to_urls_map_.find(host)); 61 host_to_urls_map_.erase(host_to_urls_map_.find(host));
61 } 62 }
62 63
63 void SearchHostToURLsMap::Update(const TemplateURL* existing_turl, 64 void SearchHostToURLsMap::Update(const TemplateURL* existing_turl,
64 const TemplateURL& new_values, 65 const TemplateURL& new_values,
65 const SearchTermsData& search_terms_data) { 66 const SearchTermsData& search_terms_data,
67 Profile* profile) {
66 DCHECK(initialized_); 68 DCHECK(initialized_);
67 DCHECK(existing_turl); 69 DCHECK(existing_turl);
68 70
69 Remove(existing_turl); 71 Remove(existing_turl, profile);
70 72
71 // Use the information from new_values but preserve existing_turl's id. 73 // Use the information from new_values but preserve existing_turl's id.
72 TemplateURLID previous_id = existing_turl->id(); 74 TemplateURLID previous_id = existing_turl->id();
73 TemplateURL* modifiable_turl = const_cast<TemplateURL*>(existing_turl); 75 TemplateURL* modifiable_turl = const_cast<TemplateURL*>(existing_turl);
74 *modifiable_turl = new_values; 76 *modifiable_turl = new_values;
75 modifiable_turl->set_id(previous_id); 77 modifiable_turl->set_id(previous_id);
76 78
77 Add(existing_turl, search_terms_data); 79 Add(existing_turl, search_terms_data);
78 } 80 }
79 81
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (url_set_iterator != i->second.end()) { 134 if (url_set_iterator != i->second.end()) {
133 i->second.erase(url_set_iterator); 135 i->second.erase(url_set_iterator);
134 if (i->second.empty()) 136 if (i->second.empty())
135 host_to_urls_map_.erase(i); 137 host_to_urls_map_.erase(i);
136 // A given TemplateURL only occurs once in the map. As soon as we find the 138 // A given TemplateURL only occurs once in the map. As soon as we find the
137 // entry, stop. 139 // entry, stop.
138 return; 140 return;
139 } 141 }
140 } 142 }
141 } 143 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698