OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/location.h" | 5 #include "base/location.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "dbus/bus.h" | 9 #include "dbus/bus.h" |
10 #include "dbus/message.h" | 10 #include "dbus/message.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) { | 48 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) { |
49 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path."); | 49 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path."); |
50 return; | 50 return; |
51 } | 51 } |
52 | 52 |
53 ServiceProviderMap::iterator iter = | 53 ServiceProviderMap::iterator iter = |
54 service_provider_map_.find(advertisement_object_path); | 54 service_provider_map_.find(advertisement_object_path); |
55 if (iter == service_provider_map_.end()) { | 55 if (iter == service_provider_map_.end()) { |
56 error_callback.Run(bluetooth_advertising_manager::kErrorInvalidArguments, | 56 error_callback.Run(bluetooth_advertising_manager::kErrorInvalidArguments, |
57 "Advertisement object not registered"); | 57 "Advertisement object not registered"); |
58 } else if (!currently_registered_.value().empty()) { | 58 } else if (currently_registered_.size() >= kMaxBluezAdvertisements) { |
59 error_callback.Run(bluetooth_advertising_manager::kErrorFailed, | 59 error_callback.Run(bluetooth_advertising_manager::kErrorFailed, |
60 "Maximum advertisements reached"); | 60 "Maximum advertisements reached"); |
61 } else { | 61 } else { |
62 currently_registered_ = advertisement_object_path; | 62 currently_registered_.push_back(advertisement_object_path); |
63 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 63 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 void FakeBluetoothLEAdvertisingManagerClient::UnregisterAdvertisement( | 67 void FakeBluetoothLEAdvertisingManagerClient::UnregisterAdvertisement( |
68 const dbus::ObjectPath& manager_object_path, | 68 const dbus::ObjectPath& manager_object_path, |
69 const dbus::ObjectPath& advertisement_object_path, | 69 const dbus::ObjectPath& advertisement_object_path, |
70 const base::Closure& callback, | 70 const base::Closure& callback, |
71 const ErrorCallback& error_callback) { | 71 const ErrorCallback& error_callback) { |
72 VLOG(1) << "UnregisterAdvertisment: " << advertisement_object_path.value(); | 72 VLOG(1) << "UnregisterAdvertisment: " << advertisement_object_path.value(); |
73 | 73 |
74 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) { | 74 if (manager_object_path != dbus::ObjectPath(kAdvertisingManagerPath)) { |
75 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path."); | 75 error_callback.Run(kNoResponseError, "Invalid Advertising Manager path."); |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 ServiceProviderMap::iterator iter = | 79 auto service_iter = service_provider_map_.find(advertisement_object_path); |
80 service_provider_map_.find(advertisement_object_path); | 80 auto reg_iter = |
81 if (iter == service_provider_map_.end()) { | 81 std::find(currently_registered_.begin(), currently_registered_.end(), |
| 82 advertisement_object_path); |
| 83 |
| 84 if (service_iter == service_provider_map_.end()) { |
82 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, | 85 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, |
83 "Advertisement not registered"); | 86 "Advertisement not registered"); |
84 } else if (advertisement_object_path != currently_registered_) { | 87 } else if (reg_iter == currently_registered_.end()) { |
85 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, | 88 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, |
86 "Does not exist"); | 89 "Does not exist"); |
87 } else { | 90 } else { |
88 currently_registered_ = dbus::ObjectPath(""); | 91 currently_registered_.erase(reg_iter); |
89 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); | 92 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); |
90 } | 93 } |
91 } | 94 } |
92 | 95 |
93 void FakeBluetoothLEAdvertisingManagerClient::SetAdvertisingInterval( | 96 void FakeBluetoothLEAdvertisingManagerClient::SetAdvertisingInterval( |
94 const dbus::ObjectPath& object_path, | 97 const dbus::ObjectPath& object_path, |
95 uint16_t min_interval_ms, | 98 uint16_t min_interval_ms, |
96 uint16_t max_interval_ms, | 99 uint16_t max_interval_ms, |
97 const base::Closure& callback, | 100 const base::Closure& callback, |
98 const ErrorCallback& error_callback) { | 101 const ErrorCallback& error_callback) { |
(...skipping 15 matching lines...) Expand all Loading... |
114 void FakeBluetoothLEAdvertisingManagerClient:: | 117 void FakeBluetoothLEAdvertisingManagerClient:: |
115 UnregisterAdvertisementServiceProvider( | 118 UnregisterAdvertisementServiceProvider( |
116 FakeBluetoothLEAdvertisementServiceProvider* service_provider) { | 119 FakeBluetoothLEAdvertisementServiceProvider* service_provider) { |
117 ServiceProviderMap::iterator iter = | 120 ServiceProviderMap::iterator iter = |
118 service_provider_map_.find(service_provider->object_path_); | 121 service_provider_map_.find(service_provider->object_path_); |
119 if (iter != service_provider_map_.end() && iter->second == service_provider) | 122 if (iter != service_provider_map_.end() && iter->second == service_provider) |
120 service_provider_map_.erase(iter); | 123 service_provider_map_.erase(iter); |
121 } | 124 } |
122 | 125 |
123 } // namespace bluez | 126 } // namespace bluez |
OLD | NEW |