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

Side by Side Diff: device/bluetooth/bluetooth_device_chromeos.cc

Issue 180163009: chrome.bluetooth API improvements. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix threading ownership related to ApiResourceManager<BluetoothApiSocket> and BluetoothSocketEventD… Created 6 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "device/bluetooth/bluetooth_device_chromeos.h" 5 #include "device/bluetooth/bluetooth_device_chromeos.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "chromeos/dbus/bluetooth_adapter_client.h" 13 #include "chromeos/dbus/bluetooth_adapter_client.h"
14 #include "chromeos/dbus/bluetooth_device_client.h" 14 #include "chromeos/dbus/bluetooth_device_client.h"
15 #include "chromeos/dbus/bluetooth_input_client.h" 15 #include "chromeos/dbus/bluetooth_input_client.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "dbus/bus.h" 17 #include "dbus/bus.h"
18 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 18 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
19 #include "device/bluetooth/bluetooth_pairing_chromeos.h" 19 #include "device/bluetooth/bluetooth_pairing_chromeos.h"
20 #include "device/bluetooth/bluetooth_profile_chromeos.h" 20 #include "device/bluetooth/bluetooth_profile_chromeos.h"
21 #include "device/bluetooth/bluetooth_socket.h" 21 #include "device/bluetooth/bluetooth_socket.h"
22 #include "third_party/cros_system_api/dbus/service_constants.h" 22 #include "third_party/cros_system_api/dbus/service_constants.h"
23 23
24 using device::BluetoothDevice; 24 using device::BluetoothDevice;
25 25
26 namespace { 26 namespace {
27 27
28 const char kNotImplemented[] = "Function not yet implemented";
29
28 // Histogram enumerations for pairing results. 30 // Histogram enumerations for pairing results.
29 enum UMAPairingResult { 31 enum UMAPairingResult {
30 UMA_PAIRING_RESULT_SUCCESS, 32 UMA_PAIRING_RESULT_SUCCESS,
31 UMA_PAIRING_RESULT_INPROGRESS, 33 UMA_PAIRING_RESULT_INPROGRESS,
32 UMA_PAIRING_RESULT_FAILED, 34 UMA_PAIRING_RESULT_FAILED,
33 UMA_PAIRING_RESULT_AUTH_FAILED, 35 UMA_PAIRING_RESULT_AUTH_FAILED,
34 UMA_PAIRING_RESULT_AUTH_CANCELED, 36 UMA_PAIRING_RESULT_AUTH_CANCELED,
35 UMA_PAIRING_RESULT_AUTH_REJECTED, 37 UMA_PAIRING_RESULT_AUTH_REJECTED,
36 UMA_PAIRING_RESULT_AUTH_TIMEOUT, 38 UMA_PAIRING_RESULT_AUTH_TIMEOUT,
37 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE, 39 UMA_PAIRING_RESULT_UNSUPPORTED_DEVICE,
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 GetProperties(object_path_); 222 GetProperties(object_path_);
221 DCHECK(properties); 223 DCHECK(properties);
222 224
223 return properties->uuids.value(); 225 return properties->uuids.value();
224 } 226 }
225 227
226 void BluetoothDeviceChromeOS::GetServiceRecords( 228 void BluetoothDeviceChromeOS::GetServiceRecords(
227 const ServiceRecordsCallback& callback, 229 const ServiceRecordsCallback& callback,
228 const ErrorCallback& error_callback) { 230 const ErrorCallback& error_callback) {
229 // TODO(keybuk): not implemented; remove 231 // TODO(keybuk): not implemented; remove
230 error_callback.Run(); 232 error_callback.Run(kNotImplemented);
231 } 233 }
232 234
233 void BluetoothDeviceChromeOS::ProvidesServiceWithName( 235 void BluetoothDeviceChromeOS::ProvidesServiceWithName(
234 const std::string& name, 236 const std::string& name,
235 const ProvidesServiceCallback& callback) { 237 const ProvidesServiceCallback& callback) {
236 // TODO(keybuk): not implemented; remove 238 // TODO(keybuk): not implemented; remove
237 callback.Run(false); 239 callback.Run(false);
238 } 240 }
239 241
240 bool BluetoothDeviceChromeOS::ExpectingPinCode() const { 242 bool BluetoothDeviceChromeOS::ExpectingPinCode() const {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 362
361 void BluetoothDeviceChromeOS::ConnectToService( 363 void BluetoothDeviceChromeOS::ConnectToService(
362 const std::string& service_uuid, 364 const std::string& service_uuid,
363 const SocketCallback& callback) { 365 const SocketCallback& callback) {
364 // TODO(keybuk): implement 366 // TODO(keybuk): implement
365 callback.Run(scoped_refptr<device::BluetoothSocket>()); 367 callback.Run(scoped_refptr<device::BluetoothSocket>());
366 } 368 }
367 369
368 void BluetoothDeviceChromeOS::ConnectToProfile( 370 void BluetoothDeviceChromeOS::ConnectToProfile(
369 device::BluetoothProfile* profile, 371 device::BluetoothProfile* profile,
372 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
373 scoped_refptr<base::SequencedTaskRunner> file_task_runner,
374 net::NetLog* net_log,
375 const net::NetLog::Source& source,
370 const base::Closure& callback, 376 const base::Closure& callback,
371 const ErrorCallback& error_callback) { 377 const ErrorCallback& error_callback) {
372 BluetoothProfileChromeOS* profile_chromeos = 378 BluetoothProfileChromeOS* profile_chromeos =
373 static_cast<BluetoothProfileChromeOS*>(profile); 379 static_cast<BluetoothProfileChromeOS*>(profile);
374 VLOG(1) << object_path_.value() << ": Connecting profile: " 380 VLOG(1) << object_path_.value() << ": Connecting profile: "
375 << profile_chromeos->uuid(); 381 << profile_chromeos->uuid();
376 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 382 DBusThreadManager::Get()->GetBluetoothDeviceClient()->
377 ConnectProfile( 383 ConnectProfile(
378 object_path_, 384 object_path_,
379 profile_chromeos->uuid(), 385 profile_chromeos->uuid(),
380 base::Bind( 386 base::Bind(
381 &BluetoothDeviceChromeOS::OnConnectProfile, 387 &BluetoothDeviceChromeOS::OnConnectProfile,
382 weak_ptr_factory_.GetWeakPtr(), 388 weak_ptr_factory_.GetWeakPtr(),
383 profile, 389 profile,
384 callback), 390 callback),
385 base::Bind( 391 base::Bind(
386 &BluetoothDeviceChromeOS::OnConnectProfileError, 392 &BluetoothDeviceChromeOS::OnConnectProfileError,
387 weak_ptr_factory_.GetWeakPtr(), 393 weak_ptr_factory_.GetWeakPtr(),
388 profile, 394 profile,
389 error_callback)); 395 error_callback));
390 } 396 }
391 397
392 void BluetoothDeviceChromeOS::SetOutOfBandPairingData( 398 void BluetoothDeviceChromeOS::SetOutOfBandPairingData(
393 const device::BluetoothOutOfBandPairingData& data, 399 const device::BluetoothOutOfBandPairingData& data,
394 const base::Closure& callback, 400 const base::Closure& callback,
395 const ErrorCallback& error_callback) { 401 const ErrorCallback& error_callback) {
396 // TODO(keybuk): implement 402 // TODO(keybuk): implement
397 error_callback.Run(); 403 error_callback.Run(kNotImplemented);
398 } 404 }
399 405
400 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData( 406 void BluetoothDeviceChromeOS::ClearOutOfBandPairingData(
401 const base::Closure& callback, 407 const base::Closure& callback,
402 const ErrorCallback& error_callback) { 408 const ErrorCallback& error_callback) {
403 // TODO(keybuk): implement 409 // TODO(keybuk): implement
404 error_callback.Run(); 410 error_callback.Run(kNotImplemented);
405 } 411 }
406 412
407 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing( 413 BluetoothPairingChromeOS* BluetoothDeviceChromeOS::BeginPairing(
408 BluetoothDevice::PairingDelegate* pairing_delegate) { 414 BluetoothDevice::PairingDelegate* pairing_delegate) {
409 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate)); 415 pairing_.reset(new BluetoothPairingChromeOS(this, pairing_delegate));
410 return pairing_.get(); 416 return pairing_.get();
411 } 417 }
412 418
413 void BluetoothDeviceChromeOS::EndPairing() { 419 void BluetoothDeviceChromeOS::EndPairing() {
414 pairing_.reset(); 420 pairing_.reset();
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 VLOG(1) << object_path_.value() << ": Disconnected"; 563 VLOG(1) << object_path_.value() << ": Disconnected";
558 callback.Run(); 564 callback.Run();
559 } 565 }
560 566
561 void BluetoothDeviceChromeOS::OnDisconnectError( 567 void BluetoothDeviceChromeOS::OnDisconnectError(
562 const ErrorCallback& error_callback, 568 const ErrorCallback& error_callback,
563 const std::string& error_name, 569 const std::string& error_name,
564 const std::string& error_message) { 570 const std::string& error_message) {
565 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: " 571 LOG(WARNING) << object_path_.value() << ": Failed to disconnect device: "
566 << error_name << ": " << error_message; 572 << error_name << ": " << error_message;
567 error_callback.Run(); 573 error_callback.Run(error_message);
568 } 574 }
569 575
570 void BluetoothDeviceChromeOS::OnForgetError( 576 void BluetoothDeviceChromeOS::OnForgetError(
571 const ErrorCallback& error_callback, 577 const ErrorCallback& error_callback,
572 const std::string& error_name, 578 const std::string& error_name,
573 const std::string& error_message) { 579 const std::string& error_message) {
574 LOG(WARNING) << object_path_.value() << ": Failed to remove device: " 580 LOG(WARNING) << object_path_.value() << ": Failed to remove device: "
575 << error_name << ": " << error_message; 581 << error_name << ": " << error_message;
576 error_callback.Run(); 582 error_callback.Run(error_message);
577 } 583 }
578 584
579 void BluetoothDeviceChromeOS::OnConnectProfile( 585 void BluetoothDeviceChromeOS::OnConnectProfile(
580 device::BluetoothProfile* profile, 586 device::BluetoothProfile* profile,
581 const base::Closure& callback) { 587 const base::Closure& callback) {
582 BluetoothProfileChromeOS* profile_chromeos = 588 BluetoothProfileChromeOS* profile_chromeos =
583 static_cast<BluetoothProfileChromeOS*>(profile); 589 static_cast<BluetoothProfileChromeOS*>(profile);
584 VLOG(1) << object_path_.value() << ": Profile connected: " 590 VLOG(1) << object_path_.value() << ": Profile connected: "
585 << profile_chromeos->uuid(); 591 << profile_chromeos->uuid();
586 callback.Run(); 592 callback.Run();
587 } 593 }
588 594
589 void BluetoothDeviceChromeOS::OnConnectProfileError( 595 void BluetoothDeviceChromeOS::OnConnectProfileError(
590 device::BluetoothProfile* profile, 596 device::BluetoothProfile* profile,
591 const ErrorCallback& error_callback, 597 const ErrorCallback& error_callback,
592 const std::string& error_name, 598 const std::string& error_name,
593 const std::string& error_message) { 599 const std::string& error_message) {
594 BluetoothProfileChromeOS* profile_chromeos = 600 BluetoothProfileChromeOS* profile_chromeos =
595 static_cast<BluetoothProfileChromeOS*>(profile); 601 static_cast<BluetoothProfileChromeOS*>(profile);
596 VLOG(1) << object_path_.value() << ": Profile connection failed: " 602 VLOG(1) << object_path_.value() << ": Profile connection failed: "
597 << profile_chromeos->uuid() << ": " 603 << profile_chromeos->uuid() << ": "
598 << error_name << ": " << error_message; 604 << error_name << ": " << error_message;
599 error_callback.Run(); 605 error_callback.Run(error_message);
600 } 606 }
601 607
602 } // namespace chromeos 608 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698