| OLD | NEW |
| 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_input_client.h" | 5 #include "device/bluetooth/dbus/fake_bluetooth_input_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
| 12 #include "dbus/message.h" | 12 #include "dbus/message.h" |
| 13 #include "dbus/object_manager.h" | 13 #include "dbus/object_manager.h" |
| 14 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
| 15 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" | 15 #include "device/bluetooth/dbus/fake_bluetooth_device_client.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 16 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 | 17 |
| 18 namespace bluez { | 18 namespace bluez { |
| 19 | 19 |
| 20 FakeBluetoothInputClient::Properties::Properties( | 20 FakeBluetoothInputClient::Properties::Properties( |
| 21 const PropertyChangedCallback& callback) | 21 const PropertyChangedCallback& callback) |
| 22 : BluetoothInputClient::Properties( | 22 : BluetoothInputClient::Properties( |
| 23 NULL, | 23 nullptr, |
| 24 bluetooth_input::kBluetoothInputInterface, | 24 bluetooth_input::kBluetoothInputInterface, |
| 25 callback) {} | 25 callback) {} |
| 26 | 26 |
| 27 FakeBluetoothInputClient::Properties::~Properties() {} | 27 FakeBluetoothInputClient::Properties::~Properties() {} |
| 28 | 28 |
| 29 void FakeBluetoothInputClient::Properties::Get( | 29 void FakeBluetoothInputClient::Properties::Get( |
| 30 dbus::PropertyBase* property, | 30 dbus::PropertyBase* property, |
| 31 dbus::PropertySet::GetCallback callback) { | 31 dbus::PropertySet::GetCallback callback) { |
| 32 VLOG(1) << "Get " << property->name(); | 32 VLOG(1) << "Get " << property->name(); |
| 33 callback.Run(false); | 33 callback.Run(false); |
| 34 } | 34 } |
| 35 | 35 |
| 36 void FakeBluetoothInputClient::Properties::GetAll() { | 36 void FakeBluetoothInputClient::Properties::GetAll() { |
| 37 VLOG(1) << "GetAll"; | 37 VLOG(1) << "GetAll"; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void FakeBluetoothInputClient::Properties::Set( | 40 void FakeBluetoothInputClient::Properties::Set( |
| 41 dbus::PropertyBase* property, | 41 dbus::PropertyBase* property, |
| 42 dbus::PropertySet::SetCallback callback) { | 42 dbus::PropertySet::SetCallback callback) { |
| 43 VLOG(1) << "Set " << property->name(); | 43 VLOG(1) << "Set " << property->name(); |
| 44 callback.Run(false); | 44 callback.Run(false); |
| 45 } | 45 } |
| 46 | 46 |
| 47 FakeBluetoothInputClient::FakeBluetoothInputClient() {} | 47 FakeBluetoothInputClient::FakeBluetoothInputClient() {} |
| 48 | 48 |
| 49 FakeBluetoothInputClient::~FakeBluetoothInputClient() { | 49 FakeBluetoothInputClient::~FakeBluetoothInputClient() {} |
| 50 // Clean up Properties structures | |
| 51 base::STLDeleteValues(&properties_map_); | |
| 52 } | |
| 53 | 50 |
| 54 void FakeBluetoothInputClient::Init(dbus::Bus* bus) {} | 51 void FakeBluetoothInputClient::Init(dbus::Bus* bus) {} |
| 55 | 52 |
| 56 void FakeBluetoothInputClient::AddObserver(Observer* observer) { | 53 void FakeBluetoothInputClient::AddObserver(Observer* observer) { |
| 57 observers_.AddObserver(observer); | 54 observers_.AddObserver(observer); |
| 58 } | 55 } |
| 59 | 56 |
| 60 void FakeBluetoothInputClient::RemoveObserver(Observer* observer) { | 57 void FakeBluetoothInputClient::RemoveObserver(Observer* observer) { |
| 61 observers_.RemoveObserver(observer); | 58 observers_.RemoveObserver(observer); |
| 62 } | 59 } |
| 63 | 60 |
| 64 FakeBluetoothInputClient::Properties* FakeBluetoothInputClient::GetProperties( | 61 FakeBluetoothInputClient::Properties* FakeBluetoothInputClient::GetProperties( |
| 65 const dbus::ObjectPath& object_path) { | 62 const dbus::ObjectPath& object_path) { |
| 66 PropertiesMap::iterator iter = properties_map_.find(object_path); | 63 auto iter = properties_map_.find(object_path); |
| 67 if (iter != properties_map_.end()) | 64 if (iter != properties_map_.end()) |
| 68 return iter->second; | 65 return iter->second.get(); |
| 69 return NULL; | 66 return nullptr; |
| 70 } | 67 } |
| 71 | 68 |
| 72 void FakeBluetoothInputClient::AddInputDevice( | 69 void FakeBluetoothInputClient::AddInputDevice( |
| 73 const dbus::ObjectPath& object_path) { | 70 const dbus::ObjectPath& object_path) { |
| 74 if (properties_map_.find(object_path) != properties_map_.end()) | 71 if (properties_map_.find(object_path) != properties_map_.end()) |
| 75 return; | 72 return; |
| 76 | 73 |
| 77 Properties* properties = | 74 std::unique_ptr<Properties> properties = base::MakeUnique<Properties>( |
| 78 new Properties(base::Bind(&FakeBluetoothInputClient::OnPropertyChanged, | 75 base::Bind(&FakeBluetoothInputClient::OnPropertyChanged, |
| 79 base::Unretained(this), object_path)); | 76 base::Unretained(this), object_path)); |
| 80 | 77 |
| 81 // The LegacyAutopair and DisplayPinCode devices represent a typical mouse | 78 // The LegacyAutopair and DisplayPinCode devices represent a typical mouse |
| 82 // and keyboard respectively, so mark them as ReconnectMode "any". The | 79 // and keyboard respectively, so mark them as ReconnectMode "any". The |
| 83 // DisplayPasskey device represents a Bluetooth 2.1+ keyboard and the | 80 // DisplayPasskey device represents a Bluetooth 2.1+ keyboard and the |
| 84 // ConnectUnpairable device represents a pre-standardization mouse, so mark | 81 // ConnectUnpairable device represents a pre-standardization mouse, so mark |
| 85 // them as ReconnectMode "device". | 82 // them as ReconnectMode "device". |
| 86 if (object_path.value() == FakeBluetoothDeviceClient::kDisplayPasskeyPath || | 83 if (object_path.value() == FakeBluetoothDeviceClient::kDisplayPasskeyPath || |
| 87 object_path.value() == | 84 object_path.value() == |
| 88 FakeBluetoothDeviceClient::kConnectUnpairablePath) { | 85 FakeBluetoothDeviceClient::kConnectUnpairablePath) { |
| 89 properties->reconnect_mode.ReplaceValue( | 86 properties->reconnect_mode.ReplaceValue( |
| 90 bluetooth_input::kDeviceReconnectModeProperty); | 87 bluetooth_input::kDeviceReconnectModeProperty); |
| 91 } else { | 88 } else { |
| 92 properties->reconnect_mode.ReplaceValue( | 89 properties->reconnect_mode.ReplaceValue( |
| 93 bluetooth_input::kAnyReconnectModeProperty); | 90 bluetooth_input::kAnyReconnectModeProperty); |
| 94 } | 91 } |
| 95 | 92 |
| 96 properties_map_[object_path] = properties; | 93 properties_map_[object_path] = std::move(properties); |
| 97 | 94 |
| 98 for (auto& observer : observers_) | 95 for (auto& observer : observers_) |
| 99 observer.InputAdded(object_path); | 96 observer.InputAdded(object_path); |
| 100 } | 97 } |
| 101 | 98 |
| 102 void FakeBluetoothInputClient::RemoveInputDevice( | 99 void FakeBluetoothInputClient::RemoveInputDevice( |
| 103 const dbus::ObjectPath& object_path) { | 100 const dbus::ObjectPath& object_path) { |
| 104 PropertiesMap::iterator it = properties_map_.find(object_path); | 101 auto it = properties_map_.find(object_path); |
| 105 | 102 |
| 106 if (it == properties_map_.end()) | 103 if (it == properties_map_.end()) |
| 107 return; | 104 return; |
| 108 | 105 |
| 109 for (auto& observer : observers_) | 106 for (auto& observer : observers_) |
| 110 observer.InputRemoved(object_path); | 107 observer.InputRemoved(object_path); |
| 111 | 108 |
| 112 delete it->second; | |
| 113 properties_map_.erase(it); | 109 properties_map_.erase(it); |
| 114 } | 110 } |
| 115 | 111 |
| 116 void FakeBluetoothInputClient::OnPropertyChanged( | 112 void FakeBluetoothInputClient::OnPropertyChanged( |
| 117 const dbus::ObjectPath& object_path, | 113 const dbus::ObjectPath& object_path, |
| 118 const std::string& property_name) { | 114 const std::string& property_name) { |
| 119 for (auto& observer : observers_) | 115 for (auto& observer : observers_) |
| 120 observer.InputPropertyChanged(object_path, property_name); | 116 observer.InputPropertyChanged(object_path, property_name); |
| 121 } | 117 } |
| 122 | 118 |
| 123 } // namespace bluez | 119 } // namespace bluez |
| OLD | NEW |