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

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

Issue 1415573014: Reland "Add Linux support for the Bluetooth API" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build fix. Created 5 years, 1 month 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_bluez.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 "dbus/bus.h" 15 #include "dbus/bus.h"
16 #include "dbus/object_path.h" 16 #include "dbus/object_path.h"
17 #include "device/bluetooth/bluetooth_adapter_chromeos.h" 17 #include "device/bluetooth/bluetooth_adapter_bluez.h"
18 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h" 18 #include "device/bluetooth/dbus/bluetooth_le_advertising_manager_client.h"
19 #include "device/bluetooth/dbus/bluez_dbus_manager.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 << "BluetoothAdvertisementBlueZ::Unregister failed with error code = "
27 << error; 27 << error;
28 } 28 }
29 29
30 device::BluetoothAdvertisement::ErrorCode GetErrorCodeFromErrorStrings( 30 device::BluetoothAdvertisement::ErrorCode GetErrorCodeFromErrorStrings(
31 const std::string& error_name, 31 const std::string& error_name,
32 const std::string& error_message) { 32 const std::string& error_message) {
33 if (error_name == bluetooth_advertising_manager::kErrorFailed || 33 if (error_name == bluetooth_advertising_manager::kErrorFailed ||
34 error_name == bluetooth_advertising_manager::kErrorAlreadyExists) { 34 error_name == bluetooth_advertising_manager::kErrorAlreadyExists) {
35 return device::BluetoothAdvertisement::ErrorCode:: 35 return device::BluetoothAdvertisement::ErrorCode::
36 ERROR_ADVERTISEMENT_ALREADY_EXISTS; 36 ERROR_ADVERTISEMENT_ALREADY_EXISTS;
(...skipping 24 matching lines...) Expand all
61 error_callback, 61 error_callback,
62 const std::string& error_name, 62 const std::string& error_name,
63 const std::string& error_message) { 63 const std::string& error_message) {
64 LOG(WARNING) << "Error while unregistering advertisement. error_name = " 64 LOG(WARNING) << "Error while unregistering advertisement. error_name = "
65 << error_name << ", error_message = " << error_message; 65 << error_name << ", error_message = " << error_message;
66 error_callback.Run(GetErrorCodeFromErrorStrings(error_name, error_message)); 66 error_callback.Run(GetErrorCodeFromErrorStrings(error_name, error_message));
67 } 67 }
68 68
69 } // namespace 69 } // namespace
70 70
71 namespace chromeos { 71 namespace bluez {
72 72
73 BluetoothAdvertisementChromeOS::BluetoothAdvertisementChromeOS( 73 BluetoothAdvertisementBlueZ::BluetoothAdvertisementBlueZ(
74 scoped_ptr<device::BluetoothAdvertisement::Data> data, 74 scoped_ptr<device::BluetoothAdvertisement::Data> data,
75 scoped_refptr<BluetoothAdapterChromeOS> adapter) 75 scoped_refptr<BluetoothAdapterBlueZ> 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(bluez::BluezDBusManager::Get()); 85 DCHECK(bluez::BluezDBusManager::Get());
86 provider_ = bluez::BluetoothLEAdvertisementServiceProvider::Create( 86 provider_ = bluez::BluetoothLEAdvertisementServiceProvider::Create(
87 bluez::BluezDBusManager::Get()->GetSystemBus(), advertisement_object_path, 87 bluez::BluezDBusManager::Get()->GetSystemBus(), advertisement_object_path,
88 this, 88 this,
89 static_cast< 89 static_cast<
90 bluez::BluetoothLEAdvertisementServiceProvider::AdvertisementType>( 90 bluez::BluetoothLEAdvertisementServiceProvider::AdvertisementType>(
91 data->type()), 91 data->type()),
92 data->service_uuids().Pass(), data->manufacturer_data().Pass(), 92 data->service_uuids().Pass(), data->manufacturer_data().Pass(),
93 data->solicit_uuids().Pass(), data->service_data().Pass()); 93 data->solicit_uuids().Pass(), data->service_data().Pass());
94 } 94 }
95 95
96 void BluetoothAdvertisementChromeOS::Register( 96 void BluetoothAdvertisementBlueZ::Register(
97 const base::Closure& success_callback, 97 const base::Closure& success_callback,
98 const device::BluetoothAdapter::CreateAdvertisementErrorCallback& 98 const device::BluetoothAdapter::CreateAdvertisementErrorCallback&
99 error_callback) { 99 error_callback) {
100 DCHECK(bluez::BluezDBusManager::Get()); 100 DCHECK(bluez::BluezDBusManager::Get());
101 bluez::BluezDBusManager::Get() 101 bluez::BluezDBusManager::Get()
102 ->GetBluetoothLEAdvertisingManagerClient() 102 ->GetBluetoothLEAdvertisingManagerClient()
103 ->RegisterAdvertisement( 103 ->RegisterAdvertisement(
104 adapter_->object_path(), provider_->object_path(), success_callback, 104 adapter_->object_path(), provider_->object_path(), success_callback,
105 base::Bind(&RegisterErrorCallbackConnector, error_callback)); 105 base::Bind(&RegisterErrorCallbackConnector, error_callback));
106 } 106 }
107 107
108 BluetoothAdvertisementChromeOS::~BluetoothAdvertisementChromeOS() { 108 BluetoothAdvertisementBlueZ::~BluetoothAdvertisementBlueZ() {
109 Unregister(base::Bind(&base::DoNothing), base::Bind(&UnregisterFailure)); 109 Unregister(base::Bind(&base::DoNothing), base::Bind(&UnregisterFailure));
110 } 110 }
111 111
112 void BluetoothAdvertisementChromeOS::Unregister( 112 void BluetoothAdvertisementBlueZ::Unregister(
113 const SuccessCallback& success_callback, 113 const SuccessCallback& success_callback,
114 const ErrorCallback& error_callback) { 114 const ErrorCallback& error_callback) {
115 // 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,
116 // return an error. 116 // return an error.
117 if (!provider_) { 117 if (!provider_) {
118 error_callback.Run(device::BluetoothAdvertisement::ErrorCode:: 118 error_callback.Run(device::BluetoothAdvertisement::ErrorCode::
119 ERROR_ADVERTISEMENT_DOES_NOT_EXIST); 119 ERROR_ADVERTISEMENT_DOES_NOT_EXIST);
120 return; 120 return;
121 } 121 }
122 122
123 DCHECK(bluez::BluezDBusManager::Get()); 123 DCHECK(bluez::BluezDBusManager::Get());
124 bluez::BluezDBusManager::Get() 124 bluez::BluezDBusManager::Get()
125 ->GetBluetoothLEAdvertisingManagerClient() 125 ->GetBluetoothLEAdvertisingManagerClient()
126 ->UnregisterAdvertisement( 126 ->UnregisterAdvertisement(
127 adapter_->object_path(), provider_->object_path(), success_callback, 127 adapter_->object_path(), provider_->object_path(), success_callback,
128 base::Bind(&UnregisterErrorCallbackConnector, error_callback)); 128 base::Bind(&UnregisterErrorCallbackConnector, error_callback));
129 provider_.reset(); 129 provider_.reset();
130 } 130 }
131 131
132 void BluetoothAdvertisementChromeOS::Released() { 132 void BluetoothAdvertisementBlueZ::Released() {
133 LOG(WARNING) << "Advertisement released."; 133 LOG(WARNING) << "Advertisement released.";
134 provider_.reset(); 134 provider_.reset();
135 FOR_EACH_OBSERVER(BluetoothAdvertisement::Observer, observers_, 135 FOR_EACH_OBSERVER(BluetoothAdvertisement::Observer, observers_,
136 AdvertisementReleased(this)); 136 AdvertisementReleased(this));
137 } 137 }
138 138
139 } // namespace chromeos 139 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698