Commit 0aa4b42f authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS PhoneHub] Create chromeos::secure_channel::NearbyConnector

This class is implemented as a KeyedService and provides an interface
that the SecureChannel service can use to make connection requests over
the Nearby Connections library. It will be used by SecureChannel to make
connection requests on behalf of Phone Hub.

Bug: 1106937
Change-Id: Ie624c874ef4eeff65f417b89d6d48a90a63ae1cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2496289
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825001}
parent e06c7f41
......@@ -2605,6 +2605,10 @@ source_set("chromeos") {
"secure_channel/nearby_connection_broker.h",
"secure_channel/nearby_connection_broker_impl.cc",
"secure_channel/nearby_connection_broker_impl.h",
"secure_channel/nearby_connector_factory.cc",
"secure_channel/nearby_connector_factory.h",
"secure_channel/nearby_connector_impl.cc",
"secure_channel/nearby_connector_impl.h",
"secure_channel/nearby_endpoint_finder.cc",
"secure_channel/nearby_endpoint_finder.h",
"secure_channel/nearby_endpoint_finder_impl.cc",
......@@ -3777,6 +3781,7 @@ source_set("unit_tests") {
"scanning/zeroconf_scanner_detector_unittest.cc",
"scheduler_configuration_manager_unittest.cc",
"secure_channel/nearby_connection_broker_impl_unittest.cc",
"secure_channel/nearby_connector_impl_unittest.cc",
"secure_channel/nearby_endpoint_finder_impl_unittest.cc",
"session_length_limiter_unittest.cc",
"settings/cros_settings_unittest.cc",
......
......@@ -36,6 +36,7 @@
#include "chrome/browser/chromeos/printing/history/print_job_history_service_factory.h"
#include "chrome/browser/chromeos/printing/print_management/printing_manager_factory.h"
#include "chrome/browser/chromeos/printing/synced_printers_manager_factory.h"
#include "chrome/browser/chromeos/secure_channel/nearby_connector_factory.h"
#include "chrome/browser/chromeos/smb_client/smb_service_factory.h"
#include "chrome/browser/chromeos/tether/tether_service_factory.h"
#include "chrome/browser/chromeos/web_applications/crosh_loader_factory.h"
......@@ -89,6 +90,7 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
policy::UserNetworkConfigurationUpdaterFactory::GetInstance();
printing::print_management::PrintingManagerFactory::GetInstance();
PrintJobHistoryServiceFactory::GetInstance();
secure_channel::NearbyConnectorFactory::GetInstance();
smb_client::SmbServiceFactory::GetInstance();
SyncedPrintersManagerFactory::GetInstance();
TetherServiceFactory::GetInstance();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/secure_channel/nearby_connector_factory.h"
#include "chrome/browser/chromeos/nearby/nearby_process_manager_factory.h"
#include "chrome/browser/chromeos/secure_channel/nearby_connector_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace chromeos {
namespace secure_channel {
// static
NearbyConnector* NearbyConnectorFactory::GetForProfile(Profile* profile) {
return static_cast<NearbyConnectorImpl*>(
NearbyConnectorFactory::GetInstance()->GetServiceForBrowserContext(
profile, /*create=*/true));
}
// static
NearbyConnectorFactory* NearbyConnectorFactory::GetInstance() {
return base::Singleton<NearbyConnectorFactory>::get();
}
NearbyConnectorFactory::NearbyConnectorFactory()
: BrowserContextKeyedServiceFactory(
"NearbyConnector",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(nearby::NearbyProcessManagerFactory::GetInstance());
}
NearbyConnectorFactory::~NearbyConnectorFactory() = default;
KeyedService* NearbyConnectorFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
nearby::NearbyProcessManager* nearby_process_manager =
nearby::NearbyProcessManagerFactory::GetForProfile(
Profile::FromBrowserContext(context));
// If null, control of the Nearby utility process is not supported for this
// profile.
if (!nearby_process_manager)
return nullptr;
return new NearbyConnectorImpl(nearby_process_manager);
}
bool NearbyConnectorFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
} // namespace secure_channel
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_FACTORY_H_
#define CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_FACTORY_H_
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
class Profile;
namespace chromeos {
namespace secure_channel {
class NearbyConnector;
class NearbyConnectorFactory : public BrowserContextKeyedServiceFactory {
public:
static NearbyConnector* GetForProfile(Profile* profile);
static NearbyConnectorFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<NearbyConnectorFactory>;
NearbyConnectorFactory();
NearbyConnectorFactory(const NearbyConnectorFactory&) = delete;
NearbyConnectorFactory& operator=(const NearbyConnectorFactory&) = delete;
~NearbyConnectorFactory() override;
// BrowserContextKeyedServiceFactory:
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
};
} // namespace secure_channel
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_FACTORY_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/secure_channel/nearby_connector_impl.h"
#include "base/bind.h"
#include "chrome/browser/chromeos/secure_channel/nearby_connection_broker_impl.h"
#include "chrome/browser/chromeos/secure_channel/nearby_endpoint_finder_impl.h"
#include "chromeos/components/multidevice/logging/logging.h"
#include "chromeos/services/nearby/public/cpp/nearby_process_manager.h"
#include "chromeos/services/secure_channel/public/cpp/client/nearby_connector.h"
#include "components/keyed_service/core/keyed_service.h"
namespace chromeos {
namespace secure_channel {
NearbyConnectorImpl::ConnectionRequestMetadata::ConnectionRequestMetadata(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback)
: bluetooth_public_address(bluetooth_public_address),
message_receiver(std::move(message_receiver)),
callback(std::move(callback)) {}
NearbyConnectorImpl::ConnectionRequestMetadata::~ConnectionRequestMetadata() =
default;
NearbyConnectorImpl::ActiveConnectionAttempt::ActiveConnectionAttempt(
const base::UnguessableToken& attempt_id,
std::unique_ptr<NearbyEndpointFinder> endpoint_finder,
ConnectCallback callback)
: attempt_id(attempt_id),
endpoint_finder(std::move(endpoint_finder)),
callback(std::move(callback)) {}
NearbyConnectorImpl::ActiveConnectionAttempt::~ActiveConnectionAttempt() =
default;
NearbyConnectorImpl::NearbyConnectorImpl(
nearby::NearbyProcessManager* nearby_process_manager)
: nearby_process_manager_(nearby_process_manager) {}
NearbyConnectorImpl::~NearbyConnectorImpl() = default;
void NearbyConnectorImpl::Connect(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback) {
queued_connection_requests_.emplace(
std::make_unique<ConnectionRequestMetadata>(bluetooth_public_address,
std::move(message_receiver),
std::move(callback)));
ProcessQueuedConnectionRequests();
}
void NearbyConnectorImpl::Shutdown() {
nearby_process_manager_ = nullptr;
ClearActiveAndPendingConnections();
}
void NearbyConnectorImpl::ClearActiveAndPendingConnections() {
if (active_connection_attempt_) {
InvokeActiveConnectionAttemptCallback(mojo::NullRemote());
active_connection_attempt_.reset();
}
id_to_brokers_map_.clear();
process_reference_.reset();
}
void NearbyConnectorImpl::ProcessQueuedConnectionRequests() {
// Shutdown() has been called, so no further connection requests should be
// attempted.
if (!nearby_process_manager_)
return;
// No queued requests; nothing to do.
if (queued_connection_requests_.empty())
return;
// Only one connection can be requested at a time.
if (active_connection_attempt_)
return;
// If there is no currently-held process reference, request one. This ensures
// that the Nearby utility process is running.
if (!process_reference_) {
PA_LOG(VERBOSE) << "Obtaining Nearby process reference";
process_reference_ = nearby_process_manager_->GetNearbyProcessReference(
base::BindOnce(&NearbyConnectorImpl::OnNearbyProcessStopped,
weak_ptr_factory_.GetWeakPtr()));
if (!process_reference_) {
PA_LOG(WARNING) << "Could not obtain Nearby process reference";
return;
}
}
// Remove the request from the front of the queue.
std::unique_ptr<ConnectionRequestMetadata> metadata =
std::move(queued_connection_requests_.front());
queued_connection_requests_.pop();
auto new_broker_id = base::UnguessableToken::Create();
mojo::PendingRemote<mojom::NearbyMessageSender> message_sender_pending_remote;
mojo::PendingReceiver<mojom::NearbyMessageSender>
message_sender_pending_receiver =
message_sender_pending_remote.InitWithNewPipeAndPassReceiver();
DCHECK(!active_connection_attempt_);
active_connection_attempt_.emplace(
new_broker_id,
NearbyEndpointFinderImpl::Factory::Create(
process_reference_->GetNearbyConnections()),
std::move(metadata->callback));
id_to_brokers_map_[new_broker_id] =
NearbyConnectionBrokerImpl::Factory::Create(
metadata->bluetooth_public_address,
active_connection_attempt_->endpoint_finder.get(),
std::move(message_sender_pending_receiver),
std::move(metadata->message_receiver),
process_reference_->GetNearbyConnections(),
base::BindOnce(&NearbyConnectorImpl::OnConnected,
base::Unretained(this), new_broker_id,
std::move(message_sender_pending_remote)),
base::BindOnce(&NearbyConnectorImpl::OnDisconnected,
base::Unretained(this), new_broker_id));
}
void NearbyConnectorImpl::OnNearbyProcessStopped() {
ClearActiveAndPendingConnections();
ProcessQueuedConnectionRequests();
}
void NearbyConnectorImpl::OnConnected(
const base::UnguessableToken& id,
mojo::PendingRemote<mojom::NearbyMessageSender>
message_sender_pending_remote) {
DCHECK_EQ(active_connection_attempt_->attempt_id, id);
InvokeActiveConnectionAttemptCallback(
std::move(message_sender_pending_remote));
active_connection_attempt_.reset();
ProcessQueuedConnectionRequests();
}
void NearbyConnectorImpl::OnDisconnected(const base::UnguessableToken& id) {
// If the pending connection could not complete, invoke the callback with an
// unbound PendingRemote.
if (active_connection_attempt_ &&
active_connection_attempt_->attempt_id == id) {
InvokeActiveConnectionAttemptCallback(mojo::NullRemote());
active_connection_attempt_.reset();
}
id_to_brokers_map_.erase(id);
// If this disconnection corresponds to the last active broker, release the
// process reference so that the Nearby utility process can shut down if
// applicable.
if (id_to_brokers_map_.empty()) {
PA_LOG(VERBOSE) << "Releasing Nearby process reference";
process_reference_.reset();
return;
}
ProcessQueuedConnectionRequests();
}
void NearbyConnectorImpl::InvokeActiveConnectionAttemptCallback(
mojo::PendingRemote<mojom::NearbyMessageSender>
message_sender_pending_remote) {
std::move(active_connection_attempt_->callback)
.Run(std::move(message_sender_pending_remote));
}
} // namespace secure_channel
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_IMPL_H_
#define CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_IMPL_H_
#include <memory>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/containers/queue.h"
#include "base/memory/weak_ptr.h"
#include "base/unguessable_token.h"
#include "chromeos/services/nearby/public/cpp/nearby_process_manager.h"
#include "chromeos/services/secure_channel/public/cpp/client/nearby_connector.h"
#include "components/keyed_service/core/keyed_service.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace chromeos {
namespace secure_channel {
class NearbyConnectionBroker;
class NearbyEndpointFinder;
// NearbyConnector implementation which uses NearbyProcessManager to interact
// with Nearby Connections. When a connection is requested, NearbyConnectorImpl
// obtains a reference to the Nearby utility process, and when no requests are
// active, the class releases its reference.
//
// Because only one NearbyEndpointFinder is meant to be used at a time,
// connections are connected in a queue; once one connection has been
// established, it is possible for a new one to be requested. The class
// assigns an ID to each connection and holds a reference to a
// NearbyConnectionBroker for each one.
class NearbyConnectorImpl : public NearbyConnector, public KeyedService {
public:
explicit NearbyConnectorImpl(
nearby::NearbyProcessManager* nearby_process_manager);
~NearbyConnectorImpl() override;
private:
struct ConnectionRequestMetadata {
ConnectionRequestMetadata(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback);
ConnectionRequestMetadata(const ConnectionRequestMetadata&) = delete;
ConnectionRequestMetadata& operator=(const ConnectionRequestMetadata&) =
delete;
~ConnectionRequestMetadata();
std::vector<uint8_t> bluetooth_public_address;
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver;
ConnectCallback callback;
};
struct ActiveConnectionAttempt {
ActiveConnectionAttempt(
const base::UnguessableToken& attempt_id,
std::unique_ptr<NearbyEndpointFinder> endpoint_finder,
ConnectCallback callback);
~ActiveConnectionAttempt();
base::UnguessableToken attempt_id;
std::unique_ptr<NearbyEndpointFinder> endpoint_finder;
ConnectCallback callback;
};
/// mojom::NearbyConnector:
void Connect(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback) override;
// KeyedService:
void Shutdown() override;
void ClearActiveAndPendingConnections();
void ProcessQueuedConnectionRequests();
void OnNearbyProcessStopped();
void OnConnected(const base::UnguessableToken& id,
mojo::PendingRemote<mojom::NearbyMessageSender>
message_sender_pending_remote);
void OnDisconnected(const base::UnguessableToken& id);
void InvokeActiveConnectionAttemptCallback(
mojo::PendingRemote<mojom::NearbyMessageSender>
message_sender_pending_remote);
nearby::NearbyProcessManager* nearby_process_manager_;
// Reference to the Nearby utility process; null if we have not requested a
// connection to the process (i.e., when there are no active connection
// requests).
std::unique_ptr<nearby::NearbyProcessManager::NearbyProcessReference>
process_reference_;
// Metadata for connection requests which are planned but not yet started.
base::queue<std::unique_ptr<ConnectionRequestMetadata>>
queued_connection_requests_;
// Active connection brokers, which delegate messages between Nearby
// Connections and SecureChannel. This map can contain at most one broker
// which is in the process of connecting and any number of active connections.
// If a broker is currently pending a connection, its ID is stored in
// |broker_id_pending_connection_|.
base::flat_map<base::UnguessableToken,
std::unique_ptr<NearbyConnectionBroker>>
id_to_brokers_map_;
// Metadata for an ongoing connection attempt. If this field is set, it means
// that the entry in |id_to_brokers_map_| with the given ID is currently
// attempting a connection. If null, there is no pending connection attempt.
base::Optional<ActiveConnectionAttempt> active_connection_attempt_;
base::WeakPtrFactory<NearbyConnectorImpl> weak_ptr_factory_{this};
};
} // namespace secure_channel
} // namespace chromeos
#endif // CHROME_BROWSER_CHROMEOS_SECURE_CHANNEL_NEARBY_CONNECTOR_IMPL_H_
......@@ -12,6 +12,8 @@ source_set("client") {
"connection_attempt.h",
"connection_attempt_impl.cc",
"connection_attempt_impl.h",
"nearby_connector.cc",
"nearby_connector.h",
"secure_channel_client.h",
"secure_channel_client_impl.cc",
"secure_channel_client_impl.h",
......@@ -36,6 +38,8 @@ static_library("test_support") {
"fake_client_channel_observer.h",
"fake_connection_attempt.cc",
"fake_connection_attempt.h",
"fake_nearby_connector.cc",
"fake_nearby_connector.h",
"fake_secure_channel_client.cc",
"fake_secure_channel_client.h",
]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/services/secure_channel/public/cpp/client/fake_nearby_connector.h"
namespace chromeos {
namespace secure_channel {
FakeNearbyConnector::FakeConnection::FakeConnection(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingReceiver<mojom::NearbyMessageSender>
message_sender_pending_receiver,
mojo::PendingRemote<mojom::NearbyMessageReceiver>
message_receiver_pending_remote)
: bluetooth_public_address_(bluetooth_public_address),
message_sender_receiver_(this,
std::move(message_sender_pending_receiver)),
message_receiver_remote_(std::move(message_receiver_pending_remote)) {}
FakeNearbyConnector::FakeConnection::~FakeConnection() = default;
void FakeNearbyConnector::FakeConnection::Disconnect() {
message_sender_receiver_.reset();
message_receiver_remote_.reset();
}
void FakeNearbyConnector::FakeConnection::ReceiveMessage(
const std::string& message) {
message_receiver_remote_->OnMessageReceived(message);
}
void FakeNearbyConnector::FakeConnection::SendMessage(
const std::string& message,
SendMessageCallback callback) {
sent_messages_.push_back(message);
std::move(callback).Run(should_send_succeed_);
}
FakeNearbyConnector::ConnectArgs::ConnectArgs(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback)
: bluetooth_public_address(bluetooth_public_address),
message_receiver(std::move(message_receiver)),
callback(std::move(callback)) {}
FakeNearbyConnector::ConnectArgs::~ConnectArgs() = default;
FakeNearbyConnector::FakeNearbyConnector() = default;
FakeNearbyConnector::~FakeNearbyConnector() = default;
void FakeNearbyConnector::FailQueuedCallback() {
DCHECK(!queued_connect_args_.empty());
std::move(queued_connect_args_.front()->callback).Run(mojo::NullRemote());
queued_connect_args_.pop();
}
FakeNearbyConnector::FakeConnection*
FakeNearbyConnector::ConnectQueuedCallback() {
DCHECK(!queued_connect_args_.empty());
mojo::PendingRemote<mojom::NearbyMessageSender> message_sender_pending_remote;
mojo::PendingReceiver<mojom::NearbyMessageSender>
message_sender_pending_receiver =
message_sender_pending_remote.InitWithNewPipeAndPassReceiver();
auto fake_connection = std::make_unique<FakeConnection>(
queued_connect_args_.front()->bluetooth_public_address,
std::move(message_sender_pending_receiver),
std::move(queued_connect_args_.front()->message_receiver));
std::move(queued_connect_args_.front()->callback)
.Run(std::move(message_sender_pending_remote));
queued_connect_args_.pop();
FakeConnection* fake_connection_ptr = fake_connection.get();
fake_connections_.emplace_back(std::move(fake_connection));
return fake_connection_ptr;
}
void FakeNearbyConnector::Connect(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback) {
queued_connect_args_.emplace(std::make_unique<ConnectArgs>(
bluetooth_public_address, std::move(message_receiver),
std::move(callback)));
std::move(on_connect_closure).Run();
}
} // namespace secure_channel
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_FAKE_NEARBY_CONNECTOR_H_
#define CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_FAKE_NEARBY_CONNECTOR_H_
#include <memory>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/containers/queue.h"
#include "chromeos/services/secure_channel/public/cpp/client/nearby_connector.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace chromeos {
namespace secure_channel {
// Fake NearbyConnector implementation. When Connect() is called, parameters are
// queued up and can be completed using either FailQueuedCallback() or
// ConnectQueuedCallback(). Both of these functions take the parameters at the
// front of the queue and either cause the connection to fail or succeed. In the
// success case, a FakeConnection is returned which allows the client to
// interact with the connection.
class FakeNearbyConnector : public NearbyConnector {
public:
FakeNearbyConnector();
~FakeNearbyConnector() override;
class FakeConnection : public mojom::NearbyMessageSender {
public:
FakeConnection(const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingReceiver<mojom::NearbyMessageSender>
message_sender_pending_receiver,
mojo::PendingRemote<mojom::NearbyMessageReceiver>
message_receiver_pending_remote);
~FakeConnection() override;
void Disconnect();
void ReceiveMessage(const std::string& message);
void set_should_send_succeed(bool should_send_succeed) {
should_send_succeed_ = should_send_succeed;
}
const std::vector<uint8_t>& bluetooth_public_address() const {
return bluetooth_public_address_;
}
const std::vector<std::string>& sent_messages() { return sent_messages_; }
private:
// mojom::NearbyMessageSender:
void SendMessage(const std::string& message,
SendMessageCallback callback) override;
std::vector<uint8_t> bluetooth_public_address_;
mojo::Receiver<mojom::NearbyMessageSender> message_sender_receiver_;
mojo::Remote<mojom::NearbyMessageReceiver> message_receiver_remote_;
std::vector<std::string> sent_messages_;
bool should_send_succeed_ = true;
};
void FailQueuedCallback();
FakeConnection* ConnectQueuedCallback();
// Invoked when Connect() is called.
base::OnceClosure on_connect_closure;
private:
struct ConnectArgs {
ConnectArgs(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback);
~ConnectArgs();
std::vector<uint8_t> bluetooth_public_address;
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver;
ConnectCallback callback;
};
/// mojom::NearbyConnector:
void Connect(
const std::vector<uint8_t>& bluetooth_public_address,
mojo::PendingRemote<mojom::NearbyMessageReceiver> message_receiver,
ConnectCallback callback) override;
base::queue<std::unique_ptr<ConnectArgs>> queued_connect_args_;
std::vector<std::unique_ptr<FakeConnection>> fake_connections_;
};
} // namespace secure_channel
} // namespace chromeos
#endif // CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_FAKE_NEARBY_CONNECTOR_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/services/secure_channel/public/cpp/client/nearby_connector.h"
namespace chromeos {
namespace secure_channel {
NearbyConnector::NearbyConnector() = default;
NearbyConnector::~NearbyConnector() = default;
mojo::PendingRemote<mojom::NearbyConnector>
NearbyConnector::GeneratePendingRemote() {
mojo::PendingRemote<mojom::NearbyConnector> pending_remote;
receiver_set_.Add(this, pending_remote.InitWithNewPipeAndPassReceiver());
return pending_remote;
}
} // namespace secure_channel
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_NEARBY_CONNECTOR_H_
#define CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_NEARBY_CONNECTOR_H_
#include "chromeos/services/secure_channel/public/mojom/nearby_connector.mojom.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
namespace chromeos {
namespace secure_channel {
// Provides Nearby Connections functionality to the SecureChannel service.
class NearbyConnector : public mojom::NearbyConnector {
public:
NearbyConnector();
~NearbyConnector() override;
mojo::PendingRemote<mojom::NearbyConnector> GeneratePendingRemote();
private:
mojo::ReceiverSet<mojom::NearbyConnector> receiver_set_;
};
} // namespace secure_channel
} // namespace chromeos
#endif // CHROMEOS_SERVICES_SECURE_CHANNEL_PUBLIC_CPP_CLIENT_NEARBY_CONNECTOR_H_
......@@ -20,3 +20,20 @@ interface NearbyMessageReceiver {
OnMessageReceived(string message);
};
// Provides an interface to make a SecureChannel connection over the Nearby
// Connections library.
interface NearbyConnector {
// Starts a connection attempt to the device with the provided address, using
// |kServiceId| as the service ID for the connection. If the attempt succeeds,
// a NearbyMessageSender is returned to the caller, enabling the caller to
// send messages over the connection. If the attempt fails, null is returned.
//
// To disconnect an active connection, disconnect either |message_receiver| or
// |message_sender|. If the remote device disconnects an active connection,
// these are both disconnected; clients should set disconnection handlers to
// be notified if a disconnection should occur.
Connect(array<uint8, 6> bluetooth_public_address,
pending_remote<NearbyMessageReceiver> message_receiver) =>
(pending_remote<NearbyMessageSender>? message_sender);
};
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