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

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

Issue 8570022: base::Bind() conversion for chrome/browser/search_engines (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month 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_provider_install_data.h" 5 #include "chrome/browser/search_engines/search_provider_install_data.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/task.h"
13 #include "chrome/browser/search_engines/search_host_to_urls_map.h" 13 #include "chrome/browser/search_engines/search_host_to_urls_map.h"
14 #include "chrome/browser/search_engines/search_terms_data.h" 14 #include "chrome/browser/search_engines/search_terms_data.h"
15 #include "chrome/browser/search_engines/template_url.h" 15 #include "chrome/browser/search_engines/template_url.h"
16 #include "chrome/browser/search_engines/template_url_service.h" 16 #include "chrome/browser/search_engines/template_url_service.h"
17 #include "chrome/browser/search_engines/util.h" 17 #include "chrome/browser/search_engines/util.h"
18 #include "chrome/browser/webdata/web_data_service.h" 18 #include "chrome/browser/webdata/web_data_service.h"
19 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
22 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 131 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
132 content::NotificationService::AllSources()); 132 content::NotificationService::AllSources());
133 registrar_.Add(this, ui_death_notification, ui_death_source); 133 registrar_.Add(this, ui_death_notification, ui_death_source);
134 } 134 }
135 135
136 void GoogleURLObserver::Observe(int type, 136 void GoogleURLObserver::Observe(int type,
137 const content::NotificationSource& source, 137 const content::NotificationSource& source,
138 const content::NotificationDetails& details) { 138 const content::NotificationDetails& details) {
139 if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) { 139 if (type == chrome::NOTIFICATION_GOOGLE_URL_UPDATED) {
140 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 140 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
141 NewRunnableMethod(change_notifier_.get(), 141 base::Bind(&GoogleURLChangeNotifier::OnChange,
142 &GoogleURLChangeNotifier::OnChange, 142 change_notifier_.get(),
143 UIThreadSearchTermsData().GoogleBaseURLValue())); 143 UIThreadSearchTermsData().GoogleBaseURLValue()));
144 } else { 144 } else {
145 // This must be the death notification. 145 // This must be the death notification.
146 delete this; 146 delete this;
147 } 147 }
148 } 148 }
149 149
150 // Indicates if the two inputs have the same security origin. 150 // Indicates if the two inputs have the same security origin.
151 // |requested_origin| should only be a security origin (no path, etc.). 151 // |requested_origin| should only be a security origin (no path, etc.).
152 // It is ok if |template_url| is NULL. 152 // It is ok if |template_url| is NULL.
153 static bool IsSameOrigin(const GURL& requested_origin, 153 static bool IsSameOrigin(const GURL& requested_origin,
(...skipping 24 matching lines...) Expand all
178 178
179 SearchProviderInstallData::~SearchProviderInstallData() { 179 SearchProviderInstallData::~SearchProviderInstallData() {
180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
181 181
182 if (load_handle_) { 182 if (load_handle_) {
183 DCHECK(web_service_.get()); 183 DCHECK(web_service_.get());
184 web_service_->CancelRequest(load_handle_); 184 web_service_->CancelRequest(load_handle_);
185 } 185 }
186 } 186 }
187 187
188 void SearchProviderInstallData::CallWhenLoaded(Task* task) { 188 void SearchProviderInstallData::CallWhenLoaded(const base::Closure& closure) {
189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
190 190
191 if (provider_map_.get()) { 191 if (provider_map_.get()) {
192 task->Run(); 192 closure.Run();
193 delete task;
194 return; 193 return;
195 } 194 }
196 195
197 task_queue_.Push(task); 196 closure_queue_.push_back(closure);
198 if (load_handle_) 197 if (load_handle_)
199 return; 198 return;
200 199
201 if (web_service_.get()) 200 if (web_service_.get())
202 load_handle_ = web_service_->GetKeywords(this); 201 load_handle_ = web_service_->GetKeywords(this);
203 else 202 else
204 OnLoadFailed(); 203 OnLoadFailed();
205 } 204 }
206 205
207 SearchProviderInstallData::State SearchProviderInstallData::GetInstallState( 206 SearchProviderInstallData::State SearchProviderInstallData::GetInstallState(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 provider_map_.reset(new SearchHostToURLsMap()); 292 provider_map_.reset(new SearchHostToURLsMap());
294 IOThreadSearchTermsData search_terms_data(google_base_url_); 293 IOThreadSearchTermsData search_terms_data(google_base_url_);
295 provider_map_->Init(template_urls_.get(), search_terms_data); 294 provider_map_->Init(template_urls_.get(), search_terms_data);
296 SetDefault(NULL); 295 SetDefault(NULL);
297 NotifyLoaded(); 296 NotifyLoaded();
298 } 297 }
299 298
300 void SearchProviderInstallData::NotifyLoaded() { 299 void SearchProviderInstallData::NotifyLoaded() {
301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
302 301
303 task_queue_.Run(); 302 for (std::vector<base::Closure>::const_iterator it = closure_queue_.begin();
303 it != closure_queue_.end();
304 ++it) {
305 it->Run();
306 }
307 closure_queue_.clear();
sky 2011/11/16 04:42:17 I've feel better if you created a vector on the st
dcheng 2011/11/16 10:00:39 Done for both, but any particular reason for prefe
304 308
305 // Since we expect this request to be rare, clear out the information. This 309 // Since we expect this request to be rare, clear out the information. This
306 // also keeps the responses current as the search providers change. 310 // also keeps the responses current as the search providers change.
307 provider_map_.reset(); 311 provider_map_.reset();
308 SetDefault(NULL); 312 SetDefault(NULL);
309 } 313 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698