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 "chromeos/dbus/fake_bluetooth_adapter_client.h" | 5 #include "chromeos/dbus/fake_bluetooth_adapter_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 VLOG(1) << "GetAll"; | 58 VLOG(1) << "GetAll"; |
59 } | 59 } |
60 | 60 |
61 void FakeBluetoothAdapterClient::Properties::Set( | 61 void FakeBluetoothAdapterClient::Properties::Set( |
62 dbus::PropertyBase *property, | 62 dbus::PropertyBase *property, |
63 dbus::PropertySet::SetCallback callback) { | 63 dbus::PropertySet::SetCallback callback) { |
64 VLOG(1) << "Set " << property->name(); | 64 VLOG(1) << "Set " << property->name(); |
65 if (property->name() == powered.name() || property->name() == alias.name()) { | 65 if (property->name() == powered.name() || property->name() == alias.name()) { |
66 callback.Run(true); | 66 callback.Run(true); |
67 property->ReplaceValueWithSetValue(); | 67 property->ReplaceValueWithSetValue(); |
68 NotifyPropertyChanged(property->name()); | |
69 } else { | 68 } else { |
70 callback.Run(false); | 69 callback.Run(false); |
71 } | 70 } |
72 } | 71 } |
73 | 72 |
74 | 73 |
75 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() | 74 FakeBluetoothAdapterClient::FakeBluetoothAdapterClient() |
76 : visible_(true), | 75 : visible_(true), |
77 second_visible_(false), | 76 second_visible_(false), |
78 discovering_count_(0) { | 77 discovering_count_(0) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return; | 133 return; |
135 } | 134 } |
136 | 135 |
137 ++discovering_count_; | 136 ++discovering_count_; |
138 VLOG(1) << "StartDiscovery: " << object_path.value() << ", " | 137 VLOG(1) << "StartDiscovery: " << object_path.value() << ", " |
139 << "count is now " << discovering_count_; | 138 << "count is now " << discovering_count_; |
140 callback.Run(); | 139 callback.Run(); |
141 | 140 |
142 if (discovering_count_ == 1) { | 141 if (discovering_count_ == 1) { |
143 properties_->discovering.ReplaceValue(true); | 142 properties_->discovering.ReplaceValue(true); |
144 properties_->NotifyPropertyChanged(properties_->discovering.name()); | |
145 | 143 |
146 FakeBluetoothDeviceClient* device_client = | 144 FakeBluetoothDeviceClient* device_client = |
147 static_cast<FakeBluetoothDeviceClient*>( | 145 static_cast<FakeBluetoothDeviceClient*>( |
148 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); | 146 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); |
149 device_client->BeginDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); | 147 device_client->BeginDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); |
150 } | 148 } |
151 } | 149 } |
152 | 150 |
153 void FakeBluetoothAdapterClient::StopDiscovery( | 151 void FakeBluetoothAdapterClient::StopDiscovery( |
154 const dbus::ObjectPath& object_path, | 152 const dbus::ObjectPath& object_path, |
(...skipping 15 matching lines...) Expand all Loading... |
170 << "count is now " << discovering_count_; | 168 << "count is now " << discovering_count_; |
171 callback.Run(); | 169 callback.Run(); |
172 | 170 |
173 if (discovering_count_ == 0) { | 171 if (discovering_count_ == 0) { |
174 FakeBluetoothDeviceClient* device_client = | 172 FakeBluetoothDeviceClient* device_client = |
175 static_cast<FakeBluetoothDeviceClient*>( | 173 static_cast<FakeBluetoothDeviceClient*>( |
176 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); | 174 DBusThreadManager::Get()->GetExperimentalBluetoothDeviceClient()); |
177 device_client->EndDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); | 175 device_client->EndDiscoverySimulation(dbus::ObjectPath(kAdapterPath)); |
178 | 176 |
179 properties_->discovering.ReplaceValue(false); | 177 properties_->discovering.ReplaceValue(false); |
180 properties_->NotifyPropertyChanged(properties_->discovering.name()); | |
181 } | 178 } |
182 } | 179 } |
183 | 180 |
184 void FakeBluetoothAdapterClient::RemoveDevice( | 181 void FakeBluetoothAdapterClient::RemoveDevice( |
185 const dbus::ObjectPath& object_path, | 182 const dbus::ObjectPath& object_path, |
186 const dbus::ObjectPath& device_path, | 183 const dbus::ObjectPath& device_path, |
187 const base::Closure& callback, | 184 const base::Closure& callback, |
188 const ErrorCallback& error_callback) { | 185 const ErrorCallback& error_callback) { |
189 if (object_path != dbus::ObjectPath(kAdapterPath)) { | 186 if (object_path != dbus::ObjectPath(kAdapterPath)) { |
190 error_callback.Run(kNoResponseError, ""); | 187 error_callback.Run(kNoResponseError, ""); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 236 |
240 void FakeBluetoothAdapterClient::OnPropertyChanged( | 237 void FakeBluetoothAdapterClient::OnPropertyChanged( |
241 const std::string& property_name) { | 238 const std::string& property_name) { |
242 if (property_name == properties_->powered.name() && | 239 if (property_name == properties_->powered.name() && |
243 !properties_->powered.value()) { | 240 !properties_->powered.value()) { |
244 VLOG(1) << "Adapter powered off"; | 241 VLOG(1) << "Adapter powered off"; |
245 | 242 |
246 if (discovering_count_) { | 243 if (discovering_count_) { |
247 discovering_count_ = 0; | 244 discovering_count_ = 0; |
248 properties_->discovering.ReplaceValue(false); | 245 properties_->discovering.ReplaceValue(false); |
249 properties_->NotifyPropertyChanged(properties_->discovering.name()); | |
250 } | 246 } |
251 } | 247 } |
252 | 248 |
253 FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, | 249 FOR_EACH_OBSERVER(ExperimentalBluetoothAdapterClient::Observer, observers_, |
254 AdapterPropertyChanged(dbus::ObjectPath(kAdapterPath), | 250 AdapterPropertyChanged(dbus::ObjectPath(kAdapterPath), |
255 property_name)); | 251 property_name)); |
256 } | 252 } |
257 | 253 |
258 } // namespace chromeos | 254 } // namespace chromeos |
OLD | NEW |