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

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

Powered by Google App Engine
This is Rietveld 408576698