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

Unified Diff: device/bluetooth/test/fake_central.cc

Issue 2858803003: bluetooth: Implement simulatePreconnectedPeripheral. (Closed)
Patch Set: small cleanup Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/test/fake_central.cc
diff --git a/device/bluetooth/test/fake_central.cc b/device/bluetooth/test/fake_central.cc
index 6c9e10f6bb286fa1410e8badff14a9adac228cea..5b109684226fa1ad90f90425611edaaa5ea0f99a 100644
--- a/device/bluetooth/test/fake_central.cc
+++ b/device/bluetooth/test/fake_central.cc
@@ -4,8 +4,16 @@
#include "device/bluetooth/test/fake_central.h"
+#include <memory>
+#include <string>
+#include <utility>
+
+#include "base/bind_helpers.h"
+#include "base/stl_util.h"
+#include "base/threading/thread_task_runner_handle.h"
#include "device/bluetooth/bluetooth_discovery_filter.h"
#include "device/bluetooth/public/interfaces/test/fake_bluetooth.mojom.h"
+#include "device/bluetooth/test/fake_peripheral.h"
namespace bluetooth {
@@ -13,7 +21,26 @@ FakeCentral::FakeCentral(mojom::CentralState state,
mojom::FakeCentralRequest request)
: state_(state), binding_(this, std::move(request)) {}
-FakeCentral::~FakeCentral() {}
+void FakeCentral::SimulateSystemConnectedPeripheral(
+ const std::string& address,
+ const std::string& name,
+ const SimulateSystemConnectedPeripheralCallback& callback) {
+ auto device_iter = devices_.find(address);
+ if (device_iter == devices_.end()) {
scheib 2017/05/03 20:38:49 If called with the same address but a new name thi
ortuno 2017/05/04 04:16:21 Good catch. This is at the JS API level right? A p
scheib 2017/05/04 04:54:20 Even with your update the logic sets the name if t
+ std::unique_ptr<FakePeripheral> fake_peripheral =
+ base::MakeUnique<FakePeripheral>(this, address, name);
+
+ auto insert_iter = devices_.emplace(address, std::move(fake_peripheral));
+ DCHECK(insert_iter.second);
+ device_iter = insert_iter.first;
+ }
+
+ FakePeripheral* fake_peripheral =
+ static_cast<FakePeripheral*>(device_iter->second.get());
+ fake_peripheral->SetGattConnected(true);
+
+ callback.Run(fake_peripheral->GetIdentifier());
+}
std::string FakeCentral::GetAddress() const {
NOTREACHED();
@@ -154,4 +181,6 @@ void FakeCentral::RemovePairingDelegateInternal(
NOTREACHED();
}
+FakeCentral::~FakeCentral() {}
+
} // namespace bluetooth

Powered by Google App Engine
This is Rietveld 408576698