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

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

Issue 2084463002: BlueZ + DBus implementations of create/remove service record functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_adapter_client.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/dbus/fake_bluetooth_adapter_client.h" 5 #include "device/bluetooth/dbus/fake_bluetooth_adapter_client.h"
6 6
7 #include <map>
8 #include <utility>
9
10 #include "base/bind_helpers.h"
11 #include "base/callback_forward.h"
7 #include "base/location.h" 12 #include "base/location.h"
8 #include "base/logging.h" 13 #include "base/logging.h"
9 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
11 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "dbus/bus.h"
18 #include "device/bluetooth/bluez/bluetooth_service_record_bluez.h"
12 #include "device/bluetooth/dbus/bluez_dbus_manager.h" 19 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
13 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" 20 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h"
14 #include "third_party/cros_system_api/dbus/service_constants.h" 21 #include "third_party/cros_system_api/dbus/service_constants.h"
15 22
16 namespace bluez { 23 namespace bluez {
17 24
18 namespace { 25 namespace {
19 26
20 // Default interval for delayed tasks. 27 // Default interval for delayed tasks.
21 const int kSimulationIntervalMs = 750; 28 const int kSimulationIntervalMs = 750;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } else { 71 } else {
65 callback.Run(false); 72 callback.Run(false);
66 } 73 }
67 } 74 }
68 75
69 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() 76 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient()
70 : visible_(true), 77 : visible_(true),
71 second_visible_(false), 78 second_visible_(false),
72 discovering_count_(0), 79 discovering_count_(0),
73 set_discovery_filter_should_fail_(false), 80 set_discovery_filter_should_fail_(false),
74 simulation_interval_ms_(kSimulationIntervalMs) { 81 simulation_interval_ms_(kSimulationIntervalMs),
82 last_handle_(0) {
75 properties_.reset(new Properties(base::Bind( 83 properties_.reset(new Properties(base::Bind(
76 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); 84 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this))));
77 85
78 properties_->address.ReplaceValue(kAdapterAddress); 86 properties_->address.ReplaceValue(kAdapterAddress);
79 properties_->name.ReplaceValue("Fake Adapter (Name)"); 87 properties_->name.ReplaceValue("Fake Adapter (Name)");
80 properties_->alias.ReplaceValue(kAdapterName); 88 properties_->alias.ReplaceValue(kAdapterName);
81 properties_->pairable.ReplaceValue(true); 89 properties_->pairable.ReplaceValue(true);
82 90
83 second_properties_.reset(new Properties(base::Bind( 91 second_properties_.reset(new Properties(base::Bind(
84 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this)))); 92 &FakeBluetoothAdapterClient::OnPropertyChanged, base::Unretained(this))));
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 PostDelayedTask(base::Bind(error_callback, kNoResponseError, "")); 227 PostDelayedTask(base::Bind(error_callback, kNoResponseError, ""));
220 set_discovery_filter_should_fail_ = false; 228 set_discovery_filter_should_fail_ = false;
221 return; 229 return;
222 } 230 }
223 231
224 discovery_filter_.reset(new DiscoveryFilter()); 232 discovery_filter_.reset(new DiscoveryFilter());
225 discovery_filter_->CopyFrom(discovery_filter); 233 discovery_filter_->CopyFrom(discovery_filter);
226 PostDelayedTask(callback); 234 PostDelayedTask(callback);
227 } 235 }
228 236
237 void FakeBluetoothAdapterClient::CreateServiceRecord(
238 const dbus::ObjectPath& object_path,
239 const bluez::BluetoothServiceRecordBlueZ& record,
240 const ServiceRecordCallback& callback,
241 const ErrorCallback& error_callback) {
242 ++last_handle_;
243 records_.insert(
244 std::pair<uint32_t, BluetoothServiceRecordBlueZ>(last_handle_, record));
245 callback.Run(last_handle_);
246 }
247
248 void FakeBluetoothAdapterClient::RemoveServiceRecord(
249 const dbus::ObjectPath& object_path,
250 uint32_t handle,
251 const base::Closure& callback,
252 const ErrorCallback& error_callback) {
253 auto it = records_.find(handle);
254 if (it == records_.end()) {
255 error_callback.Run(bluetooth_adapter::kErrorDoesNotExist,
256 "Service record does not exist.");
257 return;
258 }
259 records_.erase(it);
260 callback.Run();
261 }
262
229 void FakeBluetoothAdapterClient::SetSimulationIntervalMs(int interval_ms) { 263 void FakeBluetoothAdapterClient::SetSimulationIntervalMs(int interval_ms) {
230 simulation_interval_ms_ = interval_ms; 264 simulation_interval_ms_ = interval_ms;
231 } 265 }
232 266
233 BluetoothAdapterClient::DiscoveryFilter* 267 BluetoothAdapterClient::DiscoveryFilter*
234 FakeBluetoothAdapterClient::GetDiscoveryFilter() { 268 FakeBluetoothAdapterClient::GetDiscoveryFilter() {
235 return discovery_filter_.get(); 269 return discovery_filter_.get();
236 } 270 }
237 271
238 void FakeBluetoothAdapterClient::SetVisible(bool visible) { 272 void FakeBluetoothAdapterClient::SetVisible(bool visible) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 } 331 }
298 332
299 void FakeBluetoothAdapterClient::PostDelayedTask( 333 void FakeBluetoothAdapterClient::PostDelayedTask(
300 const base::Closure& callback) { 334 const base::Closure& callback) {
301 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 335 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
302 FROM_HERE, callback, 336 FROM_HERE, callback,
303 base::TimeDelta::FromMilliseconds(simulation_interval_ms_)); 337 base::TimeDelta::FromMilliseconds(simulation_interval_ms_));
304 } 338 }
305 339
306 } // namespace bluez 340 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_adapter_client.h ('k') | device/device_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698