Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chromeos/dbus/fake_bluetooth_input_client.h" | |
| 6 | |
| 7 #include <map> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/stl_util.h" | |
| 11 #include "chromeos/dbus/bluetooth_property.h" | |
| 12 #include "chromeos/dbus/fake_bluetooth_device_client.h" | |
| 13 #include "dbus/bus.h" | |
| 14 #include "dbus/message.h" | |
| 15 #include "dbus/object_manager.h" | |
| 16 #include "dbus/object_path.h" | |
| 17 #include "dbus/object_proxy.h" | |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 19 | |
| 20 namespace chromeos { | |
| 21 | |
| 22 FakeBluetoothInputClient::Properties::Properties( | |
| 23 const PropertyChangedCallback& callback) | |
| 24 : ExperimentalBluetoothInputClient::Properties( | |
| 25 NULL, | |
| 26 bluetooth_input::kExperimentalBluetoothInputInterface, | |
| 27 callback) { | |
| 28 } | |
| 29 | |
| 30 FakeBluetoothInputClient::Properties::~Properties() { | |
| 31 } | |
| 32 | |
| 33 void FakeBluetoothInputClient::Properties::Get( | |
| 34 dbus::PropertyBase* property, | |
| 35 dbus::PropertySet::GetCallback callback) { | |
| 36 VLOG(1) << "Get " << property->name(); | |
| 37 callback.Run(false); | |
| 38 } | |
| 39 | |
| 40 void FakeBluetoothInputClient::Properties::GetAll() { | |
| 41 VLOG(1) << "GetAll"; | |
| 42 } | |
| 43 | |
| 44 void FakeBluetoothInputClient::Properties::Set( | |
| 45 dbus::PropertyBase *property, | |
| 46 dbus::PropertySet::SetCallback callback) { | |
| 47 VLOG(1) << "Set " << property->name(); | |
| 48 callback.Run(false); | |
| 49 } | |
| 50 | |
| 51 | |
| 52 FakeBluetoothInputClient::FakeBluetoothInputClient() { | |
| 53 } | |
| 54 | |
| 55 FakeBluetoothInputClient::~FakeBluetoothInputClient() { | |
| 56 // Clean up Properties structures | |
| 57 STLDeleteValues(&properties_map_); | |
| 58 } | |
| 59 | |
| 60 void FakeBluetoothInputClient::AddObserver(Observer* observer) { | |
| 61 observers_.AddObserver(observer); | |
| 62 } | |
| 63 | |
| 64 void FakeBluetoothInputClient::RemoveObserver(Observer* observer) { | |
| 65 observers_.RemoveObserver(observer); | |
| 66 } | |
| 67 | |
| 68 FakeBluetoothInputClient::Properties* | |
| 69 FakeBluetoothInputClient::GetProperties(const dbus::ObjectPath& object_path) { | |
| 70 PropertiesMap::iterator iter = properties_map_.find(object_path); | |
| 71 if (iter != properties_map_.end()) | |
| 72 return iter->second; | |
| 73 return NULL; | |
| 74 } | |
| 75 | |
| 76 void FakeBluetoothInputClient::AddInputDevice( | |
| 77 const dbus::ObjectPath& object_path) { | |
| 78 if (properties_map_.find(object_path) != properties_map_.end()) | |
| 79 return; | |
| 80 | |
| 81 Properties* properties = new Properties(base::Bind( | |
| 82 &FakeBluetoothInputClient::OnPropertyChanged, | |
| 83 base::Unretained(this), | |
| 84 object_path)); | |
| 85 | |
| 86 // Mark Apple mouse and keyboard as ReconnectMode "any" and the Motorola and | |
| 87 // Microsoft devices as ReconnectMode "device". | |
| 88 if (object_path.value() == FakeBluetoothDeviceClient::kMotorolaKeyboardPath || | |
| 89 object_path.value() == FakeBluetoothDeviceClient::kMicrosoftMousePath) { | |
| 90 properties->reconnect_mode.ReplaceValue( | |
| 91 bluetooth_input::kDeviceReconnectModeProperty); | |
| 92 } else { | |
| 93 properties->reconnect_mode.ReplaceValue( | |
| 94 bluetooth_input::kAnyReconnectModeProperty); | |
| 95 } | |
| 96 | |
| 97 properties_map_[object_path] = properties; | |
| 98 | |
| 99 FOR_EACH_OBSERVER(ExperimentalBluetoothInputClient::Observer, observers_, | |
| 100 InputAdded(object_path)); | |
| 101 } | |
| 102 | |
| 103 void FakeBluetoothInputClient::RemoveInputDevice( | |
| 104 const dbus::ObjectPath& object_path) { | |
| 105 PropertiesMap::iterator it = properties_map_.find(object_path); | |
| 106 | |
| 107 if (it == properties_map_.end()) | |
| 108 return; | |
| 109 delete it->second; | |
| 110 properties_map_.erase(it); | |
| 111 | |
| 112 FOR_EACH_OBSERVER(ExperimentalBluetoothInputClient::Observer, observers_, | |
| 113 InputRemoved(object_path)); | |
|
keybuk
2013/04/18 20:50:25
Object Manager ensures that the Properties* is sti
deymo
2013/04/18 22:19:55
Done.
| |
| 114 } | |
| 115 | |
| 116 void FakeBluetoothInputClient::OnPropertyChanged( | |
| 117 const dbus::ObjectPath& object_path, | |
| 118 const std::string& property_name) { | |
| 119 FOR_EACH_OBSERVER(ExperimentalBluetoothInputClient::Observer, observers_, | |
| 120 InputPropertyChanged(object_path, property_name)); | |
| 121 } | |
| 122 | |
| 123 } // namespace chromeos | |
| OLD | NEW |