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

Side by Side Diff: chromeos/dbus/fake_bluetooth_device_client.h

Issue 1258783009: Add functionality to Bluetooth settings UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge changes from new patch Created 5 years, 4 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 (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 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ 5 #ifndef CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_
7 7
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/containers/scoped_ptr_map.h"
13 #include "base/observer_list.h" 14 #include "base/observer_list.h"
14 #include "chromeos/chromeos_export.h" 15 #include "chromeos/chromeos_export.h"
15 #include "chromeos/dbus/bluetooth_agent_service_provider.h" 16 #include "chromeos/dbus/bluetooth_agent_service_provider.h"
16 #include "chromeos/dbus/bluetooth_device_client.h" 17 #include "chromeos/dbus/bluetooth_device_client.h"
17 #include "chromeos/dbus/bluetooth_profile_service_provider.h" 18 #include "chromeos/dbus/bluetooth_profile_service_provider.h"
18 #include "dbus/object_path.h" 19 #include "dbus/object_path.h"
19 #include "dbus/property.h" 20 #include "dbus/property.h"
20 21
21 namespace chromeos { 22 namespace chromeos {
22 23
23 // FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon 24 // FakeBluetoothDeviceClient simulates the behavior of the Bluetooth Daemon
24 // device objects and is used both in test cases in place of a mock and on 25 // device objects and is used both in test cases in place of a mock and on
25 // the Linux desktop. 26 // the Linux desktop.
26 class CHROMEOS_EXPORT FakeBluetoothDeviceClient 27 class CHROMEOS_EXPORT FakeBluetoothDeviceClient
27 : public BluetoothDeviceClient { 28 : public BluetoothDeviceClient {
28 public: 29 public:
29 struct Properties : public BluetoothDeviceClient::Properties { 30 struct Properties : public BluetoothDeviceClient::Properties {
30 explicit Properties(const PropertyChangedCallback & callback); 31 explicit Properties(const PropertyChangedCallback & callback);
31 ~Properties() override; 32 ~Properties() override;
32 33
33 // dbus::PropertySet override 34 // dbus::PropertySet override
34 void Get(dbus::PropertyBase* property, 35 void Get(dbus::PropertyBase* property,
35 dbus::PropertySet::GetCallback callback) override; 36 dbus::PropertySet::GetCallback callback) override;
36 void GetAll() override; 37 void GetAll() override;
37 void Set(dbus::PropertyBase* property, 38 void Set(dbus::PropertyBase* property,
38 dbus::PropertySet::SetCallback callback) override; 39 dbus::PropertySet::SetCallback callback) override;
39 }; 40 };
40 41
42 struct SimulatedPairingOptions {
43 std::string pairing_method;
44 std::string pairing_auth_token;
45 };
46
47 // Stores properties of a device that is about to be
48 // created.
stevenjb 2015/08/03 15:02:57 One line
rfrappier 2015/08/03 15:43:15 Done.
49 struct IncomingDeviceProperties {
50 IncomingDeviceProperties();
51 ~IncomingDeviceProperties();
stevenjb 2015/08/03 15:02:57 Constructor / destructor not needed in struct.
rfrappier 2015/08/03 15:43:15 Chrome's style checker requires them in this case
stevenjb 2015/08/03 15:56:20 Ew. OK, nevermind.
52
53 std::string device_name;
54 std::string device_alias;
55 std::string device_address;
56 std::string device_path;
57 std::string pairing_method;
58 std::string pairing_auth_token;
59 int device_class = 0;
60 bool is_trusted = true;
61 };
62
41 FakeBluetoothDeviceClient(); 63 FakeBluetoothDeviceClient();
42 ~FakeBluetoothDeviceClient() override; 64 ~FakeBluetoothDeviceClient() override;
43 65
44 // BluetoothDeviceClient overrides 66 // BluetoothDeviceClient overrides
45 void Init(dbus::Bus* bus) override; 67 void Init(dbus::Bus* bus) override;
46 void AddObserver(Observer* observer) override; 68 void AddObserver(Observer* observer) override;
47 void RemoveObserver(Observer* observer) override; 69 void RemoveObserver(Observer* observer) override;
48 std::vector<dbus::ObjectPath> GetDevicesForAdapter( 70 std::vector<dbus::ObjectPath> GetDevicesForAdapter(
49 const dbus::ObjectPath& adapter_path) override; 71 const dbus::ObjectPath& adapter_path) override;
50 Properties* GetProperties(const dbus::ObjectPath& object_path) override; 72 Properties* GetProperties(const dbus::ObjectPath& object_path) override;
(...skipping 28 matching lines...) Expand all
79 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path); 101 void EndDiscoverySimulation(const dbus::ObjectPath& adapter_path);
80 102
81 // Simulates incoming pairing of devices for the given adapter. 103 // Simulates incoming pairing of devices for the given adapter.
82 void BeginIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); 104 void BeginIncomingPairingSimulation(const dbus::ObjectPath& adapter_path);
83 void EndIncomingPairingSimulation(const dbus::ObjectPath& adapter_path); 105 void EndIncomingPairingSimulation(const dbus::ObjectPath& adapter_path);
84 106
85 // Creates a device from the set we return for the given adapter. 107 // Creates a device from the set we return for the given adapter.
86 void CreateDevice(const dbus::ObjectPath& adapter_path, 108 void CreateDevice(const dbus::ObjectPath& adapter_path,
87 const dbus::ObjectPath& device_path); 109 const dbus::ObjectPath& device_path);
88 110
111 // Creates a device with the given properties.
112 void CreateDeviceWithProperties(const dbus::ObjectPath& adapter_path,
113 const IncomingDeviceProperties& props);
114
115 SimulatedPairingOptions* GetPairingOptions(
116 const dbus::ObjectPath& object_path);
117
89 // Removes a device from the set we return for the given adapter. 118 // Removes a device from the set we return for the given adapter.
90 void RemoveDevice(const dbus::ObjectPath& adapter_path, 119 void RemoveDevice(const dbus::ObjectPath& adapter_path,
91 const dbus::ObjectPath& device_path); 120 const dbus::ObjectPath& device_path);
92 121
93 // Simulates a pairing for the device with the given D-Bus object path, 122 // Simulates a pairing for the device with the given D-Bus object path,
94 // |object_path|. Set |incoming_request| to true if simulating an incoming 123 // |object_path|. Set |incoming_request| to true if simulating an incoming
95 // pairing request, false for an outgoing one. On successful completion 124 // pairing request, false for an outgoing one. On successful completion
96 // |callback| will be called, on failure, |error_callback| is called. 125 // |callback| will be called, on failure, |error_callback| is called.
97 void SimulatePairing(const dbus::ObjectPath& object_path, 126 void SimulatePairing(const dbus::ObjectPath& object_path,
98 bool incoming_request, 127 bool incoming_request,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 BluetoothProfileServiceProvider::Delegate::Status status); 268 BluetoothProfileServiceProvider::Delegate::Status status);
240 void DisconnectionCallback( 269 void DisconnectionCallback(
241 const dbus::ObjectPath& object_path, 270 const dbus::ObjectPath& object_path,
242 const base::Closure& callback, 271 const base::Closure& callback,
243 const ErrorCallback& error_callback, 272 const ErrorCallback& error_callback,
244 BluetoothProfileServiceProvider::Delegate::Status status); 273 BluetoothProfileServiceProvider::Delegate::Status status);
245 274
246 // List of observers interested in event notifications from us. 275 // List of observers interested in event notifications from us.
247 base::ObserverList<Observer> observers_; 276 base::ObserverList<Observer> observers_;
248 277
249 // Static properties we return. 278 using PropertiesMap =
250 typedef std::map<const dbus::ObjectPath, Properties *> PropertiesMap; 279 base::ScopedPtrMap<const dbus::ObjectPath, scoped_ptr<Properties>>;
251 PropertiesMap properties_map_; 280 PropertiesMap properties_map_;
252 std::vector<dbus::ObjectPath> device_list_; 281 std::vector<dbus::ObjectPath> device_list_;
253 282
283 // Properties which are used to decied which method of pairing should
284 // be done on request.
285 using PairingOptionsMap =
286 base::ScopedPtrMap<const dbus::ObjectPath,
287 scoped_ptr<SimulatedPairingOptions>>;
288 PairingOptionsMap pairing_options_map_;
289
254 int simulation_interval_ms_; 290 int simulation_interval_ms_;
255 uint32_t discovery_simulation_step_; 291 uint32_t discovery_simulation_step_;
256 uint32_t incoming_pairing_simulation_step_; 292 uint32_t incoming_pairing_simulation_step_;
257 bool pairing_cancelled_; 293 bool pairing_cancelled_;
258 294
259 int16 connection_rssi_; 295 int16 connection_rssi_;
260 int16 transmit_power_; 296 int16 transmit_power_;
261 int16 max_transmit_power_; 297 int16 max_transmit_power_;
262 }; 298 };
263 299
264 } // namespace chromeos 300 } // namespace chromeos
265 301
266 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_ 302 #endif // CHROMEOS_DBUS_FAKE_BLUETOOTH_DEVICE_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698