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

Side by Side Diff: device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.cc

Issue 2389393005: Revert of components/arc: implement multi advertising (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@plumb-incoming-connections
Patch Set: Created 4 years, 2 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
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_.size() >= kMaxBluezAdvertisements) { 58 } else if (!currently_registered_.value().empty()) {
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_.push_back(advertisement_object_path); 62 currently_registered_ = 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 auto service_iter = service_provider_map_.find(advertisement_object_path); 79 ServiceProviderMap::iterator iter =
80 auto reg_iter = 80 service_provider_map_.find(advertisement_object_path);
81 std::find(currently_registered_.begin(), currently_registered_.end(), 81 if (iter == service_provider_map_.end()) {
82 advertisement_object_path);
83
84 if (service_iter == service_provider_map_.end()) {
85 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, 82 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
86 "Advertisement not registered"); 83 "Advertisement not registered");
87 } else if (reg_iter == currently_registered_.end()) { 84 } else if (advertisement_object_path != currently_registered_) {
88 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist, 85 error_callback.Run(bluetooth_advertising_manager::kErrorDoesNotExist,
89 "Does not exist"); 86 "Does not exist");
90 } else { 87 } else {
91 currently_registered_.erase(reg_iter); 88 currently_registered_ = dbus::ObjectPath("");
92 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback); 89 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
93 } 90 }
94 } 91 }
95 92
96 void FakeBluetoothLEAdvertisingManagerClient::SetAdvertisingInterval( 93 void FakeBluetoothLEAdvertisingManagerClient::SetAdvertisingInterval(
97 const dbus::ObjectPath& object_path, 94 const dbus::ObjectPath& object_path,
98 uint16_t min_interval_ms, 95 uint16_t min_interval_ms,
99 uint16_t max_interval_ms, 96 uint16_t max_interval_ms,
100 const base::Closure& callback, 97 const base::Closure& callback,
101 const ErrorCallback& error_callback) { 98 const ErrorCallback& error_callback) {
(...skipping 15 matching lines...) Expand all
117 void FakeBluetoothLEAdvertisingManagerClient:: 114 void FakeBluetoothLEAdvertisingManagerClient::
118 UnregisterAdvertisementServiceProvider( 115 UnregisterAdvertisementServiceProvider(
119 FakeBluetoothLEAdvertisementServiceProvider* service_provider) { 116 FakeBluetoothLEAdvertisementServiceProvider* service_provider) {
120 ServiceProviderMap::iterator iter = 117 ServiceProviderMap::iterator iter =
121 service_provider_map_.find(service_provider->object_path_); 118 service_provider_map_.find(service_provider->object_path_);
122 if (iter != service_provider_map_.end() && iter->second == service_provider) 119 if (iter != service_provider_map_.end() && iter->second == service_provider)
123 service_provider_map_.erase(iter); 120 service_provider_map_.erase(iter);
124 } 121 }
125 122
126 } // namespace bluez 123 } // namespace bluez
OLDNEW
« no previous file with comments | « device/bluetooth/dbus/fake_bluetooth_le_advertising_manager_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698