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

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

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_advertisement_chromeos.h" 5 #include "device/bluetooth/bluetooth_advertisement_chromeos.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "chromeos/dbus/bluetooth_le_advertising_manager_client.h"
16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "dbus/bus.h" 15 #include "dbus/bus.h"
18 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
19 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 17 #include "device/bluetooth/bluetooth_adapter_chromeos.h"
18 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h"
19 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
20 #include "third_party/cros_system_api/dbus/service_constants.h" 20 #include "third_party/cros_system_api/dbus/service_constants.h"
21 21
22 namespace { 22 namespace {
23 23
24 void UnregisterFailure(device::BluetoothAdvertisement::ErrorCode error) { 24 void UnregisterFailure(device::BluetoothAdvertisement::ErrorCode error) {
25 LOG(ERROR) 25 LOG(ERROR)
26 << "BluetoothAdvertisementChromeOS::Unregister failed with error code = " 26 << "BluetoothAdvertisementChromeOS::Unregister failed with error code = "
27 << error; 27 << error;
28 } 28 }
29 29
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 scoped_refptr<BluetoothAdapterChromeOS> adapter) 75 scoped_refptr<BluetoothAdapterChromeOS> adapter)
76 : adapter_(adapter) { 76 : adapter_(adapter) {
77 // Generate a new object path - make sure that we strip any -'s from the 77 // Generate a new object path - make sure that we strip any -'s from the
78 // generated GUID string since object paths can only contain alphanumeric 78 // generated GUID string since object paths can only contain alphanumeric
79 // characters and _ characters. 79 // characters and _ characters.
80 std::string GuidString = base::GenerateGUID(); 80 std::string GuidString = base::GenerateGUID();
81 base::RemoveChars(GuidString, "-", &GuidString); 81 base::RemoveChars(GuidString, "-", &GuidString);
82 dbus::ObjectPath advertisement_object_path = 82 dbus::ObjectPath advertisement_object_path =
83 dbus::ObjectPath("/org/chromium/bluetooth_advertisement/" + GuidString); 83 dbus::ObjectPath("/org/chromium/bluetooth_advertisement/" + GuidString);
84 84
85 DCHECK(DBusThreadManager::Get()); 85 DCHECK(bluez::BluezDBusManager::Get());
86 provider_ = BluetoothLEAdvertisementServiceProvider::Create( 86 provider_ = bluez::BluetoothLEAdvertisementServiceProvider::Create(
87 DBusThreadManager::Get()->GetSystemBus(), advertisement_object_path, this, 87 bluez::BluezDBusManager::Get()->GetSystemBus(), advertisement_object_path,
88 static_cast<BluetoothLEAdvertisementServiceProvider::AdvertisementType>( 88 this,
89 static_cast<
90 bluez::BluetoothLEAdvertisementServiceProvider::AdvertisementType>(
89 data->type()), 91 data->type()),
90 data->service_uuids().Pass(), data->manufacturer_data().Pass(), 92 data->service_uuids().Pass(), data->manufacturer_data().Pass(),
91 data->solicit_uuids().Pass(), data->service_data().Pass()); 93 data->solicit_uuids().Pass(), data->service_data().Pass());
92 } 94 }
93 95
94 void BluetoothAdvertisementChromeOS::Register( 96 void BluetoothAdvertisementChromeOS::Register(
95 const base::Closure& success_callback, 97 const base::Closure& success_callback,
96 const device::BluetoothAdapter::CreateAdvertisementErrorCallback& 98 const device::BluetoothAdapter::CreateAdvertisementErrorCallback&
97 error_callback) { 99 error_callback) {
98 DCHECK(DBusThreadManager::Get()); 100 DCHECK(bluez::BluezDBusManager::Get());
99 DBusThreadManager::Get() 101 bluez::BluezDBusManager::Get()
100 ->GetBluetoothLEAdvertisingManagerClient() 102 ->GetBluetoothLEAdvertisingManagerClient()
101 ->RegisterAdvertisement( 103 ->RegisterAdvertisement(
102 adapter_->object_path(), provider_->object_path(), success_callback, 104 adapter_->object_path(), provider_->object_path(), success_callback,
103 base::Bind(&RegisterErrorCallbackConnector, error_callback)); 105 base::Bind(&RegisterErrorCallbackConnector, error_callback));
104 } 106 }
105 107
106 BluetoothAdvertisementChromeOS::~BluetoothAdvertisementChromeOS() { 108 BluetoothAdvertisementChromeOS::~BluetoothAdvertisementChromeOS() {
107 Unregister(base::Bind(&base::DoNothing), base::Bind(&UnregisterFailure)); 109 Unregister(base::Bind(&base::DoNothing), base::Bind(&UnregisterFailure));
108 } 110 }
109 111
110 void BluetoothAdvertisementChromeOS::Unregister( 112 void BluetoothAdvertisementChromeOS::Unregister(
111 const SuccessCallback& success_callback, 113 const SuccessCallback& success_callback,
112 const ErrorCallback& error_callback) { 114 const ErrorCallback& error_callback) {
113 // If we don't have a provider, that means we have already been unregistered, 115 // If we don't have a provider, that means we have already been unregistered,
114 // return an error. 116 // return an error.
115 if (!provider_) { 117 if (!provider_) {
116 error_callback.Run(device::BluetoothAdvertisement::ErrorCode:: 118 error_callback.Run(device::BluetoothAdvertisement::ErrorCode::
117 ERROR_ADVERTISEMENT_DOES_NOT_EXIST); 119 ERROR_ADVERTISEMENT_DOES_NOT_EXIST);
118 return; 120 return;
119 } 121 }
120 122
121 DCHECK(DBusThreadManager::Get()); 123 DCHECK(bluez::BluezDBusManager::Get());
122 DBusThreadManager::Get() 124 bluez::BluezDBusManager::Get()
123 ->GetBluetoothLEAdvertisingManagerClient() 125 ->GetBluetoothLEAdvertisingManagerClient()
124 ->UnregisterAdvertisement( 126 ->UnregisterAdvertisement(
125 adapter_->object_path(), provider_->object_path(), success_callback, 127 adapter_->object_path(), provider_->object_path(), success_callback,
126 base::Bind(&UnregisterErrorCallbackConnector, error_callback)); 128 base::Bind(&UnregisterErrorCallbackConnector, error_callback));
127 provider_.reset(); 129 provider_.reset();
128 } 130 }
129 131
130 void BluetoothAdvertisementChromeOS::Released() { 132 void BluetoothAdvertisementChromeOS::Released() {
131 LOG(WARNING) << "Advertisement released."; 133 LOG(WARNING) << "Advertisement released.";
132 provider_.reset(); 134 provider_.reset();
133 FOR_EACH_OBSERVER(BluetoothAdvertisement::Observer, observers_, 135 FOR_EACH_OBSERVER(BluetoothAdvertisement::Observer, observers_,
134 AdvertisementReleased(this)); 136 AdvertisementReleased(this));
135 } 137 }
136 138
137 } // namespace chromeos 139 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_advertisement_chromeos.h ('k') | device/bluetooth/bluetooth_advertisement_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698