diff --git a/sharing/BUILD b/sharing/BUILD index 2d00e45d..028ac35b 100644 --- a/sharing/BUILD +++ b/sharing/BUILD @@ -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", diff --git a/sharing/certificates/BUILD b/sharing/certificates/BUILD index e303ab1e..f18cfbd8 100644 --- a/sharing/certificates/BUILD +++ b/sharing/certificates/BUILD @@ -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", diff --git a/sharing/certificates/fake_nearby_share_certificate_manager.cc b/sharing/certificates/fake_nearby_share_certificate_manager.cc index 5a6ba7d9..7895eda6 100644 --- a/sharing/certificates/fake_nearby_share_certificate_manager.cc +++ b/sharing/certificates/fake_nearby_share_certificate_manager.cc @@ -23,12 +23,12 @@ #include #include +#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" diff --git a/sharing/certificates/fake_nearby_share_certificate_manager.h b/sharing/certificates/fake_nearby_share_certificate_manager.h index 0ceb98b3..0a5c8f24 100644 --- a/sharing/certificates/fake_nearby_share_certificate_manager.h +++ b/sharing/certificates/fake_nearby_share_certificate_manager.h @@ -24,12 +24,12 @@ #include #include +#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" diff --git a/sharing/certificates/nearby_share_certificate_manager_impl.cc b/sharing/certificates/nearby_share_certificate_manager_impl.cc index e3b02823..a79283d3 100644 --- a/sharing/certificates/nearby_share_certificate_manager_impl.cc +++ b/sharing/certificates/nearby_share_certificate_manager_impl.cc @@ -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" diff --git a/sharing/certificates/nearby_share_certificate_manager_impl.h b/sharing/certificates/nearby_share_certificate_manager_impl.h index 68d5adbc..a94598c4 100644 --- a/sharing/certificates/nearby_share_certificate_manager_impl.h +++ b/sharing/certificates/nearby_share_certificate_manager_impl.h @@ -23,6 +23,7 @@ #include #include +#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_client_; std::unique_ptr nearby_identity_client_; diff --git a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc index bb826146..cf4b5b24 100644 --- a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc +++ b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc @@ -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" diff --git a/sharing/contacts/BUILD b/sharing/contacts/BUILD index d2848a3e..63c23367 100644 --- a/sharing/contacts/BUILD +++ b/sharing/contacts/BUILD @@ -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", diff --git a/sharing/contacts/nearby_share_contact_manager_impl.cc b/sharing/contacts/nearby_share_contact_manager_impl.cc index dfa1c28f..43244f96 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl.cc +++ b/sharing/contacts/nearby_share_contact_manager_impl.cc @@ -23,11 +23,11 @@ #include #include +#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" diff --git a/sharing/contacts/nearby_share_contact_manager_impl.h b/sharing/contacts/nearby_share_contact_manager_impl.h index e6ad10bc..b40ef772 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl.h +++ b/sharing/contacts/nearby_share_contact_manager_impl.h @@ -17,10 +17,10 @@ #include +#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 { diff --git a/sharing/contacts/nearby_share_contact_manager_impl_test.cc b/sharing/contacts/nearby_share_contact_manager_impl_test.cc index e9f5d345..7f246d6f 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl_test.cc +++ b/sharing/contacts/nearby_share_contact_manager_impl_test.cc @@ -18,15 +18,14 @@ #include #include -#include #include #include +#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" diff --git a/sharing/internal/api/BUILD b/sharing/internal/api/BUILD index 7e1f6eb2..a0e132ed 100644 --- a/sharing/internal/api/BUILD +++ b/sharing/internal/api/BUILD @@ -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", diff --git a/sharing/internal/api/fake_nearby_share_client.cc b/sharing/internal/api/fake_nearby_share_client.cc deleted file mode 100644 index 61b7acd8..00000000 --- a/sharing/internal/api/fake_nearby_share_client.cc +++ /dev/null @@ -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 -#include - -#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& 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& response) &&> - callback) { - absl::StatusOr 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& response) &&> - callback) { - absl::StatusOr 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& response) &&> - callback) { - absl::StatusOr 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& response) &&> - callback) { - absl::StatusOr 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& response) &&> - callback) { - absl::StatusOr 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& response) &&> - callback) { - absl::StatusOr 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& - response) &&> - callback) { - absl::StatusOr 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 -FakeNearbyShareClientFactory::CreateInstance() { - auto instance = std::make_unique(); - instances_.push_back(instance.get()); - return instance; -} - -std::unique_ptr -FakeNearbyShareClientFactory::CreateIdentityInstance() { - auto instance = std::make_unique(); - identity_instances_.push_back(instance.get()); - return instance; -} - -} // namespace sharing -} // namespace nearby diff --git a/sharing/internal/api/fake_nearby_share_client.h b/sharing/internal/api/fake_nearby_share_client.h deleted file mode 100644 index 487bef0b..00000000 --- a/sharing/internal/api/fake_nearby_share_client.h +++ /dev/null @@ -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 -#include - -#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 - list_contact_people_requests() { - absl::MutexLock lock(mutex_); - return list_contact_people_requests_; - } - - void SetListContactPeopleResponses( - std::vector> responses) { - absl::MutexLock lock(mutex_); - list_contact_people_responses_ = responses; - } - - void ListContactPeople( - proto::ListContactPeopleRequest request, - absl::AnyInvocable& response) &&> - callback) override; - - std::vector - initiate_binding_requests() { - absl::MutexLock lock(mutex_); - return initiate_binding_requests_; - } - - void SetInitiateBindingResponses( - std::vector> - responses) { - absl::MutexLock lock(mutex_); - initiate_binding_responses_ = responses; - } - - void InitiateBinding( - google::nearby::identity::v1::InitiateBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& response) &&> - callback) override; - - std::vector - join_binding_requests() { - absl::MutexLock lock(mutex_); - return join_binding_requests_; - } - - void SetJoinBindingResponses( - std::vector> - responses) { - absl::MutexLock lock(mutex_); - join_binding_responses_ = responses; - } - - void JoinBinding( - google::nearby::identity::v1::JoinBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& response) &&> - callback) override; - - std::vector - delete_binding_requests() { - absl::MutexLock lock(mutex_); - return delete_binding_requests_; - } - - void SetDeleteBindingResponses( - std::vector> - responses) { - absl::MutexLock lock(mutex_); - delete_binding_responses_ = responses; - } - - void DeleteBinding( - google::nearby::identity::v1::DeleteBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& response) &&> - callback) override; - - private: - absl::Mutex mutex_; - std::vector - list_contact_people_requests_ ABSL_GUARDED_BY(mutex_); - std::vector> - list_contact_people_responses_ ABSL_GUARDED_BY(mutex_); - std::vector - initiate_binding_requests_ ABSL_GUARDED_BY(mutex_); - std::vector< - absl::StatusOr> - initiate_binding_responses_ ABSL_GUARDED_BY(mutex_); - std::vector - join_binding_requests_ ABSL_GUARDED_BY(mutex_); - std::vector> - join_binding_responses_ ABSL_GUARDED_BY(mutex_); - std::vector - delete_binding_requests_ ABSL_GUARDED_BY(mutex_); - std::vector< - absl::StatusOr> - 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 - publish_device_requests() ABSL_LOCKS_EXCLUDED(mutex_) { - absl::MutexLock lock(mutex_); - return publish_device_requests_; - } - - std::vector - 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& response) &&> - callback) ABSL_LOCKS_EXCLUDED(mutex_) override; - - void SetPublishDeviceResponses( - std::vector< - absl::StatusOr> - 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> - responses) ABSL_LOCKS_EXCLUDED(mutex_) { - absl::MutexLock lock(mutex_); - query_shared_credentials_responses_ = responses; - } - - std::vector - 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& response) &&> - callback) ABSL_LOCKS_EXCLUDED(mutex_) override; - - void SetGetAccountInfoResponse( - absl::StatusOr - response) ABSL_LOCKS_EXCLUDED(mutex_) { - absl::MutexLock lock(mutex_); - get_account_info_response_ = response; - } - - std::vector - 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> - responses) ABSL_LOCKS_EXCLUDED(mutex_) { - absl::MutexLock lock(mutex_); - query_shared_credentials_with_binding_ids_responses_ = responses; - } - - private: - absl::Mutex mutex_; - std::vector - publish_device_requests_ ABSL_GUARDED_BY(mutex_); - std::vector< - absl::StatusOr> - publish_device_responses_ ABSL_GUARDED_BY(mutex_); - - std::vector - query_shared_credentials_requests_ ABSL_GUARDED_BY(mutex_); - std::vector> - query_shared_credentials_responses_ ABSL_GUARDED_BY(mutex_); - - std::vector - get_account_info_requests_ ABSL_GUARDED_BY(mutex_); - absl::StatusOr - 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> - 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& instances() { return instances_; } - std::vector& identity_instances() { - return identity_instances_; - } - - private: - // SharingRpcClientFactory: - std::unique_ptr CreateInstance() - override; - - std::unique_ptr - CreateIdentityInstance() override; - - std::vector instances_; - std::vector identity_instances_; -}; - -} // namespace sharing -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_FAKE_NEARBY_SHARE_CLIENT_H_ diff --git a/sharing/internal/api/mock_sharing_platform.h b/sharing/internal/api/mock_sharing_platform.h index fc7b547d..b5b64e18 100644 --- a/sharing/internal/api/mock_sharing_platform.h +++ b/sharing/internal/api/mock_sharing_platform.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, CreatePublicCertificateDatabase, (const FilePath& database_path), (override)); - MOCK_METHOD( - std::unique_ptr, CreateSharingRpcClientFactory, - (Clock * clock, - nearby::sharing::analytics::AnalyticsRecorder* analytics_recorder), - (override)); MOCK_METHOD(bool, UpdateFileOriginMetadata, (std::vector & file_paths), (override)); }; diff --git a/sharing/internal/api/sharing_platform.h b/sharing/internal/api/sharing_platform.h index abc3703a..d5bab76a 100644 --- a/sharing/internal/api/sharing_platform.h +++ b/sharing/internal/api/sharing_platform.h @@ -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 CreatePublicCertificateDatabase(const FilePath& database_path) = 0; - virtual std::unique_ptr - 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. diff --git a/sharing/internal/api/sharing_rpc_client.h b/sharing/internal/api/sharing_rpc_client.h deleted file mode 100644 index 7dcb91e6..00000000 --- a/sharing/internal/api/sharing_rpc_client.h +++ /dev/null @@ -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 - -#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& response) &&> - callback) = 0; - - virtual void GetAccountInfo( - google::nearby::identity::v1::GetAccountInfoRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& 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& response) &&> - callback) = 0; - - virtual void InitiateBinding( - google::nearby::identity::v1::InitiateBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& response) &&> - callback) = 0; - - virtual void JoinBinding( - google::nearby::identity::v1::JoinBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& response) &&> - callback) = 0; - - virtual void DeleteBinding( - google::nearby::identity::v1::DeleteBindingRequest request, - absl::AnyInvocable< - void(const absl::StatusOr& 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 CreateInstance() = 0; - virtual std::unique_ptr CreateIdentityInstance() = 0; -}; - -} // namespace nearby::sharing::api - -#endif // THIRD_PARTY_NEARBY_SHARING_INTERNAL_API_SHARING_RPC_CLIENT_H_ diff --git a/sharing/nearby_sharing_service_factory.cc b/sharing/nearby_sharing_service_factory.cc index baee53f8..f7aac28d 100644 --- a/sharing/nearby_sharing_service_factory.cc +++ b/sharing/nearby_sharing_service_factory.cc @@ -17,6 +17,7 @@ #include #include +#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( + &sharing_platform.GetAccountManager(), context_->GetClock(), + analytics_recorder); auto nearby_share_contact_manager = std::make_unique( context_.get(), sharing_platform.GetAccountManager(), diff --git a/sharing/nearby_sharing_service_impl.cc b/sharing/nearby_sharing_service_impl.cc index fc21d2f4..1d48bff6 100644 --- a/sharing/nearby_sharing_service_impl.cc +++ b/sharing/nearby_sharing_service_impl.cc @@ -31,6 +31,7 @@ #include #include +#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" diff --git a/sharing/nearby_sharing_service_impl.h b/sharing/nearby_sharing_service_impl.h index 82813706..21152726 100644 --- a/sharing/nearby_sharing_service_impl.h +++ b/sharing/nearby_sharing_service_impl.h @@ -27,6 +27,7 @@ #include #include +#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"