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

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.cc

Issue 2353133005: Add the chrome.bluetoothLowEnergy.setAdvertisingInterval API. (Closed)
Patch Set: . Created 4 years, 3 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 "base/location.h" 5 #include "base/location.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/single_thread_task_runner.h" 7 #include "base/single_thread_task_runner.h"
8 #include "base/threading/thread_task_runner_handle.h" 8 #include "base/threading/thread_task_runner_handle.h"
9 #include "dbus/bus.h" 9 #include "dbus/bus.h"
10 #include "dbus/message.h" 10 #include "dbus/message.h"
11 #include "dbus/object_proxy.h" 11 #include "dbus/object_proxy.h"
12 #include "device/bluetooth/dbus/fake_bluetooth_le_advertisement_service_provider .h" 12 #include "device/bluetooth/dbus/fake_bluetooth_le_advertisement_service_provider .h"
13 #include "device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.h" 13 #include "device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
15 15
16 namespace bluez { 16 namespace bluez {
17 17
18 const char FakeBluetoothLEAdvertisingManagerClient::kAdvertisingManagerPath[] = 18 namespace {
19 "/fake/hci0"; 19
20 constexpr char kAdvertisingManagerPath[] = "/fake/hci0";
21 constexpr uint16_t kMinIntervalMs = 20;
ortuno 2016/09/22 03:02:25 nit: Please add an explanation and mention the sec
22 constexpr uint16_t kMaxIntervalMs = 10240;
23
24 } // namespace
20 25
21 FakeBluetoothLEAdvertisingManagerClient:: 26 FakeBluetoothLEAdvertisingManagerClient::
22 FakeBluetoothLEAdvertisingManagerClient() {} 27 FakeBluetoothLEAdvertisingManagerClient() {}
23 28
24 FakeBluetoothLEAdvertisingManagerClient:: 29 FakeBluetoothLEAdvertisingManagerClient::
25 ~FakeBluetoothLEAdvertisingManagerClient() {} 30 ~FakeBluetoothLEAdvertisingManagerClient() {}
26 31
27 void FakeBluetoothLEAdvertisingManagerClient::Init(dbus::Bus* bus) {} 32 void FakeBluetoothLEAdvertisingManagerClient::Init(dbus::Bus* bus) {}
28 33
29 void FakeBluetoothLEAdvertisingManagerClient::AddObserver(Observer* observer) {} 34 void FakeBluetoothLEAdvertisingManagerClient::AddObserver(Observer* observer) {}
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 "Advertisement not registered"); 81 "Advertisement not registered");
77 } else if (advertisement_object_path != currently_registered_) { 82 } else if (advertisement_object_path != currently_registered_) {
78 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, 83 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
79 "Does not exist"); 84 "Does not exist");
80 } else { 85 } else {
81 currently_registered_ = dbus::ObjectPath(""); 86 currently_registered_ = dbus::ObjectPath("");
82 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 87 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
83 } 88 }
84 } 89 }
85 90
91 void FakeBluetoothLEAdvertisingManagerClient::SetAdvertisingInterval(
92 const dbus::ObjectPath& object_path,
93 uint16_t min_interval_ms,
94 uint16_t max_interval_ms,
95 const base::Closure& callback,
96 const ErrorCallback& error_callback) {
97 if (min_interval_ms < kMinIntervalMs || max_interval_ms > kMaxIntervalMs ||
98 min_interval_ms > max_interval_ms) {
99 error_callback.Run(bluetooth_advertising_manager::kErrorInvalidArguments,
100 "Invalid interval.");
101 return;
102 }
103 callback.Run();
104 }
105
86 void FakeBluetoothLEAdvertisingManagerClient:: 106 void FakeBluetoothLEAdvertisingManagerClient::
87 RegisterAdvertisementServiceProvider( 107 RegisterAdvertisementServiceProvider(
88 FakeBluetoothLEAdvertisementServiceProvider* service_provider) { 108 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
89 service_provider_map_[service_provider->object_path_] = service_provider; 109 service_provider_map_[service_provider->object_path_] = service_provider;
90 } 110 }
91 111
92 void FakeBluetoothLEAdvertisingManagerClient:: 112 void FakeBluetoothLEAdvertisingManagerClient::
93 UnregisterAdvertisementServiceProvider( 113 UnregisterAdvertisementServiceProvider(
94 FakeBluetoothLEAdvertisementServiceProvider* service_provider) { 114 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
95 ServiceProviderMap::iterator iter = 115 ServiceProviderMap::iterator iter =
96 service_provider_map_.find(service_provider->object_path_); 116 service_provider_map_.find(service_provider->object_path_);
97 if (iter != service_provider_map_.end() && iter->second == service_provider) 117 if (iter != service_provider_map_.end() && iter->second == service_provider)
98 service_provider_map_.erase(iter); 118 service_provider_map_.erase(iter);
99 } 119 }
100 120
101 } // namespace bluez 121 } // namespace bluez
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698