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

Side by Side Diff: chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.cc

Issue 2825963003: Rewrite base::Bind to base::BindOnce with base_bind_rewriters in //chrome/browser/extensions (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/extensions/api/runtime/chrome_runtime_api_delegate.h" 5 #include "chrome/browser/extensions/api/runtime/chrome_runtime_api_delegate.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 202
203 ExtensionService* service = 203 ExtensionService* service =
204 ExtensionSystem::Get(browser_context_)->extension_service(); 204 ExtensionSystem::Get(browser_context_)->extension_service();
205 if (reload_info.second >= kFastReloadCount) { 205 if (reload_info.second >= kFastReloadCount) {
206 // Unloading an extension clears all warnings, so first terminate the 206 // Unloading an extension clears all warnings, so first terminate the
207 // extension, and then add the warning. Since this is called from an 207 // extension, and then add the warning. Since this is called from an
208 // extension function unloading the extension has to be done 208 // extension function unloading the extension has to be done
209 // asynchronously. Fortunately PostTask guarentees FIFO order so just 209 // asynchronously. Fortunately PostTask guarentees FIFO order so just
210 // post both tasks. 210 // post both tasks.
211 base::ThreadTaskRunnerHandle::Get()->PostTask( 211 base::ThreadTaskRunnerHandle::Get()->PostTask(
212 FROM_HERE, base::Bind(&ExtensionService::TerminateExtension, 212 FROM_HERE, base::BindOnce(&ExtensionService::TerminateExtension,
213 service->AsWeakPtr(), extension_id)); 213 service->AsWeakPtr(), extension_id));
214 extensions::WarningSet warnings; 214 extensions::WarningSet warnings;
215 warnings.insert( 215 warnings.insert(
216 extensions::Warning::CreateReloadTooFrequentWarning( 216 extensions::Warning::CreateReloadTooFrequentWarning(
217 extension_id)); 217 extension_id));
218 base::ThreadTaskRunnerHandle::Get()->PostTask( 218 base::ThreadTaskRunnerHandle::Get()->PostTask(
219 FROM_HERE, base::Bind(&extensions::WarningService::NotifyWarningsOnUI, 219 FROM_HERE,
220 browser_context_, warnings)); 220 base::BindOnce(&extensions::WarningService::NotifyWarningsOnUI,
221 browser_context_, warnings));
221 } else { 222 } else {
222 // We can't call ReloadExtension directly, since when this method finishes 223 // We can't call ReloadExtension directly, since when this method finishes
223 // it tries to decrease the reference count for the extension, which fails 224 // it tries to decrease the reference count for the extension, which fails
224 // if the extension has already been reloaded; so instead we post a task. 225 // if the extension has already been reloaded; so instead we post a task.
225 base::ThreadTaskRunnerHandle::Get()->PostTask( 226 base::ThreadTaskRunnerHandle::Get()->PostTask(
226 FROM_HERE, base::Bind(&ExtensionService::ReloadExtension, 227 FROM_HERE, base::BindOnce(&ExtensionService::ReloadExtension,
227 service->AsWeakPtr(), extension_id)); 228 service->AsWeakPtr(), extension_id));
228 } 229 }
229 } 230 }
230 231
231 bool ChromeRuntimeAPIDelegate::CheckForUpdates( 232 bool ChromeRuntimeAPIDelegate::CheckForUpdates(
232 const std::string& extension_id, 233 const std::string& extension_id,
233 const UpdateCheckCallback& callback) { 234 const UpdateCheckCallback& callback) {
234 ExtensionSystem* system = ExtensionSystem::Get(browser_context_); 235 ExtensionSystem* system = ExtensionSystem::Get(browser_context_);
235 ExtensionService* service = system->extension_service(); 236 ExtensionService* service = system->extension_service();
236 ExtensionUpdater* updater = service->updater(); 237 ExtensionUpdater* updater = service->updater();
237 if (!updater) { 238 if (!updater) {
238 return false; 239 return false;
239 } 240 }
240 241
241 UpdateCheckInfo& info = update_check_info_[extension_id]; 242 UpdateCheckInfo& info = update_check_info_[extension_id];
242 243
243 // If not enough time has elapsed, or we have 10 or more outstanding calls, 244 // If not enough time has elapsed, or we have 10 or more outstanding calls,
244 // return a status of throttled. 245 // return a status of throttled.
245 if (info.backoff->ShouldRejectRequest() || info.callbacks.size() >= 10) { 246 if (info.backoff->ShouldRejectRequest() || info.callbacks.size() >= 10) {
246 base::ThreadTaskRunnerHandle::Get()->PostTask( 247 base::ThreadTaskRunnerHandle::Get()->PostTask(
247 FROM_HERE, 248 FROM_HERE, base::BindOnce(callback, UpdateCheckResult(
248 base::Bind(callback, UpdateCheckResult(true, kUpdateThrottled, ""))); 249 true, kUpdateThrottled, "")));
249 } else { 250 } else {
250 info.callbacks.push_back(callback); 251 info.callbacks.push_back(callback);
251 updater->CheckExtensionSoon( 252 updater->CheckExtensionSoon(
252 extension_id, base::Bind(&ChromeRuntimeAPIDelegate::UpdateCheckComplete, 253 extension_id, base::Bind(&ChromeRuntimeAPIDelegate::UpdateCheckComplete,
253 base::Unretained(this), extension_id)); 254 base::Unretained(this), extension_id));
254 } 255 }
255 return true; 256 return true;
256 } 257 }
257 258
258 void ChromeRuntimeAPIDelegate::OpenURL(const GURL& uninstall_url) { 259 void ChromeRuntimeAPIDelegate::OpenURL(const GURL& uninstall_url) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 const UpdateCheckResult& result) { 388 const UpdateCheckResult& result) {
388 auto it = update_check_info_.find(extension_id); 389 auto it = update_check_info_.find(extension_id);
389 if (it == update_check_info_.end()) 390 if (it == update_check_info_.end())
390 return; 391 return;
391 std::vector<UpdateCheckCallback> callbacks; 392 std::vector<UpdateCheckCallback> callbacks;
392 it->second.callbacks.swap(callbacks); 393 it->second.callbacks.swap(callbacks);
393 for (const auto& callback : callbacks) { 394 for (const auto& callback : callbacks) {
394 callback.Run(result); 395 callback.Run(result);
395 } 396 }
396 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698