Remove rpc client from sharing platform.

PiperOrigin-RevId: 878135348
This commit is contained in:
Francis Tsui
2026-03-03 14:49:52 -08:00
committed by Copybara-Service
parent 115fa39dd3
commit f79846c431
20 changed files with 21 additions and 661 deletions
+2
View File
@@ -382,6 +382,8 @@ cc_library(
"//internal/platform:types",
"//internal/platform/implementation:account_manager",
"//internal/platform/implementation:types",
"//location/nearby/sharing/lib/rpc:grpc_async_client_factory",
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
"//proto:sharing_enums_cc_proto",
"//sharing/analytics",
"//sharing/certificates",
+3 -3
View File
@@ -51,7 +51,7 @@ cc_library(
"//internal/platform:mac_address",
"//internal/platform:types",
"//internal/platform/implementation:account_manager",
"//sharing/common",
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
"//sharing/internal/api:platform",
"//sharing/internal/base",
"//sharing/internal/public:logging",
@@ -97,6 +97,7 @@ cc_library(
"//internal/base:bluetooth_address",
"//internal/base:file_path",
"//internal/crypto_cros",
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
"//sharing/common:enum",
"//sharing/internal/api:platform",
"//sharing/internal/public:types",
@@ -129,7 +130,7 @@ cc_test(
"//internal/platform/implementation:account_manager",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/common",
"//location/nearby/sharing/lib/rpc:fake_nearby_share_client",
"//sharing/common:enum",
"//sharing/internal/api:mock_sharing_platform",
"//sharing/internal/api:platform",
@@ -141,7 +142,6 @@ cc_test(
"//sharing/scheduling",
"//sharing/scheduling:test_support",
"@com_github_protobuf_matchers//protobuf-matchers",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/functional:any_invocable",
"@com_google_absl//absl/status",
"@com_google_absl//absl/status:statusor",
@@ -23,12 +23,12 @@
#include <utility>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "internal/base/file_path.h"
#include "sharing/certificates/nearby_share_certificate_manager.h"
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
#include "sharing/certificates/nearby_share_private_certificate.h"
#include "sharing/certificates/test_util.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
#include "sharing/proto/enums.pb.h"
@@ -24,12 +24,12 @@
#include <string>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "internal/base/file_path.h"
#include "sharing/certificates/nearby_share_certificate_manager.h"
#include "sharing/certificates/nearby_share_certificate_manager_impl.h"
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
#include "sharing/certificates/nearby_share_private_certificate.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
#include "sharing/proto/rpc_resources.pb.h"
@@ -31,6 +31,7 @@
#include "google/nearby/identity/v1/resources.pb.h"
#include "google/nearby/identity/v1/rpcs.pb.h"
#include "google/protobuf/timestamp.pb.h"
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "absl/algorithm/algorithm.h"
#include "absl/container/flat_hash_map.h"
#include "absl/memory/memory.h"
@@ -56,7 +57,6 @@
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/api/public_certificate_database.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/base/encode.h"
#include "sharing/internal/public/context.h"
#include "sharing/internal/public/logging.h"
@@ -23,6 +23,7 @@
#include <utility>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "absl/base/nullability.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
@@ -37,7 +38,6 @@
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/api/public_certificate_database.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
#include "sharing/proto/enums.pb.h"
@@ -197,7 +197,6 @@ class NearbyShareCertificateManagerImpl
NearbyShareLocalDeviceDataManager* const local_device_data_manager_;
nearby::sharing::api::PreferenceManager& preference_manager_;
int32_t vendor_id_ = 0; // Defaults to GOOGLE.
std::unique_ptr<nearby::sharing::api::SharingRpcClient> nearby_client_;
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
nearby_identity_client_;
@@ -27,10 +27,10 @@
#include "google/nearby/identity/v1/resources.pb.h"
#include "google/nearby/identity/v1/rpcs.pb.h"
#include "location/nearby/sharing/lib/rpc/fake_nearby_share_client.h"
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
@@ -48,7 +48,6 @@
#include "sharing/certificates/nearby_share_encrypted_metadata_key.h"
#include "sharing/certificates/nearby_share_private_certificate.h"
#include "sharing/certificates/test_util.h"
#include "sharing/internal/api/fake_nearby_share_client.h"
#include "sharing/internal/api/mock_sharing_platform.h"
#include "sharing/internal/public/pref_names.h"
#include "sharing/internal/test/fake_bluetooth_adapter.h"
+2 -2
View File
@@ -43,7 +43,7 @@ cc_library(
":contacts_interface",
"//internal/platform:types",
"//internal/platform/implementation:account_manager",
"//sharing/internal/api:platform",
"//location/nearby/sharing/lib/rpc:sharing_rpc_client",
"//sharing/internal/public:logging",
"//sharing/internal/public:types",
"//sharing/proto:share_cc_proto",
@@ -72,7 +72,7 @@ cc_test(
"//internal/platform/implementation:account_manager",
"//internal/platform/implementation:platform_impl",
"//internal/test",
"//sharing/internal/api:mock_sharing_platform",
"//location/nearby/sharing/lib/rpc:fake_nearby_share_client",
"//sharing/internal/test:nearby_test",
"//sharing/local_device_data:test_support",
"//sharing/proto:share_cc_proto",
@@ -23,11 +23,11 @@
#include <utility>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/notification.h"
#include "internal/platform/implementation/account_manager.h"
#include "sharing/contacts/nearby_share_contact_manager.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
#include "sharing/internal/public/logging.h"
#include "sharing/proto/contact_rpc.pb.h"
@@ -17,10 +17,10 @@
#include <memory>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/platform/task_runner.h"
#include "sharing/contacts/nearby_share_contact_manager.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
namespace nearby {
@@ -18,15 +18,14 @@
#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "location/nearby/sharing/lib/rpc/fake_nearby_share_client.h"
#include "gtest/gtest.h"
#include "absl/time/time.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/test/fake_account_manager.h"
#include "sharing/internal/api/fake_nearby_share_client.h"
#include "sharing/internal/test/fake_context.h"
#include "sharing/local_device_data/fake_nearby_share_local_device_data_manager.h"
#include "sharing/proto/contact_rpc.pb.h"
-8
View File
@@ -28,7 +28,6 @@ cc_library(
"private_certificate_data.h",
"public_certificate_database.h",
"sharing_platform.h",
"sharing_rpc_client.h",
"system_info.h",
],
visibility = [
@@ -39,8 +38,6 @@ cc_library(
"//sharing:__subpackages__",
],
deps = [
"//google/nearby/identity/v1:binding_cc_proto",
"//google/nearby/identity/v1:rpcs_cc_proto",
"//internal/base:file_path",
"//internal/platform:mac_address",
"//internal/platform:types",
@@ -59,11 +56,7 @@ cc_library(
cc_library(
name = "mock_sharing_platform",
testonly = True,
srcs = [
"fake_nearby_share_client.cc",
],
hdrs = [
"fake_nearby_share_client.h",
"mock_app_info.h",
"mock_bluetooth_adapter.h",
"mock_fast_init_ble_beacon.h",
@@ -76,7 +69,6 @@ cc_library(
visibility = ["//visibility:public"],
deps = [
":platform",
"//google/nearby/identity/v1:binding_cc_proto",
"//internal/base:file_path",
"//internal/platform:mac_address",
"//internal/platform:types",
@@ -1,203 +0,0 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "sharing/internal/api/fake_nearby_share_client.h"
#include <memory>
#include <utility>
#include "google/nearby/identity/v1/binding.pb.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/logging.h"
#include "sharing/proto/certificate_rpc.pb.h"
#include "sharing/proto/contact_rpc.pb.h"
#include "sharing/proto/device_rpc.pb.h"
namespace nearby {
namespace sharing {
using ::google::nearby::identity::v1::GetAccountInfoRequest;
using ::google::nearby::identity::v1::GetAccountInfoResponse;
using ::google::nearby::identity::v1::PublishDeviceRequest;
using ::google::nearby::identity::v1::PublishDeviceResponse;
using ::google::nearby::identity::v1::QuerySharedCredentialsRequest;
using ::google::nearby::identity::v1::QuerySharedCredentialsResponse;
using ::google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsRequest;
using ::google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsResponse;
using ::google::nearby::identity::v1::InitiateBindingRequest;
using ::google::nearby::identity::v1::InitiateBindingResponse;
using ::google::nearby::identity::v1::JoinBindingRequest;
using ::google::nearby::identity::v1::JoinBindingResponse;
using ::google::nearby::identity::v1::DeleteBindingRequest;
using ::google::nearby::identity::v1::DeleteBindingResponse;
void FakeNearbyShareClient::ListContactPeople(
proto::ListContactPeopleRequest request,
absl::AnyInvocable<void(
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
callback) {
absl::MutexLock lock(mutex_);
list_contact_people_requests_.emplace_back(request);
if (list_contact_people_responses_.empty()) {
std::move(callback)(absl::NotFoundError(""));
return;
}
auto response = list_contact_people_responses_[0];
list_contact_people_responses_.erase(list_contact_people_responses_.begin());
std::move(callback)(response);
}
void FakeNearbyShareClient::InitiateBinding(
InitiateBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<InitiateBindingResponse>& response) &&>
callback) {
absl::StatusOr<InitiateBindingResponse> response = absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
initiate_binding_requests_.emplace_back(request);
if (!initiate_binding_responses_.empty()) {
response = initiate_binding_responses_[0];
initiate_binding_responses_.erase(initiate_binding_responses_.begin());
}
}
std::move(callback)(response);
}
void FakeNearbyShareClient::JoinBinding(
JoinBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<JoinBindingResponse>& response) &&>
callback) {
absl::StatusOr<JoinBindingResponse> response = absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
join_binding_requests_.emplace_back(request);
if (!join_binding_responses_.empty()) {
response = join_binding_responses_[0];
join_binding_responses_.erase(join_binding_responses_.begin());
}
}
std::move(callback)(response);
}
void FakeNearbyShareClient::DeleteBinding(
DeleteBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<DeleteBindingResponse>& response) &&>
callback) {
absl::StatusOr<DeleteBindingResponse> response = absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
delete_binding_requests_.emplace_back(request);
if (!delete_binding_responses_.empty()) {
response = delete_binding_responses_[0];
delete_binding_responses_.erase(delete_binding_responses_.begin());
}
}
std::move(callback)(response);
}
void FakeNearbyIdentityClient::QuerySharedCredentials(
QuerySharedCredentialsRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<QuerySharedCredentialsResponse>& response) &&>
callback) {
absl::StatusOr<QuerySharedCredentialsResponse> response =
absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
query_shared_credentials_requests_.emplace_back(request);
if (!query_shared_credentials_responses_.empty()) {
response = query_shared_credentials_responses_[0];
query_shared_credentials_responses_.erase(
query_shared_credentials_responses_.begin());
}
}
std::move(callback)(response);
}
void FakeNearbyIdentityClient::PublishDevice(
PublishDeviceRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<PublishDeviceResponse>& response) &&>
callback) {
absl::StatusOr<PublishDeviceResponse> response = absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
publish_device_requests_.emplace_back(request);
if (!publish_device_responses_.empty()) {
response = publish_device_responses_[0];
publish_device_responses_.erase(publish_device_responses_.begin());
}
}
std::move(callback)(response);
}
void FakeNearbyIdentityClient::GetAccountInfo(
GetAccountInfoRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<GetAccountInfoResponse>& response) &&>
callback) {
absl::StatusOr<GetAccountInfoResponse> response = absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
get_account_info_requests_.emplace_back(request);
response = get_account_info_response_;
}
std::move(callback)(response);
}
void FakeNearbyIdentityClient::QuerySharedCredentialsWithBindingIds(
QuerySharedCredentialsWithBindingIdsRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<QuerySharedCredentialsWithBindingIdsResponse>&
response) &&>
callback) {
absl::StatusOr<QuerySharedCredentialsWithBindingIdsResponse> response =
absl::NotFoundError("");
{
absl::MutexLock lock(mutex_);
query_shared_credentials_with_binding_ids_requests_.emplace_back(request);
if (!query_shared_credentials_with_binding_ids_responses_.empty()) {
response = query_shared_credentials_with_binding_ids_responses_[0];
query_shared_credentials_with_binding_ids_responses_.erase(
query_shared_credentials_with_binding_ids_responses_.begin());
}
}
std::move(callback)(response);
}
std::unique_ptr<nearby::sharing::api::SharingRpcClient>
FakeNearbyShareClientFactory::CreateInstance() {
auto instance = std::make_unique<FakeNearbyShareClient>();
instances_.push_back(instance.get());
return instance;
}
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
FakeNearbyShareClientFactory::CreateIdentityInstance() {
auto instance = std::make_unique<FakeNearbyIdentityClient>();
identity_instances_.push_back(instance.get());
return instance;
}
} // namespace sharing
} // namespace nearby
@@ -1,297 +0,0 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_FAKE_NEARBY_SHARE_CLIENT_H_
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_FAKE_NEARBY_SHARE_CLIENT_H_
#include <memory>
#include <vector>
#include "absl/base/thread_annotations.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
#include "absl/synchronization/mutex.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/proto/certificate_rpc.pb.h"
#include "sharing/proto/contact_rpc.pb.h"
#include "sharing/proto/device_rpc.pb.h"
namespace nearby {
namespace sharing {
// A fake implementation of the Nearby Share HTTP client that stores all request
// data. Only use in unit tests.
class FakeNearbyShareClient : public nearby::sharing::api::SharingRpcClient {
public:
FakeNearbyShareClient() = default;
~FakeNearbyShareClient() override = default;
std::vector<nearby::sharing::proto::ListContactPeopleRequest>
list_contact_people_requests() {
absl::MutexLock lock(mutex_);
return list_contact_people_requests_;
}
void SetListContactPeopleResponses(
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>> responses) {
absl::MutexLock lock(mutex_);
list_contact_people_responses_ = responses;
}
void ListContactPeople(
proto::ListContactPeopleRequest request,
absl::AnyInvocable<void(
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
callback) override;
std::vector<google::nearby::identity::v1::InitiateBindingRequest>
initiate_binding_requests() {
absl::MutexLock lock(mutex_);
return initiate_binding_requests_;
}
void SetInitiateBindingResponses(
std::vector<absl::StatusOr<google::nearby::identity::v1::
InitiateBindingResponse>>
responses) {
absl::MutexLock lock(mutex_);
initiate_binding_responses_ = responses;
}
void InitiateBinding(
google::nearby::identity::v1::InitiateBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
InitiateBindingResponse>& response) &&>
callback) override;
std::vector<google::nearby::identity::v1::JoinBindingRequest>
join_binding_requests() {
absl::MutexLock lock(mutex_);
return join_binding_requests_;
}
void SetJoinBindingResponses(
std::vector<absl::StatusOr<google::nearby::identity::v1::
JoinBindingResponse>>
responses) {
absl::MutexLock lock(mutex_);
join_binding_responses_ = responses;
}
void JoinBinding(
google::nearby::identity::v1::JoinBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
JoinBindingResponse>& response) &&>
callback) override;
std::vector<google::nearby::identity::v1::DeleteBindingRequest>
delete_binding_requests() {
absl::MutexLock lock(mutex_);
return delete_binding_requests_;
}
void SetDeleteBindingResponses(
std::vector<absl::StatusOr<google::nearby::identity::v1::
DeleteBindingResponse>>
responses) {
absl::MutexLock lock(mutex_);
delete_binding_responses_ = responses;
}
void DeleteBinding(
google::nearby::identity::v1::DeleteBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
DeleteBindingResponse>& response) &&>
callback) override;
private:
absl::Mutex mutex_;
std::vector<nearby::sharing::proto::ListContactPeopleRequest>
list_contact_people_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<absl::StatusOr<proto::ListContactPeopleResponse>>
list_contact_people_responses_ ABSL_GUARDED_BY(mutex_);
std::vector<google::nearby::identity::v1::InitiateBindingRequest>
initiate_binding_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<
absl::StatusOr<google::nearby::identity::v1::InitiateBindingResponse>>
initiate_binding_responses_ ABSL_GUARDED_BY(mutex_);
std::vector<google::nearby::identity::v1::JoinBindingRequest>
join_binding_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<absl::StatusOr<google::nearby::identity::v1::JoinBindingResponse>>
join_binding_responses_ ABSL_GUARDED_BY(mutex_);
std::vector<google::nearby::identity::v1::DeleteBindingRequest>
delete_binding_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<
absl::StatusOr<google::nearby::identity::v1::DeleteBindingResponse>>
delete_binding_responses_ ABSL_GUARDED_BY(mutex_);
};
// A fake implementation of the Nearby Identity RPC client that stores all
// request data. Only use in unit tests.
class FakeNearbyIdentityClient
: public nearby::sharing::api::IdentityRpcClient {
public:
FakeNearbyIdentityClient() = default;
~FakeNearbyIdentityClient() override = default;
std::vector<google::nearby::identity::v1::PublishDeviceRequest>
publish_device_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
return publish_device_requests_;
}
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>
query_shared_credentials_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
return query_shared_credentials_requests_;
}
void PublishDevice(
google::nearby::identity::v1::PublishDeviceRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
PublishDeviceResponse>& response) &&>
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
void SetPublishDeviceResponses(
std::vector<
absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>>
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
publish_device_responses_ = responses;
}
void QuerySharedCredentials(
google::nearby::identity::v1::QuerySharedCredentialsRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
response) &&>
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
void SetQuerySharedCredentialsResponses(
std::vector<absl::StatusOr<
google::nearby::identity::v1::QuerySharedCredentialsResponse>>
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
query_shared_credentials_responses_ = responses;
}
std::vector<google::nearby::identity::v1::GetAccountInfoRequest>
get_account_info_requests() ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
return get_account_info_requests_;
}
void GetAccountInfo(
google::nearby::identity::v1::GetAccountInfoRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
GetAccountInfoResponse>& response) &&>
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
void SetGetAccountInfoResponse(
absl::StatusOr<google::nearby::identity::v1::GetAccountInfoResponse>
response) ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
get_account_info_response_ = response;
}
std::vector<google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsRequest>
query_shared_credentials_with_binding_ids_requests()
ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
return query_shared_credentials_with_binding_ids_requests_;
}
void QuerySharedCredentialsWithBindingIds(
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
request,
absl::AnyInvocable<
void(const absl::StatusOr<
google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsResponse>& response) &&>
callback) ABSL_LOCKS_EXCLUDED(mutex_) override;
void SetQuerySharedCredentialsWithBindingIdsResponse(
std::vector<absl::StatusOr<
google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsResponse>>
responses) ABSL_LOCKS_EXCLUDED(mutex_) {
absl::MutexLock lock(mutex_);
query_shared_credentials_with_binding_ids_responses_ = responses;
}
private:
absl::Mutex mutex_;
std::vector<google::nearby::identity::v1::PublishDeviceRequest>
publish_device_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<
absl::StatusOr<google::nearby::identity::v1::PublishDeviceResponse>>
publish_device_responses_ ABSL_GUARDED_BY(mutex_);
std::vector<google::nearby::identity::v1::QuerySharedCredentialsRequest>
query_shared_credentials_requests_ ABSL_GUARDED_BY(mutex_);
std::vector<absl::StatusOr<
google::nearby::identity::v1::QuerySharedCredentialsResponse>>
query_shared_credentials_responses_ ABSL_GUARDED_BY(mutex_);
std::vector<google::nearby::identity::v1::GetAccountInfoRequest>
get_account_info_requests_ ABSL_GUARDED_BY(mutex_);
absl::StatusOr<google::nearby::identity::v1::GetAccountInfoResponse>
get_account_info_response_ ABSL_GUARDED_BY(mutex_);
std::vector<
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest>
query_shared_credentials_with_binding_ids_requests_
ABSL_GUARDED_BY(mutex_);
std::vector<absl::StatusOr<google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsResponse>>
query_shared_credentials_with_binding_ids_responses_
ABSL_GUARDED_BY(mutex_);
};
class FakeNearbyShareClientFactory
: public nearby::sharing::api::SharingRpcClientFactory {
public:
FakeNearbyShareClientFactory() = default;
~FakeNearbyShareClientFactory() override = default;
public:
// Returns all FakeNearbyShareClient instances created by CreateInstance().
std::vector<FakeNearbyShareClient*>& instances() { return instances_; }
std::vector<FakeNearbyIdentityClient*>& identity_instances() {
return identity_instances_;
}
private:
// SharingRpcClientFactory:
std::unique_ptr<nearby::sharing::api::SharingRpcClient> CreateInstance()
override;
std::unique_ptr<nearby::sharing::api::IdentityRpcClient>
CreateIdentityInstance() override;
std::vector<FakeNearbyShareClient*> instances_;
std::vector<FakeNearbyIdentityClient*> identity_instances_;
};
} // namespace sharing
} // namespace nearby
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_FAKE_NEARBY_SHARE_CLIENT_H_
@@ -22,11 +22,9 @@
#include "gmock/gmock.h"
#include "absl/strings/string_view.h"
#include "internal/base/file_path.h"
#include "internal/platform/clock.h"
#include "internal/platform/device_info.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/platform/task_runner.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/internal/api/app_info.h"
#include "sharing/internal/api/bluetooth_adapter.h"
#include "sharing/internal/api/fast_init_ble_beacon.h"
@@ -35,7 +33,6 @@
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/api/public_certificate_database.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/api/system_info.h"
namespace nearby::sharing::api {
@@ -79,11 +76,6 @@ class MockSharingPlatform : public SharingPlatform {
MOCK_METHOD(std::unique_ptr<PublicCertificateDatabase>,
CreatePublicCertificateDatabase, (const FilePath& database_path),
(override));
MOCK_METHOD(
std::unique_ptr<SharingRpcClientFactory>, CreateSharingRpcClientFactory,
(Clock * clock,
nearby::sharing::analytics::AnalyticsRecorder* analytics_recorder),
(override));
MOCK_METHOD(bool, UpdateFileOriginMetadata,
(std::vector<FilePath> & file_paths), (override));
};
-8
View File
@@ -21,11 +21,9 @@
#include "absl/strings/string_view.h"
#include "internal/base/file_path.h"
#include "internal/platform/clock.h"
#include "internal/platform/device_info.h"
#include "internal/platform/implementation/account_manager.h"
#include "internal/platform/task_runner.h"
#include "sharing/analytics/analytics_recorder.h"
#include "sharing/internal/api/app_info.h"
#include "sharing/internal/api/bluetooth_adapter.h"
#include "sharing/internal/api/fast_init_ble_beacon.h"
@@ -33,7 +31,6 @@
#include "sharing/internal/api/network_monitor.h"
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/api/public_certificate_database.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/api/system_info.h"
namespace nearby::sharing::api {
@@ -72,11 +69,6 @@ class SharingPlatform {
virtual std::unique_ptr<PublicCertificateDatabase>
CreatePublicCertificateDatabase(const FilePath& database_path) = 0;
virtual std::unique_ptr<SharingRpcClientFactory>
CreateSharingRpcClientFactory(
Clock* clock,
nearby::sharing::analytics::AnalyticsRecorder* analytics_recorder) = 0;
// On platforms where it is supported, tag the transferred files as
// originating from an untrusted source.
// Returns true on success.
-117
View File
@@ -1,117 +0,0 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_RPC_CLIENT_H_
#define THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_RPC_CLIENT_H_
#include <memory>
#include "google/nearby/identity/v1/binding.pb.h"
#include "google/nearby/identity/v1/rpcs.pb.h"
#include "absl/functional/any_invocable.h"
#include "absl/status/statusor.h"
#include "sharing/proto/certificate_rpc.pb.h"
#include "sharing/proto/contact_rpc.pb.h"
#include "sharing/proto/device_rpc.pb.h"
namespace nearby::sharing::api {
// IdentityRpcClient is used to access Nearby Identity backend APIs.
class IdentityRpcClient {
public:
IdentityRpcClient() = default;
virtual ~IdentityRpcClient() = default;
virtual void QuerySharedCredentials(
google::nearby::identity::v1::QuerySharedCredentialsRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<
google::nearby::identity::v1::QuerySharedCredentialsResponse>&
response) &&>
callback) = 0;
virtual void PublishDevice(
google::nearby::identity::v1::PublishDeviceRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
PublishDeviceResponse>& response) &&>
callback) = 0;
virtual void GetAccountInfo(
google::nearby::identity::v1::GetAccountInfoRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
GetAccountInfoResponse>& response) &&>
callback) = 0;
virtual void QuerySharedCredentialsWithBindingIds(
google::nearby::identity::v1::QuerySharedCredentialsWithBindingIdsRequest
request,
absl::AnyInvocable<
void(const absl::StatusOr<
google::nearby::identity::v1::
QuerySharedCredentialsWithBindingIdsResponse>& response) &&>
callback) = 0;
};
// SharingRpcClient is used to access Nearby Share backend APIs.
class SharingRpcClient {
public:
SharingRpcClient() = default;
virtual ~SharingRpcClient() = default;
// NearbyShareService v1: ListContactPeople
virtual void ListContactPeople(
proto::ListContactPeopleRequest request,
absl::AnyInvocable<void(
const absl::StatusOr<proto::ListContactPeopleResponse>& response) &&>
callback) = 0;
virtual void InitiateBinding(
google::nearby::identity::v1::InitiateBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
InitiateBindingResponse>& response) &&>
callback) = 0;
virtual void JoinBinding(
google::nearby::identity::v1::JoinBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
JoinBindingResponse>& response) &&>
callback) = 0;
virtual void DeleteBinding(
google::nearby::identity::v1::DeleteBindingRequest request,
absl::AnyInvocable<
void(const absl::StatusOr<google::nearby::identity::v1::
DeleteBindingResponse>& response) &&>
callback) = 0;
};
// Interface for creating SharingRpcClient instances. Because each
// SharingRpcClient instance can only be used for one API call, a factory
// makes it easier to make multiple requests in sequence or in parallel.
class SharingRpcClientFactory {
public:
SharingRpcClientFactory() = default;
virtual ~SharingRpcClientFactory() = default;
virtual std::unique_ptr<SharingRpcClient> CreateInstance() = 0;
virtual std::unique_ptr<IdentityRpcClient> CreateIdentityInstance() = 0;
};
} // namespace nearby::sharing::api
#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_RPC_CLIENT_H_
+4 -2
View File
@@ -17,6 +17,7 @@
#include <memory>
#include <utility>
#include "location/nearby/sharing/lib/rpc/grpc_async_client_factory.h"
#include "internal/analytics/event_logger.h"
#include "internal/platform/task_runner.h"
#include "sharing/analytics/analytics_recorder.h"
@@ -55,8 +56,9 @@ NearbySharingService* NearbySharingServiceFactory::CreateSharingService(
sharing_platform.GetDeviceInfo(), event_logger);
auto nearby_share_client_factory =
sharing_platform.CreateSharingRpcClientFactory(context_->GetClock(),
analytics_recorder);
std::make_unique<platform::common::GrpcAsyncClientFactory>(
&sharing_platform.GetAccountManager(), context_->GetClock(),
analytics_recorder);
auto nearby_share_contact_manager =
std::make_unique<NearbyShareContactManagerImpl>(
context_.get(), sharing_platform.GetAccountManager(),
+1 -1
View File
@@ -31,6 +31,7 @@
#include <utility>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "absl/container/flat_hash_map.h"
#include "absl/functional/any_invocable.h"
#include "absl/functional/bind_front.h"
@@ -72,7 +73,6 @@
#include "sharing/incoming_share_session.h"
#include "sharing/internal/api/bluetooth_adapter.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/base/encode.h"
#include "sharing/internal/public/connectivity_manager.h"
#include "sharing/internal/public/context.h"
+1 -1
View File
@@ -27,6 +27,7 @@
#include <tuple>
#include <vector>
#include "location/nearby/sharing/lib/rpc/sharing_rpc_client.h"
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/functional/any_invocable.h"
@@ -51,7 +52,6 @@
#include "sharing/internal/api/bluetooth_adapter.h"
#include "sharing/internal/api/preference_manager.h"
#include "sharing/internal/api/sharing_platform.h"
#include "sharing/internal/api/sharing_rpc_client.h"
#include "sharing/internal/public/context.h"
#include "sharing/local_device_data/nearby_share_local_device_data_manager.h"
#include "sharing/nearby_connection.h"