Commit 1f13d955 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Refactor NearbyConnections to support multiple Cores

Each Core object is meant to be used by a single client, so we will use
one for Nearby Share and one for Phone Hub. Each Core instance uses the
same underlying connectivity framework, so we instantiate a single
OfflineServiceController and share it with all Cores.

This CL also adds a service_id parameter to each
mojom::NearbyConnections function so that we can decide which Core
object to use to process each call.

Bug: 1106937
Change-Id: Ibbf8378822862579b79321689dd00a61d204fb1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495878Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824962}
parent 875685e6
......@@ -98,7 +98,7 @@ void NearbyConnectionsManagerImpl::StartAdvertising(
incoming_connection_listener_ = listener;
nearby_connections_->StartAdvertising(
endpoint_info, kServiceId,
kServiceId, endpoint_info,
AdvertisingOptions::New(
kStrategy, std::move(allowed_mediums),
/*auto_upgrade_bandwidth=*/is_high_power,
......@@ -112,7 +112,7 @@ void NearbyConnectionsManagerImpl::StartAdvertising(
void NearbyConnectionsManagerImpl::StopAdvertising() {
if (nearby_connections_) {
nearby_connections_->StopAdvertising(
base::BindOnce([](ConnectionsStatus status) {
kServiceId, base::BindOnce([](ConnectionsStatus status) {
NS_LOG(VERBOSE) << __func__
<< ": Stop advertising attempted over Nearby "
"Connections with result: "
......@@ -155,7 +155,7 @@ void NearbyConnectionsManagerImpl::StartDiscovery(
void NearbyConnectionsManagerImpl::StopDiscovery() {
if (nearby_connections_) {
nearby_connections_->StopDiscovery(
base::BindOnce([](ConnectionsStatus status) {
kServiceId, base::BindOnce([](ConnectionsStatus status) {
NS_LOG(VERBOSE) << __func__
<< ": Stop discovery attempted over Nearby "
"Connections with result: "
......@@ -203,7 +203,7 @@ void NearbyConnectionsManagerImpl::Connect(
connect_timeout_timers_.emplace(endpoint_id, std::move(timeout_timer));
nearby_connections_->RequestConnection(
endpoint_info, endpoint_id,
kServiceId, endpoint_info, endpoint_id,
ConnectionOptions::New(std::move(allowed_mediums),
std::move(bluetooth_mac_address)),
std::move(lifecycle_listener),
......@@ -239,7 +239,7 @@ void NearbyConnectionsManagerImpl::Disconnect(const std::string& endpoint_id) {
return;
nearby_connections_->DisconnectFromEndpoint(
endpoint_id,
kServiceId, endpoint_id,
base::BindOnce(
[](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
......@@ -263,7 +263,7 @@ void NearbyConnectionsManagerImpl::Send(const std::string& endpoint_id,
RegisterPayloadStatusListener(payload->id, listener);
nearby_connections_->SendPayload(
{endpoint_id}, std::move(payload),
kServiceId, {endpoint_id}, std::move(payload),
base::BindOnce(
[](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
......@@ -300,8 +300,8 @@ void NearbyConnectionsManagerImpl::OnFileCreated(
ConnectionsCallback callback,
NearbyFileHandler::CreateFileResult result) {
nearby_connections_->RegisterPayloadFile(
payload_id, std::move(result.input_file), std::move(result.output_file),
std::move(callback));
kServiceId, payload_id, std::move(result.input_file),
std::move(result.output_file), std::move(callback));
}
NearbyConnectionsManagerImpl::Payload*
......@@ -326,7 +326,7 @@ void NearbyConnectionsManagerImpl::Cancel(int64_t payload_id) {
payload_status_listeners_.erase(it);
}
nearby_connections_->CancelPayload(
payload_id,
kServiceId, payload_id,
base::BindOnce(
[](int64_t payload_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
......@@ -367,7 +367,7 @@ void NearbyConnectionsManagerImpl::UpgradeBandwidth(
return;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_id,
kServiceId, endpoint_id,
base::BindOnce(
[](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
......@@ -452,7 +452,7 @@ void NearbyConnectionsManagerImpl::OnConnectionInitiated(
payload_listener.InitWithNewPipeAndPassReceiver());
nearby_connections_->AcceptConnection(
endpoint_id, std::move(payload_listener),
kServiceId, endpoint_id, std::move(payload_listener),
base::BindOnce(
[](const std::string& endpoint_id, ConnectionsStatus status) {
NS_LOG(VERBOSE)
......@@ -572,7 +572,8 @@ void NearbyConnectionsManagerImpl::OnPayloadTransferUpdate(
if (!payload_it->second->content->is_bytes()) {
NS_LOG(WARNING) << "Received unknown payload of file type. Cancelling.";
nearby_connections_->CancelPayload(payload_it->first, base::DoNothing());
nearby_connections_->CancelPayload(kServiceId, payload_it->first,
base::DoNothing());
return;
}
......@@ -599,7 +600,7 @@ bool NearbyConnectionsManagerImpl::BindNearbyConnections() {
void NearbyConnectionsManagerImpl::Reset() {
if (nearby_connections_) {
nearby_connections_->StopAllEndpoints(
base::BindOnce([](ConnectionsStatus status) {
kServiceId, base::BindOnce([](ConnectionsStatus status) {
NS_LOG(VERBOSE) << __func__
<< ": Stop all endpoints attempted over Nearby "
"Connections with result: "
......
......@@ -26,12 +26,14 @@
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/shared_remote.h"
#include "third_party/nearby/src/cpp/core/core.h"
#include "third_party/nearby/src/cpp/core/internal/service_controller.h"
namespace location {
namespace nearby {
namespace connections {
class Core;
// Implementation of the NearbyConnections mojo interface.
// This class acts as a bridge to the NearbyConnections library which is pulled
// in as a third_party dependency. It handles the translation from mojo calls to
......@@ -50,7 +52,7 @@ class NearbyConnections : public mojom::NearbyConnections {
mojom::NearbyConnectionsDependenciesPtr dependencies,
scoped_refptr<base::SequencedTaskRunner> io_task_runner,
base::OnceClosure on_disconnect,
std::unique_ptr<Core> core = std::make_unique<Core>());
std::unique_ptr<ServiceController> service_controller = nullptr);
NearbyConnections(const NearbyConnections&) = delete;
NearbyConnections& operator=(const NearbyConnections&) = delete;
......@@ -85,41 +87,52 @@ class NearbyConnections : public mojom::NearbyConnections {
// mojom::NearbyConnections:
void StartAdvertising(
const std::vector<uint8_t>& endpoint_info,
const std::string& service_id,
const std::vector<uint8_t>& endpoint_info,
mojom::AdvertisingOptionsPtr options,
mojo::PendingRemote<mojom::ConnectionLifecycleListener> listener,
StartAdvertisingCallback callback) override;
void StopAdvertising(StopAdvertisingCallback callback) override;
void StopAdvertising(const std::string& service_id,
StopAdvertisingCallback callback) override;
void StartDiscovery(
const std::string& service_id,
mojom::DiscoveryOptionsPtr options,
mojo::PendingRemote<mojom::EndpointDiscoveryListener> listener,
StartDiscoveryCallback callback) override;
void StopDiscovery(StopDiscoveryCallback callback) override;
void StopDiscovery(const std::string& service_id,
StopDiscoveryCallback callback) override;
void RequestConnection(
const std::string& service_id,
const std::vector<uint8_t>& endpoint_info,
const std::string& endpoint_id,
mojom::ConnectionOptionsPtr options,
mojo::PendingRemote<mojom::ConnectionLifecycleListener> listener,
RequestConnectionCallback callback) override;
void DisconnectFromEndpoint(const std::string& endpoint_id,
void DisconnectFromEndpoint(const std::string& service_id,
const std::string& endpoint_id,
DisconnectFromEndpointCallback callback) override;
void AcceptConnection(const std::string& endpoint_id,
void AcceptConnection(const std::string& service_id,
const std::string& endpoint_id,
mojo::PendingRemote<mojom::PayloadListener> listener,
AcceptConnectionCallback callback) override;
void RejectConnection(const std::string& endpoint_id,
void RejectConnection(const std::string& service_id,
const std::string& endpoint_id,
RejectConnectionCallback callback) override;
void SendPayload(const std::vector<std::string>& endpoint_ids,
void SendPayload(const std::string& service_id,
const std::vector<std::string>& endpoint_ids,
mojom::PayloadPtr payload,
SendPayloadCallback callback) override;
void CancelPayload(int64_t payload_id,
void CancelPayload(const std::string& service_id,
int64_t payload_id,
CancelPayloadCallback callback) override;
void StopAllEndpoints(StopAllEndpointsCallback callback) override;
void StopAllEndpoints(const std::string& service_id,
StopAllEndpointsCallback callback) override;
void InitiateBandwidthUpgrade(
const std::string& service_id,
const std::string& endpoint_id,
InitiateBandwidthUpgradeCallback callback) override;
void RegisterPayloadFile(int64_t payload_id,
void RegisterPayloadFile(const std::string& service_id,
int64_t payload_id,
base::File input_file,
base::File output_file,
RegisterPayloadFileCallback callback) override;
......@@ -134,6 +147,9 @@ class NearbyConnections : public mojom::NearbyConnections {
scoped_refptr<base::SingleThreadTaskRunner> GetThreadTaskRunner();
private:
Core* GetCore(const std::string& service_id);
void InitializeOfflineServiceController();
void OnDisconnect();
mojo::Receiver<mojom::NearbyConnections> nearby_connections_;
......@@ -148,9 +164,12 @@ class NearbyConnections : public mojom::NearbyConnections {
mojo::SharedRemote<sharing::mojom::WebRtcSignalingMessenger>
webrtc_signaling_messenger_;
// Core is thread-safe as its operations are always dispatched to a
// single-thread executor.
std::unique_ptr<Core> core_;
std::unique_ptr<ServiceController> service_controller_;
// Map from service ID to the Core object to be used for that service. Each
// service uses its own Core object, but all Core objects share the underlying
// ServiceController instance.
base::flat_map<std::string, std::unique_ptr<Core>> service_id_to_core_map_;
// input_file_map_ is accessed from background threads.
base::Lock input_file_lock_;
......
......@@ -186,16 +186,15 @@ class NearbyConnectionsTest : public testing::Test {
auto dependencies = mojom::NearbyConnectionsDependencies::New(
bluetooth_adapter_.adapter_.BindNewPipeAndPassRemote(),
std::move(webrtc_dependencies));
service_controller_ =
auto service_controller =
std::make_unique<testing::NiceMock<MockServiceController>>();
service_controller_ptr_ = service_controller_.get();
service_controller_ptr_ = service_controller.get();
nearby_connections_ = std::make_unique<NearbyConnections>(
remote_.BindNewPipeAndPassReceiver(), std::move(dependencies),
/*io_task_runner=*/nullptr,
base::BindOnce(&NearbyConnectionsTest::OnDisconnect,
base::Unretained(this)),
std::make_unique<Core>(
[&]() { return service_controller_.release(); }));
std::move(service_controller));
}
void OnDisconnect() { disconnect_run_loop_.Quit(); }
......@@ -278,7 +277,7 @@ class NearbyConnectionsTest : public testing::Test {
base::RunLoop start_advertising_run_loop;
nearby_connections_->StartAdvertising(
endpoint_info, kServiceId, CreateAdvertisingOptions(),
kServiceId, endpoint_info, CreateAdvertisingOptions(),
fake_connection_life_cycle_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
......@@ -328,7 +327,7 @@ class NearbyConnectionsTest : public testing::Test {
base::RunLoop request_connection_run_loop;
nearby_connections_->RequestConnection(
endpoint_info, endpoint_data.remote_endpoint_id,
kServiceId, endpoint_info, endpoint_data.remote_endpoint_id,
CreateConnectionOptions(bluetooth_mac_address),
fake_connection_life_cycle_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
......@@ -356,7 +355,7 @@ class NearbyConnectionsTest : public testing::Test {
base::RunLoop accept_connection_run_loop;
nearby_connections_->AcceptConnection(
remote_endpoint_id,
kServiceId, remote_endpoint_id,
fake_payload_listener.receiver.BindNewPipeAndPassRemote(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
......@@ -375,9 +374,6 @@ class NearbyConnectionsTest : public testing::Test {
std::unique_ptr<NearbyConnections> nearby_connections_;
testing::NiceMock<MockServiceController>* service_controller_ptr_;
base::RunLoop disconnect_run_loop_;
private:
std::unique_ptr<testing::NiceMock<MockServiceController>> service_controller_;
};
TEST_F(NearbyConnectionsTest, RemoteDisconnect) {
......@@ -449,7 +445,7 @@ TEST_F(NearbyConnectionsTest, StopDiscovery) {
base::RunLoop stop_discovery_run_loop;
nearby_connections_->StopDiscovery(
base::BindLambdaForTesting([&](mojom::Status status) {
kServiceId, base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
stop_discovery_run_loop.Quit();
}));
......@@ -588,7 +584,7 @@ TEST_F(NearbyConnectionsTest, RequestConnectionOnBandwidthUpgrade) {
});
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
bandwidth_upgrade_run_loop.Quit();
......@@ -657,7 +653,7 @@ TEST_F(NearbyConnectionsTest, RequestConnectionDisconnect) {
base::RunLoop disconnect_from_endpoint_run_loop;
nearby_connections_->DisconnectFromEndpoint(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
disconnect_from_endpoint_run_loop.Quit();
......@@ -725,7 +721,7 @@ TEST_F(NearbyConnectionsTest, SendBytesPayload) {
base::RunLoop send_payload_run_loop;
nearby_connections_->SendPayload(
{endpoint_data.remote_endpoint_id},
kServiceId, {endpoint_data.remote_endpoint_id},
mojom::Payload::New(kPayloadId,
mojom::PayloadContent::NewBytes(
mojom::BytesPayload::New(expected_payload))),
......@@ -769,7 +765,7 @@ TEST_F(NearbyConnectionsTest, SendBytesPayloadCancelled) {
base::RunLoop send_payload_run_loop;
nearby_connections_->SendPayload(
{endpoint_data.remote_endpoint_id},
kServiceId, {endpoint_data.remote_endpoint_id},
mojom::Payload::New(kPayloadId,
mojom::PayloadContent::NewBytes(
mojom::BytesPayload::New(expected_payload))),
......@@ -785,7 +781,8 @@ TEST_F(NearbyConnectionsTest, SendBytesPayloadCancelled) {
base::RunLoop cancel_payload_run_loop;
nearby_connections_->CancelPayload(
kPayloadId, base::BindLambdaForTesting([&](mojom::Status status) {
kServiceId, kPayloadId,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
cancel_payload_run_loop.Quit();
}));
......@@ -840,7 +837,7 @@ TEST_F(NearbyConnectionsTest, SendFilePayload) {
base::RunLoop send_payload_run_loop;
nearby_connections_->SendPayload(
{endpoint_data.remote_endpoint_id},
kServiceId, {endpoint_data.remote_endpoint_id},
mojom::Payload::New(kPayloadId,
mojom::PayloadContent::NewFile(
mojom::FilePayload::New(std::move(input_file)))),
......@@ -928,7 +925,7 @@ TEST_F(NearbyConnectionsTest, StopAdvertising) {
base::RunLoop stop_advertising_run_loop;
nearby_connections_->StopAdvertising(
base::BindLambdaForTesting([&](mojom::Status status) {
kServiceId, base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
stop_advertising_run_loop.Quit();
}));
......@@ -983,7 +980,7 @@ TEST_F(NearbyConnectionsTest, DisconnectAllEndpoints) {
base::RunLoop stop_endpoints_run_loop;
nearby_connections_->StopAllEndpoints(
base::BindLambdaForTesting([&](mojom::Status status) {
kServiceId, base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
stop_endpoints_run_loop.Quit();
}));
......@@ -1000,7 +997,7 @@ TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeFails) {
EndpointData endpoint_data = CreateEndpointData(1);
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
......@@ -1020,7 +1017,7 @@ TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterDiscoveringFails) {
// Requesting a bandwidth upgrade should fail.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
......@@ -1037,7 +1034,7 @@ TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterAdvertisingFails) {
// Requesting a bandwidth upgrade should fail.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kOutOfOrderApiCall, status);
bandwidth_upgrade_run_loop.Quit();
......@@ -1066,7 +1063,7 @@ TEST_F(NearbyConnectionsTest, InitiateBandwidthUpgradeAfterConnectionSucceeds) {
// Requesting a bandwidth upgrade should succeed.
base::RunLoop bandwidth_upgrade_run_loop;
nearby_connections_->InitiateBandwidthUpgrade(
endpoint_data.remote_endpoint_id,
kServiceId, endpoint_data.remote_endpoint_id,
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
bandwidth_upgrade_run_loop.Quit();
......@@ -1139,7 +1136,7 @@ TEST_F(NearbyConnectionsTest, ReceiveFilePayload) {
base::RunLoop register_payload_run_loop;
nearby_connections_->RegisterPayloadFile(
kPayloadId, std::move(input_file), std::move(output_file),
kServiceId, kPayloadId, std::move(input_file), std::move(output_file),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kSuccess, status);
register_payload_run_loop.Quit();
......@@ -1217,7 +1214,7 @@ TEST_F(NearbyConnectionsTest, ReceiveFilePayloadNotRegistered) {
TEST_F(NearbyConnectionsTest, RegisterPayloadFileInvalid) {
base::RunLoop register_payload_run_loop;
nearby_connections_->RegisterPayloadFile(
kPayloadId, base::File(), base::File(),
kServiceId, kPayloadId, base::File(), base::File(),
base::BindLambdaForTesting([&](mojom::Status status) {
EXPECT_EQ(mojom::Status::kError, status);
register_payload_run_loop.Quit();
......
......@@ -44,13 +44,16 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
MOCK_METHOD(void,
StartAdvertising,
(const std::vector<uint8_t>& endpoint_info,
const std::string& service_id,
(const std::string& service_id,
const std::vector<uint8_t>& endpoint_info,
AdvertisingOptionsPtr,
mojo::PendingRemote<ConnectionLifecycleListener>,
StartDiscoveryCallback),
(override));
MOCK_METHOD(void, StopAdvertising, (StopAdvertisingCallback), (override));
MOCK_METHOD(void,
StopAdvertising,
(const std::string& service_id, StopAdvertisingCallback),
(override));
MOCK_METHOD(void,
StartDiscovery,
(const std::string& service_id,
......@@ -58,10 +61,14 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
mojo::PendingRemote<EndpointDiscoveryListener>,
StartDiscoveryCallback),
(override));
MOCK_METHOD(void, StopDiscovery, (StopDiscoveryCallback), (override));
MOCK_METHOD(void,
StopDiscovery,
(const std::string& service_id, StopDiscoveryCallback),
(override));
MOCK_METHOD(void,
RequestConnection,
(const std::vector<uint8_t>& endpoint_info,
(const std::string& service_id,
const std::vector<uint8_t>& endpoint_info,
const std::string& endpoint_id,
ConnectionOptionsPtr options,
mojo::PendingRemote<ConnectionLifecycleListener>,
......@@ -69,41 +76,51 @@ class MockNearbyConnections : public NearbyConnectionsMojom {
(override));
MOCK_METHOD(void,
DisconnectFromEndpoint,
(const std::string& endpoint_id, DisconnectFromEndpointCallback),
(const std::string& service_id,
const std::string& endpoint_id,
DisconnectFromEndpointCallback),
(override));
MOCK_METHOD(void,
AcceptConnection,
(const std::string& endpoint_id,
(const std::string& service_id,
const std::string& endpoint_id,
mojo::PendingRemote<PayloadListener> listener,
AcceptConnectionCallback callback),
(override));
MOCK_METHOD(void,
RejectConnection,
(const std::string& endpoint_id,
(const std::string& service_id,
const std::string& endpoint_id,
RejectConnectionCallback callback),
(override));
MOCK_METHOD(void,
SendPayload,
(const std::vector<std::string>& endpoint_ids,
(const std::string& service_id,
const std::vector<std::string>& endpoint_ids,
PayloadPtr payload,
SendPayloadCallback callback),
(override));
MOCK_METHOD(void,
CancelPayload,
(int64_t payload_id, CancelPayloadCallback callback),
(const std::string& service_id,
int64_t payload_id,
CancelPayloadCallback callback),
(override));
MOCK_METHOD(void,
StopAllEndpoints,
(DisconnectFromEndpointCallback callback),
(const std::string& service_id,
DisconnectFromEndpointCallback callback),
(override));
MOCK_METHOD(void,
InitiateBandwidthUpgrade,
(const std::string& endpoint_id,
(const std::string& service_id,
const std::string& endpoint_id,
InitiateBandwidthUpgradeCallback callback),
(override));
MOCK_METHOD(void,
RegisterPayloadFile,
(int64_t payload_id,
(const std::string& service_id,
int64_t payload_id,
base::File input_file,
base::File output_file,
RegisterPayloadFileCallback callback),
......
......@@ -127,13 +127,13 @@ interface NearbyConnections {
// advertisement can be active at a time and calling StartAdvertising() while
// advertising will fail and return Status::kAlreadyAdvertising.
//
// endpoint_info - The local info to be broadcasted. May contain a human
// readable name to appear on other devices if broadcasting
// in high visibility mode.
// service_id - An identifier to advertise your app to other endpoints.
// This can be an arbitrary string, so long as it uniquely
// identifies your service. A good default is to use your
// app's package name.
// endpoint_info - The local info to be broadcasted. May contain a human
// readable name to appear on other devices if broadcasting
// in high visibility mode.
// options - The options for advertising.
// listener - An interface notified when remote endpoints request a
// connection to this endpoint.
......@@ -142,7 +142,7 @@ interface NearbyConnections {
// Status::kAlreadyAdvertising if the app is already advertising.
// Status::kOutOfOrderApiCall if the app is currently connected to remote
// endpoints; call StopAllEndpoints first.
StartAdvertising(array<uint8> endpoint_info, string service_id,
StartAdvertising(string service_id, array<uint8> endpoint_info,
AdvertisingOptions options,
pending_remote<ConnectionLifecycleListener> listener)
=> (Status status);
......@@ -152,9 +152,11 @@ interface NearbyConnections {
// itself or goes inactive. Payloads can still be sent to connected
// endpoints after advertising ends.
//
// service_id - Identifier used in the preceding StartAdvertising() call.
//
// Possible return values include:
// Status::kSuccess returned after advertising got stopped.
StopAdvertising() => (Status status);
StopAdvertising(string service_id) => (Status status);
// Starts discovery for remote endpoints with the specified service ID.
//
......@@ -177,12 +179,15 @@ interface NearbyConnections {
// goes inactive. Payloads can still be sent to connected endpoints after
// discovery ends.
//
// service_id - Identifier used in the preceding StartDiscovery() call.
//
// Possible return values include:
// Status::kSuccess returned after discovery got stopped.
StopDiscovery() => (Status status);
StopDiscovery(string service_id) => (Status status);
// Sends a request to connect to a remote endpoint.
//
// service_id - Service ID used to discover the endpoint.
// endpoint_info - The local info including a human readable name to appear on
// the remote endpoint.
// endpoint_id - The identifier for the remote endpoint to which a
......@@ -201,7 +206,9 @@ interface NearbyConnections {
// Status::kWifiLanError if we failed to connect because of an
// issue with WiFi.
// Status::kError if we failed to connect for any other reason.
RequestConnection(array<uint8> endpoint_info, string endpoint_id,
RequestConnection(string service_id,
array<uint8> endpoint_info,
string endpoint_id,
ConnectionOptions options,
pending_remote<ConnectionLifecycleListener> listener)
=> (Status status);
......@@ -209,6 +216,7 @@ interface NearbyConnections {
// Accepts a connection to a remote endpoint. This method must be called
// before Payloads can be exchanged with the remote endpoint.
//
// service_id - Service ID used to bootstrap the connection.
// endpoint_id - The identifier for the remote endpoint. Should match the
// value provided in a call to
// ConnectionsLifecycleListener::OnConnectionInitiated().
......@@ -220,11 +228,14 @@ interface NearbyConnections {
// Status::kOutOfOrderApiCall if
// ConnectionsLifecycleListener::OnConnectionInitiated() has not been
// called for the |endpoint_id|.
AcceptConnection(string endpoint_id, pending_remote<PayloadListener> listener)
AcceptConnection(string service_id,
string endpoint_id,
pending_remote<PayloadListener> listener)
=> (Status status);
// Rejects a connection to a remote endpoint.
//
// service_id - Service ID used to bootstrap the connection.
// endpoint_id - The identifier for the remote endpoint. Should match the
// value provided in a call to
// ConnectionsLifecycleListener::OnConnectionInitiated().
......@@ -235,20 +246,23 @@ interface NearbyConnections {
// Status::kOutOfOrderApiCall if
// ConnectionsLifecycleListener::OnConnectionInitiated() has not been
// called for the |endpoint_id|.
RejectConnection(string endpoint_id) => (Status status);
RejectConnection(string service_id, string endpoint_id) => (Status status);
// Disconnects from a remote endpoint. Payloads can no longer be sent
// to or received from the endpoint after this method is called.
//
// service_id - Service ID used to bootstrap the connection.
// endpoint_id - The identifier for the remote endpoint to disconnect from.
// Possible return values include:
// Status::kSuccess disconnected successfully.
DisconnectFromEndpoint(string endpoint_id) => (Status status);
DisconnectFromEndpoint(string service_id,
string endpoint_id) => (Status status);
// Sends a Payload to a list of remote endpoints. Payloads can only be sent to
// remote endpoints once a notice of connection acceptance has been delivered
// via ConnectionsLifecycleListener::OnConnectionResult().
//
// service_id - Service ID used to bootstrap the connection.
// endpoint_ids - Array of remote endpoint identifiers for to which the
// payload should be sent.
// payload - The Payload to be sent.
......@@ -263,14 +277,18 @@ interface NearbyConnections {
// still occur during transmission (and at different times for different
// endpoints), and will be delivered via
// PayloadListener::OnPayloadTransferUpdate().
SendPayload(array<string> endpoint_ids, Payload payload) => (Status status);
SendPayload(string service_id,
array<string> endpoint_ids,
Payload payload) => (Status status);
// Cancels a Payload currently in-flight to or from remote endpoint(s).
//
// service_id - Service ID used to bootstrap the connection.
//
// payload_id - The identifier for the Payload to be cancelled.
// Possible return values include:
// Status::kSuccess if the payload got cancelled.
CancelPayload(int64 payload_id) => (Status status);
CancelPayload(string service_id, int64 payload_id) => (Status status);
// Disconnects from, and removes all traces of, all connected and/or
// discovered endpoints. As a side effect of this call, both
......@@ -278,28 +296,37 @@ interface NearbyConnections {
// StopAllEndpoints, no further operations with remote endpoints will
// be possible until a new call to one of StartAdvertising or
// StartDiscovery.
//
// service_id - Service ID used to discover endpoints.
//
// Possible return values include:
// Status::kSuccess disconnected from all endpoints successfully.
StopAllEndpoints() => (Status status);
StopAllEndpoints(string service_id) => (Status status);
// Sends a request to initiate connection bandwidth upgrade.
//
// service_id - Service ID used to discover the endpoint.
// endpoint_id - The identifier for the remote endpoint which will be
// switching to a higher connection data rate and possibly
// different wireless protocol. On success, calls
// ConnectionLifecycleListener::OnBandwidthChanged.
// Possible return values include:
// Status::kSuccess if upgraded successfully.
InitiateBandwidthUpgrade(string endpoint_id) => (Status status);
InitiateBandwidthUpgrade(string service_id,
string endpoint_id) => (Status status);
// Register a pair of input and output file for handling incoming file
// payload associated with |payload_id_|, which is determined by feature
// specific design. The |input_file| should be opened for read access, and
// |output_file| should be opened for write access.
//
// service_id - Service ID used to discover the endpoint.
//
// Possible return values include:
// Status::kSuccess if file is registered successfully.
// Status::kError if file is not opened correctly.
RegisterPayloadFile(int64 payload_id,
RegisterPayloadFile(string service_id,
int64 payload_id,
mojo_base.mojom.ReadOnlyFile input_file,
mojo_base.mojom.File output_file)
=> (Status status);
......
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