Commit 55e23a53 authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[Nearby] Create and use SetName method on bluetooth::mojom::Adapter.

Use the new bluetooth::mojom::Adapter::SetName() to implement
Nearby Connections' BluetoothAdapter::SetName().

See go/nearby-chrome-bt for more information.

Bug: b:154848416, b:154845584, b:154847207
Change-Id: I3caf4b8ea5c1724bf1085b18bd4056acad21d774
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2340877Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799791}
parent 22584140
......@@ -59,10 +59,9 @@ std::string BluetoothAdapter::GetName() const {
}
bool BluetoothAdapter::SetName(absl::string_view name) {
// TODO(b/154848416): Add SetName call to bluetooth::mojom::Adapter and
// invoke it.
NOTIMPLEMENTED();
return false;
bool set_name_success = false;
bool call_success = adapter_->SetName(name.data(), &set_name_success);
return call_success && set_name_success;
}
} // namespace chrome
......
......@@ -118,6 +118,13 @@ TEST_F(BluetoothAdapterTest, TestGetName) {
EXPECT_EQ(fake_adapter_->name_, bluetooth_adapter_->GetName());
}
TEST_F(BluetoothAdapterTest, TestSetName) {
std::string name = "NewName";
EXPECT_NE(name, fake_adapter_->name_);
EXPECT_TRUE(bluetooth_adapter_->SetName(name));
EXPECT_EQ(name, fake_adapter_->name_);
}
} // namespace chrome
} // namespace nearby
} // namespace location
......@@ -81,6 +81,11 @@ void FakeAdapter::SetDiscoverable(bool discoverable,
std::move(callback).Run(/*success=*/true);
}
void FakeAdapter::SetName(const std::string& name, SetNameCallback callback) {
name_ = name;
std::move(callback).Run(/*success=*/true);
}
void FakeAdapter::StartDiscoverySession(
StartDiscoverySessionCallback callback) {
DCHECK(!discovery_session_);
......
......@@ -28,6 +28,7 @@ class FakeAdapter : public mojom::Adapter {
SetClientCallback callback) override;
void SetDiscoverable(bool discoverable,
SetDiscoverableCallback callback) override;
void SetName(const std::string& name, SetNameCallback callback) override;
void StartDiscoverySession(StartDiscoverySessionCallback callback) override;
void ConnectToServiceInsecurely(
const std::string& address,
......
......@@ -131,6 +131,11 @@ BluetoothInternalsTest.prototype = {
return {success: true};
}
async setName() {
this.methodCalled('setName');
return {success: true};
}
async startDiscoverySession() {
return {session: null};
}
......
......@@ -95,6 +95,16 @@ void Adapter::SetDiscoverable(bool discoverable,
weak_ptr_factory_.GetWeakPtr(), copyable_callback));
}
void Adapter::SetName(const std::string& name, SetNameCallback callback) {
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
adapter_->SetName(
name,
base::BindOnce(&Adapter::OnSetName, weak_ptr_factory_.GetWeakPtr(),
copyable_callback),
base::BindOnce(&Adapter::OnSetNameError, weak_ptr_factory_.GetWeakPtr(),
copyable_callback));
}
void Adapter::StartDiscoverySession(StartDiscoverySessionCallback callback) {
auto copyable_callback = base::AdaptCallbackForRepeating(std::move(callback));
adapter_->StartDiscoverySession(
......@@ -189,6 +199,14 @@ void Adapter::OnSetDiscoverableError(SetDiscoverableCallback callback) {
std::move(callback).Run(/*success=*/false);
}
void Adapter::OnSetName(SetNameCallback callback) {
std::move(callback).Run(/*success=*/true);
}
void Adapter::OnSetNameError(SetNameCallback callback) {
std::move(callback).Run(/*success=*/false);
}
void Adapter::OnStartDiscoverySession(
StartDiscoverySessionCallback callback,
std::unique_ptr<device::BluetoothDiscoverySession> session) {
......
......@@ -39,6 +39,7 @@ class Adapter : public mojom::Adapter,
SetClientCallback callback) override;
void SetDiscoverable(bool discoverable,
SetDiscoverableCallback callback) override;
void SetName(const std::string& name, SetNameCallback callback) override;
void StartDiscoverySession(StartDiscoverySessionCallback callback) override;
// TODO(b/162975217): Add a mechanism to allowlist which address and UUID
// pairs clients are allowed to create a connection to.
......@@ -73,6 +74,9 @@ class Adapter : public mojom::Adapter,
void OnSetDiscoverable(SetDiscoverableCallback callback);
void OnSetDiscoverableError(SetDiscoverableCallback callback);
void OnSetName(SetNameCallback callback);
void OnSetNameError(SetNameCallback callback);
void OnStartDiscoverySession(
StartDiscoverySessionCallback callback,
std::unique_ptr<device::BluetoothDiscoverySession> session);
......
......@@ -386,6 +386,8 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothAdapter
// Set the human-readable name of the adapter to |name|. On success,
// |callback| will be called. On failure, |error_callback| will be called.
// TODO(crbug.com/1117654): Implement a mechanism to request this resource
// before being able to use it.
virtual void SetName(const std::string& name,
base::OnceClosure callback,
ErrorCallback error_callback) = 0;
......
......@@ -113,6 +113,12 @@ interface Adapter {
[Sync]
SetDiscoverable(bool discoverable) => (bool success);
// Change the name of the local device as it appears to remote devices.
// TODO(crbug.com/1117654): Implement a mechanism to request this resource
// before being able to use it.
[Sync]
SetName(string name) => (bool success);
// Requests the adapter to start a new discovery session. Returns null if
// session not created successfully.
[Sync]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment