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

Side by Side Diff: chrome/browser/extensions/api/dial/dial_api.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 (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/extensions/api/dial/dial_api.h" 5 #include "chrome/browser/extensions/api/dial/dial_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 dial_registry_->AddDeviceForTest(*test_device_data_); 57 dial_registry_->AddDeviceForTest(*test_device_data_);
58 } 58 }
59 } 59 }
60 return dial_registry_; 60 return dial_registry_;
61 } 61 }
62 62
63 void DialAPI::OnListenerAdded(const EventListenerInfo& details) { 63 void DialAPI::OnListenerAdded(const EventListenerInfo& details) {
64 DCHECK_CURRENTLY_ON(BrowserThread::UI); 64 DCHECK_CURRENTLY_ON(BrowserThread::UI);
65 BrowserThread::PostTask( 65 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE, 66 BrowserThread::IO, FROM_HERE,
67 base::Bind(&DialAPI::NotifyListenerAddedOnIOThread, this)); 67 base::BindOnce(&DialAPI::NotifyListenerAddedOnIOThread, this));
68 } 68 }
69 69
70 void DialAPI::OnListenerRemoved(const EventListenerInfo& details) { 70 void DialAPI::OnListenerRemoved(const EventListenerInfo& details) {
71 DCHECK_CURRENTLY_ON(BrowserThread::UI); 71 DCHECK_CURRENTLY_ON(BrowserThread::UI);
72 BrowserThread::PostTask( 72 BrowserThread::PostTask(
73 BrowserThread::IO, FROM_HERE, 73 BrowserThread::IO, FROM_HERE,
74 base::Bind(&DialAPI::NotifyListenerRemovedOnIOThread, this)); 74 base::BindOnce(&DialAPI::NotifyListenerRemovedOnIOThread, this));
75 } 75 }
76 76
77 void DialAPI::NotifyListenerAddedOnIOThread() { 77 void DialAPI::NotifyListenerAddedOnIOThread() {
78 DCHECK_CURRENTLY_ON(BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(BrowserThread::IO);
79 VLOG(2) << "DIAL device event listener added."; 79 VLOG(2) << "DIAL device event listener added.";
80 dial_registry()->OnListenerAdded(); 80 dial_registry()->OnListenerAdded();
81 } 81 }
82 82
83 void DialAPI::NotifyListenerRemovedOnIOThread() { 83 void DialAPI::NotifyListenerRemovedOnIOThread() {
84 DCHECK_CURRENTLY_ON(BrowserThread::IO); 84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
85 VLOG(2) << "DIAL device event listener removed"; 85 VLOG(2) << "DIAL device event listener removed";
86 dial_registry()->OnListenerRemoved(); 86 dial_registry()->OnListenerRemoved();
87 } 87 }
88 88
89 void DialAPI::FillDialDevice(const media_router::DialDeviceData& device_data, 89 void DialAPI::FillDialDevice(const media_router::DialDeviceData& device_data,
90 api::dial::DialDevice* device) const { 90 api::dial::DialDevice* device) const {
91 DCHECK(!device_data.device_id().empty()); 91 DCHECK(!device_data.device_id().empty());
92 DCHECK(media_router::DialDeviceData::IsDeviceDescriptionUrl( 92 DCHECK(media_router::DialDeviceData::IsDeviceDescriptionUrl(
93 device_data.device_description_url())); 93 device_data.device_description_url()));
94 device->device_label = device_data.label(); 94 device->device_label = device_data.label();
95 device->device_description_url = device_data.device_description_url().spec(); 95 device->device_description_url = device_data.device_description_url().spec();
96 if (device_data.has_config_id()) 96 if (device_data.has_config_id())
97 device->config_id.reset(new int(device_data.config_id())); 97 device->config_id.reset(new int(device_data.config_id()));
98 } 98 }
99 99
100 void DialAPI::OnDialDeviceEvent(const DialRegistry::DeviceList& devices) { 100 void DialAPI::OnDialDeviceEvent(const DialRegistry::DeviceList& devices) {
101 DCHECK_CURRENTLY_ON(BrowserThread::IO); 101 DCHECK_CURRENTLY_ON(BrowserThread::IO);
102 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 102 BrowserThread::PostTask(
103 base::Bind(&DialAPI::SendEventOnUIThread, this, devices)); 103 BrowserThread::UI, FROM_HERE,
104 base::BindOnce(&DialAPI::SendEventOnUIThread, this, devices));
104 } 105 }
105 106
106 void DialAPI::OnDialError(const DialRegistry::DialErrorCode code) { 107 void DialAPI::OnDialError(const DialRegistry::DialErrorCode code) {
107 DCHECK_CURRENTLY_ON(BrowserThread::IO); 108 DCHECK_CURRENTLY_ON(BrowserThread::IO);
108 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 109 BrowserThread::PostTask(
109 base::Bind(&DialAPI::SendErrorOnUIThread, this, code)); 110 BrowserThread::UI, FROM_HERE,
111 base::BindOnce(&DialAPI::SendErrorOnUIThread, this, code));
110 } 112 }
111 113
112 void DialAPI::SendEventOnUIThread(const DialRegistry::DeviceList& devices) { 114 void DialAPI::SendEventOnUIThread(const DialRegistry::DeviceList& devices) {
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); 115 DCHECK_CURRENTLY_ON(BrowserThread::UI);
114 116
115 std::vector<api::dial::DialDevice> args; 117 std::vector<api::dial::DialDevice> args;
116 for (const DialDeviceData& device : devices) { 118 for (const DialDeviceData& device : devices) {
117 api::dial::DialDevice api_device; 119 api::dial::DialDevice api_device;
118 FillDialDevice(device, &api_device); 120 FillDialDevice(device, &api_device);
119 args.push_back(std::move(api_device)); 121 args.push_back(std::move(api_device));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 DialFetchDeviceDescriptionFunction::~DialFetchDeviceDescriptionFunction() {} 199 DialFetchDeviceDescriptionFunction::~DialFetchDeviceDescriptionFunction() {}
198 200
199 bool DialFetchDeviceDescriptionFunction::RunAsync() { 201 bool DialFetchDeviceDescriptionFunction::RunAsync() {
200 dial_ = DialAPIFactory::GetForBrowserContext(browser_context()).get(); 202 dial_ = DialAPIFactory::GetForBrowserContext(browser_context()).get();
201 params_ = api::dial::FetchDeviceDescription::Params::Create(*args_); 203 params_ = api::dial::FetchDeviceDescription::Params::Create(*args_);
202 EXTENSION_FUNCTION_VALIDATE(params_.get()); 204 EXTENSION_FUNCTION_VALIDATE(params_.get());
203 205
204 // DialRegistry lives on the IO thread. Hop on over there to get the URL to 206 // DialRegistry lives on the IO thread. Hop on over there to get the URL to
205 // fetch. 207 // fetch.
206 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 208 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
207 base::Bind(&DialFetchDeviceDescriptionFunction:: 209 base::BindOnce(&DialFetchDeviceDescriptionFunction::
208 GetDeviceDescriptionUrlOnIOThread, 210 GetDeviceDescriptionUrlOnIOThread,
209 this, params_->device_label)); 211 this, params_->device_label));
210 return true; 212 return true;
211 } 213 }
212 214
213 void DialFetchDeviceDescriptionFunction::GetDeviceDescriptionUrlOnIOThread( 215 void DialFetchDeviceDescriptionFunction::GetDeviceDescriptionUrlOnIOThread(
214 const std::string& label) { 216 const std::string& label) {
215 DCHECK_CURRENTLY_ON(BrowserThread::IO); 217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
216 const GURL& device_description_url = 218 const GURL& device_description_url =
217 dial_->dial_registry()->GetDeviceDescriptionURL(label); 219 dial_->dial_registry()->GetDeviceDescriptionURL(label);
218 BrowserThread::PostTask( 220 BrowserThread::PostTask(
219 BrowserThread::UI, FROM_HERE, 221 BrowserThread::UI, FROM_HERE,
220 base::Bind(&DialFetchDeviceDescriptionFunction::MaybeStartFetch, this, 222 base::BindOnce(&DialFetchDeviceDescriptionFunction::MaybeStartFetch, this,
221 device_description_url)); 223 device_description_url));
222 } 224 }
223 225
224 void DialFetchDeviceDescriptionFunction::MaybeStartFetch(const GURL& url) { 226 void DialFetchDeviceDescriptionFunction::MaybeStartFetch(const GURL& url) {
225 DCHECK_CURRENTLY_ON(BrowserThread::UI); 227 DCHECK_CURRENTLY_ON(BrowserThread::UI);
226 if (url.is_empty()) { 228 if (url.is_empty()) {
227 SetError("Device not found"); 229 SetError("Device not found");
228 SendResponse(false); 230 SendResponse(false);
229 return; 231 return;
230 } 232 }
231 233
(...skipping 28 matching lines...) Expand all
260 void DialFetchDeviceDescriptionFunction::OnFetchError( 262 void DialFetchDeviceDescriptionFunction::OnFetchError(
261 const std::string& message) { 263 const std::string& message) {
262 // Destroy the DeviceDescriptionFetcher since it still contains a reference 264 // Destroy the DeviceDescriptionFetcher since it still contains a reference
263 // to |this| in its un-invoked callback. 265 // to |this| in its un-invoked callback.
264 device_description_fetcher_.reset(); 266 device_description_fetcher_.reset();
265 SetError(message); 267 SetError(message);
266 SendResponse(false); 268 SendResponse(false);
267 } 269 }
268 270
269 } // namespace extensions 271 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698