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

Side by Side Diff: extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatcher.cc

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatc her.h" 5 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_event_dispatc her.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "device/bluetooth/bluetooth_device.h" 10 #include "device/bluetooth/bluetooth_device.h"
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void BluetoothSocketEventDispatcher::ReceiveCallback( 190 void BluetoothSocketEventDispatcher::ReceiveCallback(
191 const SocketParams& params, 191 const SocketParams& params,
192 int bytes_read, 192 int bytes_read,
193 scoped_refptr<net::IOBuffer> io_buffer) { 193 scoped_refptr<net::IOBuffer> io_buffer) {
194 DCHECK_CURRENTLY_ON(params.thread_id); 194 DCHECK_CURRENTLY_ON(params.thread_id);
195 195
196 // Dispatch "onReceive" event. 196 // Dispatch "onReceive" event.
197 bluetooth_socket::ReceiveInfo receive_info; 197 bluetooth_socket::ReceiveInfo receive_info;
198 receive_info.socket_id = params.socket_id; 198 receive_info.socket_id = params.socket_id;
199 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read); 199 receive_info.data.assign(io_buffer->data(), io_buffer->data() + bytes_read);
200 scoped_ptr<base::ListValue> args = 200 std::unique_ptr<base::ListValue> args =
201 bluetooth_socket::OnReceive::Create(receive_info); 201 bluetooth_socket::OnReceive::Create(receive_info);
202 scoped_ptr<Event> event(new Event(events::BLUETOOTH_SOCKET_ON_RECEIVE, 202 std::unique_ptr<Event> event(
203 bluetooth_socket::OnReceive::kEventName, 203 new Event(events::BLUETOOTH_SOCKET_ON_RECEIVE,
204 std::move(args))); 204 bluetooth_socket::OnReceive::kEventName, std::move(args)));
205 PostEvent(params, std::move(event)); 205 PostEvent(params, std::move(event));
206 206
207 // Post a task to delay the read until the socket is available, as 207 // Post a task to delay the read until the socket is available, as
208 // calling StartReceive at this point would error with ERR_IO_PENDING. 208 // calling StartReceive at this point would error with ERR_IO_PENDING.
209 BrowserThread::PostTask( 209 BrowserThread::PostTask(
210 params.thread_id, 210 params.thread_id,
211 FROM_HERE, 211 FROM_HERE,
212 base::Bind(&BluetoothSocketEventDispatcher::StartReceive, params)); 212 base::Bind(&BluetoothSocketEventDispatcher::StartReceive, params));
213 } 213 }
214 214
(...skipping 10 matching lines...) Expand all
225 // care. 225 // care.
226 return; 226 return;
227 } 227 }
228 228
229 // Dispatch "onReceiveError" event but don't start another read to avoid 229 // Dispatch "onReceiveError" event but don't start another read to avoid
230 // potential infinite reads if we have a persistent network error. 230 // potential infinite reads if we have a persistent network error.
231 bluetooth_socket::ReceiveErrorInfo receive_error_info; 231 bluetooth_socket::ReceiveErrorInfo receive_error_info;
232 receive_error_info.socket_id = params.socket_id; 232 receive_error_info.socket_id = params.socket_id;
233 receive_error_info.error_message = error; 233 receive_error_info.error_message = error;
234 receive_error_info.error = MapReceiveErrorReason(error_reason); 234 receive_error_info.error = MapReceiveErrorReason(error_reason);
235 scoped_ptr<base::ListValue> args = 235 std::unique_ptr<base::ListValue> args =
236 bluetooth_socket::OnReceiveError::Create(receive_error_info); 236 bluetooth_socket::OnReceiveError::Create(receive_error_info);
237 scoped_ptr<Event> event( 237 std::unique_ptr<Event> event(
238 new Event(events::BLUETOOTH_SOCKET_ON_RECEIVE_ERROR, 238 new Event(events::BLUETOOTH_SOCKET_ON_RECEIVE_ERROR,
239 bluetooth_socket::OnReceiveError::kEventName, std::move(args))); 239 bluetooth_socket::OnReceiveError::kEventName, std::move(args)));
240 PostEvent(params, std::move(event)); 240 PostEvent(params, std::move(event));
241 241
242 // Since we got an error, the socket is now "paused" until the application 242 // Since we got an error, the socket is now "paused" until the application
243 // "resumes" it. 243 // "resumes" it.
244 BluetoothApiSocket* socket = 244 BluetoothApiSocket* socket =
245 params.sockets->Get(params.extension_id, params.socket_id); 245 params.sockets->Get(params.extension_id, params.socket_id);
246 if (socket) { 246 if (socket) {
247 socket->set_paused(true); 247 socket->set_paused(true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 params.extension_id, 287 params.extension_id,
288 socket, 288 socket,
289 device->GetAddress(), 289 device->GetAddress(),
290 server_api_socket->uuid()); 290 server_api_socket->uuid());
291 int client_socket_id = params.sockets->Add(client_api_socket); 291 int client_socket_id = params.sockets->Add(client_api_socket);
292 292
293 // Dispatch "onAccept" event. 293 // Dispatch "onAccept" event.
294 bluetooth_socket::AcceptInfo accept_info; 294 bluetooth_socket::AcceptInfo accept_info;
295 accept_info.socket_id = params.socket_id; 295 accept_info.socket_id = params.socket_id;
296 accept_info.client_socket_id = client_socket_id; 296 accept_info.client_socket_id = client_socket_id;
297 scoped_ptr<base::ListValue> args = 297 std::unique_ptr<base::ListValue> args =
298 bluetooth_socket::OnAccept::Create(accept_info); 298 bluetooth_socket::OnAccept::Create(accept_info);
299 scoped_ptr<Event> event(new Event(events::BLUETOOTH_SOCKET_ON_ACCEPT, 299 std::unique_ptr<Event> event(new Event(events::BLUETOOTH_SOCKET_ON_ACCEPT,
300 bluetooth_socket::OnAccept::kEventName, 300 bluetooth_socket::OnAccept::kEventName,
301 std::move(args))); 301 std::move(args)));
302 PostEvent(params, std::move(event)); 302 PostEvent(params, std::move(event));
303 303
304 // Post a task to delay the accept until the socket is available, as 304 // Post a task to delay the accept until the socket is available, as
305 // calling StartAccept at this point would error with ERR_IO_PENDING. 305 // calling StartAccept at this point would error with ERR_IO_PENDING.
306 BrowserThread::PostTask( 306 BrowserThread::PostTask(
307 params.thread_id, 307 params.thread_id,
308 FROM_HERE, 308 FROM_HERE,
309 base::Bind(&BluetoothSocketEventDispatcher::StartAccept, params)); 309 base::Bind(&BluetoothSocketEventDispatcher::StartAccept, params));
310 } 310 }
311 311
(...skipping 10 matching lines...) Expand all
322 // care. 322 // care.
323 return; 323 return;
324 } 324 }
325 325
326 // Dispatch "onAcceptError" event but don't start another accept to avoid 326 // Dispatch "onAcceptError" event but don't start another accept to avoid
327 // potential infinite accepts if we have a persistent network error. 327 // potential infinite accepts if we have a persistent network error.
328 bluetooth_socket::AcceptErrorInfo accept_error_info; 328 bluetooth_socket::AcceptErrorInfo accept_error_info;
329 accept_error_info.socket_id = params.socket_id; 329 accept_error_info.socket_id = params.socket_id;
330 accept_error_info.error_message = error; 330 accept_error_info.error_message = error;
331 accept_error_info.error = MapAcceptErrorReason(error_reason); 331 accept_error_info.error = MapAcceptErrorReason(error_reason);
332 scoped_ptr<base::ListValue> args = 332 std::unique_ptr<base::ListValue> args =
333 bluetooth_socket::OnAcceptError::Create(accept_error_info); 333 bluetooth_socket::OnAcceptError::Create(accept_error_info);
334 scoped_ptr<Event> event(new Event(events::BLUETOOTH_SOCKET_ON_ACCEPT_ERROR, 334 std::unique_ptr<Event> event(
335 bluetooth_socket::OnAcceptError::kEventName, 335 new Event(events::BLUETOOTH_SOCKET_ON_ACCEPT_ERROR,
336 std::move(args))); 336 bluetooth_socket::OnAcceptError::kEventName, std::move(args)));
337 PostEvent(params, std::move(event)); 337 PostEvent(params, std::move(event));
338 338
339 // Since we got an error, the socket is now "paused" until the application 339 // Since we got an error, the socket is now "paused" until the application
340 // "resumes" it. 340 // "resumes" it.
341 BluetoothApiSocket* socket = 341 BluetoothApiSocket* socket =
342 params.sockets->Get(params.extension_id, params.socket_id); 342 params.sockets->Get(params.extension_id, params.socket_id);
343 if (socket) { 343 if (socket) {
344 socket->set_paused(true); 344 socket->set_paused(true);
345 } 345 }
346 } 346 }
347 347
348 // static 348 // static
349 void BluetoothSocketEventDispatcher::PostEvent(const SocketParams& params, 349 void BluetoothSocketEventDispatcher::PostEvent(const SocketParams& params,
350 scoped_ptr<Event> event) { 350 std::unique_ptr<Event> event) {
351 DCHECK_CURRENTLY_ON(params.thread_id); 351 DCHECK_CURRENTLY_ON(params.thread_id);
352 352
353 BrowserThread::PostTask( 353 BrowserThread::PostTask(
354 BrowserThread::UI, FROM_HERE, 354 BrowserThread::UI, FROM_HERE,
355 base::Bind(&DispatchEvent, params.browser_context_id, params.extension_id, 355 base::Bind(&DispatchEvent, params.browser_context_id, params.extension_id,
356 base::Passed(std::move(event)))); 356 base::Passed(std::move(event))));
357 } 357 }
358 358
359 // static 359 // static
360 void BluetoothSocketEventDispatcher::DispatchEvent( 360 void BluetoothSocketEventDispatcher::DispatchEvent(
361 void* browser_context_id, 361 void* browser_context_id,
362 const std::string& extension_id, 362 const std::string& extension_id,
363 scoped_ptr<Event> event) { 363 std::unique_ptr<Event> event) {
364 DCHECK_CURRENTLY_ON(BrowserThread::UI); 364 DCHECK_CURRENTLY_ON(BrowserThread::UI);
365 365
366 content::BrowserContext* context = 366 content::BrowserContext* context =
367 reinterpret_cast<content::BrowserContext*>(browser_context_id); 367 reinterpret_cast<content::BrowserContext*>(browser_context_id);
368 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context)) 368 if (!extensions::ExtensionsBrowserClient::Get()->IsValidContext(context))
369 return; 369 return;
370 370
371 EventRouter* router = EventRouter::Get(context); 371 EventRouter* router = EventRouter::Get(context);
372 if (router) 372 if (router)
373 router->DispatchEventToExtension(extension_id, std::move(event)); 373 router->DispatchEventToExtension(extension_id, std::move(event));
374 } 374 }
375 375
376 } // namespace api 376 } // namespace api
377 } // namespace extensions 377 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698