From 9ccfded727f131181df3e5127cd4ea79ce8fdb0e Mon Sep 17 00:00:00 2001 From: Francis Tsui Date: Thu, 23 Oct 2025 15:14:01 -0700 Subject: [PATCH] Cleanup unnecessary files and classes. PiperOrigin-RevId: 823206305 --- sharing/BUILD | 3 +- sharing/certificates/BUILD | 3 +- ...rby_share_certificate_manager_impl_test.cc | 3 - sharing/contacts/BUILD | 50 ++++------- .../fake_nearby_share_contact_manager.cc | 52 ------------ .../fake_nearby_share_contact_manager.h | 57 +------------ .../contacts/nearby_share_contact_manager.cc | 29 ------- .../contacts/nearby_share_contact_manager.h | 18 +--- .../nearby_share_contact_manager_impl.cc | 84 +++++++++---------- .../nearby_share_contact_manager_impl.h | 74 +--------------- .../nearby_share_contact_manager_impl_test.cc | 10 +-- sharing/nearby_sharing_service_factory.cc | 14 +++- sharing/nearby_sharing_service_impl.cc | 12 +-- sharing/nearby_sharing_service_impl.h | 3 + sharing/nearby_sharing_service_impl_test.cc | 9 +- 15 files changed, 92 insertions(+), 329 deletions(-) delete mode 100644 sharing/contacts/fake_nearby_share_contact_manager.cc delete mode 100644 sharing/contacts/nearby_share_contact_manager.cc diff --git a/sharing/BUILD b/sharing/BUILD index be3f6d7c..8e64046e 100644 --- a/sharing/BUILD +++ b/sharing/BUILD @@ -366,6 +366,7 @@ cc_library( "//sharing/common", "//sharing/common:enum", "//sharing/contacts", + "//sharing/contacts:contacts_interface", "//sharing/fast_initiation:nearby_fast_initiation", "//sharing/flags/generated:generated_flags", "//sharing/internal/api:platform", @@ -612,14 +613,12 @@ cc_test( "//sharing/certificates:test_support", "//sharing/common", "//sharing/common:enum", - "//sharing/contacts", "//sharing/contacts:test_support", "//sharing/fast_initiation:nearby_fast_initiation", "//sharing/fast_initiation:test_support", "//sharing/flags/generated:generated_flags", "//sharing/internal/api:mock_sharing_platform", "//sharing/internal/api:platform", - "//sharing/internal/public:types", "//sharing/internal/test:nearby_test", "//sharing/local_device_data", "//sharing/local_device_data:test_support", diff --git a/sharing/certificates/BUILD b/sharing/certificates/BUILD index 53cc8bd1..6ee757bc 100644 --- a/sharing/certificates/BUILD +++ b/sharing/certificates/BUILD @@ -124,13 +124,12 @@ cc_test( ":test_support", "//internal/platform:mac_address", "//internal/platform/implementation:account_manager", - "//internal/platform/implementation:platform_impl", # fixdeps: keep + "//internal/platform/implementation:platform_impl", "//internal/test", "//proto/identity/v1:resources_cc_proto", "//proto/identity/v1:rpcs_cc_proto", "//sharing/common", "//sharing/common:enum", - "//sharing/contacts:test_support", "//sharing/internal/api:mock_sharing_platform", "//sharing/internal/api:platform", "//sharing/internal/public:pref_names", diff --git a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc index db73fa61..2624f568 100644 --- a/sharing/certificates/nearby_share_certificate_manager_impl_test.cc +++ b/sharing/certificates/nearby_share_certificate_manager_impl_test.cc @@ -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/contacts/fake_nearby_share_contact_manager.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" @@ -114,7 +113,6 @@ class NearbyShareCertificateManagerImplTest local_device_data_manager_ = std::make_unique( kDefaultDeviceName); - contact_manager_ = std::make_unique(); AccountManager::Account account{ .display_name = GetNearbyShareTestMetadata().full_name(), @@ -501,7 +499,6 @@ class NearbyShareCertificateManagerImplTest FakeNearbyShareCertificateStorage::Factory cert_store_factory_; std::unique_ptr local_device_data_manager_; - std::unique_ptr contact_manager_; std::unique_ptr cert_manager_; }; diff --git a/sharing/contacts/BUILD b/sharing/contacts/BUILD index 757b8666..d2848a3e 100644 --- a/sharing/contacts/BUILD +++ b/sharing/contacts/BUILD @@ -17,60 +17,49 @@ load("@rules_cc//cc:cc_test.bzl", "cc_test") licenses(["notice"]) +cc_library( + name = "contacts_interface", + hdrs = [ + "nearby_share_contact_manager.h", + ], + visibility = ["//visibility:public"], + deps = [ + "//sharing/proto:share_cc_proto", + "@com_google_absl//absl/functional:any_invocable", + "@com_google_absl//absl/status:statusor", + ], +) + cc_library( name = "contacts", srcs = [ - "nearby_share_contact_manager.cc", "nearby_share_contact_manager_impl.cc", ], hdrs = [ - "nearby_share_contact_manager.h", "nearby_share_contact_manager_impl.h", ], visibility = ["//visibility:public"], deps = [ - "//internal/base", - "//internal/crypto_cros", - "//internal/flags:nearby_flags", + ":contacts_interface", "//internal/platform:types", "//internal/platform/implementation:account_manager", - "//sharing/common", - "//sharing/flags/generated:generated_flags", "//sharing/internal/api:platform", - "//sharing/internal/base", "//sharing/internal/public:logging", "//sharing/internal/public:types", - "//sharing/local_device_data", "//sharing/proto:share_cc_proto", - "//sharing/scheduling", - "@com_google_absl//absl/functional:any_invocable", - "@com_google_absl//absl/functional:bind_front", - "@com_google_absl//absl/memory", "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", - "@com_google_absl//absl/time", ], ) cc_library( name = "test_support", testonly = True, - srcs = [ - "fake_nearby_share_contact_manager.cc", - ], hdrs = [ "fake_nearby_share_contact_manager.h", ], visibility = ["//visibility:public"], - deps = [ - ":contacts", - "//internal/platform/implementation:account_manager", - "//internal/platform/implementation:types", - "//sharing/internal/api:platform", - "//sharing/internal/public:types", - "//sharing/local_device_data", - ], + deps = [":contacts_interface"], ) cc_test( @@ -83,20 +72,11 @@ cc_test( "//internal/platform/implementation:account_manager", "//internal/platform/implementation:platform_impl", "//internal/test", - "//sharing/common", "//sharing/internal/api:mock_sharing_platform", - "//sharing/internal/api:platform", "//sharing/internal/test:nearby_test", "//sharing/local_device_data:test_support", "//sharing/proto:share_cc_proto", - "//sharing/scheduling", - "//sharing/scheduling:test_support", "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_absl//absl/container:flat_hash_map", - "@com_google_absl//absl/container:flat_hash_set", - "@com_google_absl//absl/status", - "@com_google_absl//absl/status:statusor", - "@com_google_absl//absl/strings", "@com_google_absl//absl/time", "@com_google_googletest//:gtest_main", ], diff --git a/sharing/contacts/fake_nearby_share_contact_manager.cc b/sharing/contacts/fake_nearby_share_contact_manager.cc deleted file mode 100644 index cfa6c92a..00000000 --- a/sharing/contacts/fake_nearby_share_contact_manager.cc +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2021-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/contacts/fake_nearby_share_contact_manager.h" - -#include -#include - -#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" - -namespace nearby { -namespace sharing { - -FakeNearbyShareContactManager::Factory::Factory() = default; - -FakeNearbyShareContactManager::Factory::~Factory() = default; - -std::unique_ptr -FakeNearbyShareContactManager::Factory::CreateInstance( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory) { - latest_nearby_client_factory_ = nearby_client_factory; - latest_account_manager_ = &account_manager; - - auto instance = std::make_unique(); - instances_.push_back(instance.get()); - - return instance; -} - -FakeNearbyShareContactManager::FakeNearbyShareContactManager() = default; - -FakeNearbyShareContactManager::~FakeNearbyShareContactManager() = default; - -void FakeNearbyShareContactManager::GetContacts(ContactsCallback callback) {} - -} // namespace sharing -} // namespace nearby diff --git a/sharing/contacts/fake_nearby_share_contact_manager.h b/sharing/contacts/fake_nearby_share_contact_manager.h index 0ed9da3c..d52d0820 100644 --- a/sharing/contacts/fake_nearby_share_contact_manager.h +++ b/sharing/contacts/fake_nearby_share_contact_manager.h @@ -15,68 +15,19 @@ #ifndef THIRD_PARTY_NEARBY_SHARING_CONTACTS_FAKE_NEARBY_SHARE_CONTACT_MANAGER_H_ #define THIRD_PARTY_NEARBY_SHARING_CONTACTS_FAKE_NEARBY_SHARE_CONTACT_MANAGER_H_ -#include - -#include -#include - -#include "internal/platform/implementation/account_manager.h" #include "sharing/contacts/nearby_share_contact_manager.h" -#include "sharing/contacts/nearby_share_contact_manager_impl.h" -#include "sharing/internal/api/sharing_rpc_client.h" -#include "sharing/internal/public/context.h" namespace nearby { namespace sharing { -// A fake implementation of NearbyShareContactManager, along with a fake -// factory, to be used in tests. Stores parameters input into -// NearbyShareContactManager method calls. Use the notification methods from the -// base class--NotifyContactsDownloaded() and NotifyContactsUploaded()--to alert -// observers of changes; these methods are made public in this fake class. +// A fake implementation of NearbyShareContactManager. class FakeNearbyShareContactManager : public NearbyShareContactManager { public: - // Factory that creates FakeNearbyShareContactManager instances. Use in - // NearbyShareContactManagerImpl::Factor::SetFactoryForTesting() in unit - // tests. - class Factory : public NearbyShareContactManagerImpl::Factory { - public: - Factory(); - ~Factory() override; - - // Returns all FakeNearbyShareContactManager instances created by - // CreateInstance(). - std::vector& instances() { - return instances_; - } - - nearby::sharing::api::SharingRpcClientFactory* latest_http_client_factory() - const { - return latest_nearby_client_factory_; - } - - AccountManager* latest_account_manager() const { - return latest_account_manager_; - } - - private: - // NearbyShareContactManagerImpl::Factory: - std::unique_ptr CreateInstance( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory) - override; - - std::vector instances_; - nearby::sharing::api::SharingRpcClientFactory* - latest_nearby_client_factory_ = nullptr; - AccountManager* latest_account_manager_ = nullptr; - }; - - FakeNearbyShareContactManager(); - ~FakeNearbyShareContactManager() override; + FakeNearbyShareContactManager() = default; + ~FakeNearbyShareContactManager() override = default; private: - void GetContacts(ContactsCallback callback) override; + void GetContacts(ContactsCallback callback) override {}; }; } // namespace sharing diff --git a/sharing/contacts/nearby_share_contact_manager.cc b/sharing/contacts/nearby_share_contact_manager.cc deleted file mode 100644 index f502b8de..00000000 --- a/sharing/contacts/nearby_share_contact_manager.cc +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2021-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/contacts/nearby_share_contact_manager.h" - -#include - -#include "sharing/proto/rpc_resources.pb.h" - -namespace nearby { -namespace sharing { - -NearbyShareContactManager::NearbyShareContactManager() = default; - -NearbyShareContactManager::~NearbyShareContactManager() = default; - -} // namespace sharing -} // namespace nearby diff --git a/sharing/contacts/nearby_share_contact_manager.h b/sharing/contacts/nearby_share_contact_manager.h index 54ee91c3..81bf5f17 100644 --- a/sharing/contacts/nearby_share_contact_manager.h +++ b/sharing/contacts/nearby_share_contact_manager.h @@ -26,27 +26,15 @@ namespace nearby { namespace sharing { -// The Nearby Share contacts manager interfaces with the Nearby server in the -// following ways: -// 1) The user's contacts are downloaded from People API, using the Nearby -// server as a proxy. -// 2) All the user's contacts are uploaded to Nearby server, along with an -// indication of what contacts are allowed for selected-contacts visibility -// mode. The Nearby server will distribute all-contacts visibility -// certificates accordingly. For privacy reasons, the Nearby server needs to -// explicitly receive the list of contacts from the device instead of pulling -// them directly from People API. -// -// All contact data and update notifications are conveyed via observer methods; -// the manager does not return data directly from function calls. +// The Nearby Share contacts manager retrieves the user's contact list from the +// server. class NearbyShareContactManager { public: using ContactsCallback = absl::AnyInvocable< void(absl::StatusOr>, uint32_t num_unreachable_contacts_filtered_out) &&>; - NearbyShareContactManager(); - virtual ~NearbyShareContactManager(); + virtual ~NearbyShareContactManager() = default; // Retrieves the user's contact list from the server. virtual void GetContacts(ContactsCallback callback) = 0; diff --git a/sharing/contacts/nearby_share_contact_manager_impl.cc b/sharing/contacts/nearby_share_contact_manager_impl.cc index 8ad1dc7f..dfa1c28f 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl.cc +++ b/sharing/contacts/nearby_share_contact_manager_impl.cc @@ -23,7 +23,6 @@ #include #include -#include "absl/memory/memory.h" #include "absl/status/statusor.h" #include "absl/synchronization/notification.h" #include "internal/platform/implementation/account_manager.h" @@ -42,53 +41,32 @@ using ::nearby::sharing::proto::ContactRecord; using ::nearby::sharing::proto::ListContactPeopleRequest; using ::nearby::sharing::proto::ListContactPeopleResponse; -void FilterOutUnreachableContacts(std::vector& contacts) { - contacts.erase( - std::remove_if(contacts.begin(), contacts.end(), - [](const nearby::sharing::proto::ContactRecord& contact) { - return !contact.is_reachable(); - }), - contacts.end()); -} +// Class for maintaining a single instance of contacts download request. It +// is responsible for downloading all available pages and making the results +// or error available. +class ContactDownloadContext { + public: + ContactDownloadContext( + nearby::sharing::api::SharingRpcClient* nearby_share_client, + NearbyShareContactManager::ContactsCallback download_callback) + : nearby_share_client_(nearby_share_client), + download_callback_(std::move(download_callback)) {} -} // namespace + // Fetches the next page of contacts. + // If |next_page_token_| is empty, it fetches the first page. + // On successful download, if page token in the response is empty, the + // |download_callback_| is invoked with all downloaded contacts. + void FetchNextPage(); -// static -NearbyShareContactManagerImpl::Factory* - NearbyShareContactManagerImpl::Factory::test_factory_ = nullptr; + private: + nearby::sharing::api::SharingRpcClient* const nearby_share_client_; + std::optional next_page_token_; + int page_number_ = 1; + std::vector contacts_; + NearbyShareContactManager::ContactsCallback download_callback_; +}; -// static -std::unique_ptr -NearbyShareContactManagerImpl::Factory::Create( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory) { - if (test_factory_) { - return test_factory_->CreateInstance(context, account_manager, - nearby_client_factory); - } - - return absl::WrapUnique(new NearbyShareContactManagerImpl( - context, account_manager, nearby_client_factory)); -} - -// static -void NearbyShareContactManagerImpl::Factory::SetFactoryForTesting( - Factory* test_factory) { - test_factory_ = test_factory; -} - -NearbyShareContactManagerImpl::Factory::~Factory() = default; - -NearbyShareContactManagerImpl::NearbyShareContactManagerImpl( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory) - : account_manager_(account_manager), - nearby_share_client_(nearby_client_factory->CreateInstance()), - executor_(context->CreateSequencedTaskRunner()) {} - -NearbyShareContactManagerImpl::~NearbyShareContactManagerImpl() = default; - -void NearbyShareContactManagerImpl::ContactDownloadContext::FetchNextPage() { +void ContactDownloadContext::FetchNextPage() { LOG(INFO) << "Downloading contacts page=" << page_number_++; ListContactPeopleRequest request; if (next_page_token_.has_value()) { @@ -112,7 +90,12 @@ void NearbyShareContactManagerImpl::ContactDownloadContext::FetchNextPage() { // We should filter here because we only care about contacts that we // can share with. uint32_t contacts_size = contacts_.size(); - FilterOutUnreachableContacts(contacts_); + // Filter out unreachable contacts. + contacts_.erase(std::remove_if(contacts_.begin(), contacts_.end(), + [](const ContactRecord& contact) { + return !contact.is_reachable(); + }), + contacts_.end()); uint32_t num_unreachable_contacts_filtered_out = contacts_size - contacts_.size(); std::move(download_callback_)(std::move(contacts_), @@ -125,6 +108,15 @@ void NearbyShareContactManagerImpl::ContactDownloadContext::FetchNextPage() { }); } +} // namespace + +NearbyShareContactManagerImpl::NearbyShareContactManagerImpl( + Context* context, AccountManager& account_manager, + nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory) + : account_manager_(account_manager), + nearby_share_client_(nearby_client_factory->CreateInstance()), + executor_(context->CreateSequencedTaskRunner()) {} + void NearbyShareContactManagerImpl::GetContacts(ContactsCallback callback) { executor_->PostTask([this, callback = std::move(callback)]() mutable { LOG(INFO) << "Start downloading contacts"; diff --git a/sharing/contacts/nearby_share_contact_manager_impl.h b/sharing/contacts/nearby_share_contact_manager_impl.h index d31f2374..e6ad10bc 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl.h +++ b/sharing/contacts/nearby_share_contact_manager_impl.h @@ -15,94 +15,26 @@ #ifndef THIRD_PARTY_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACT_MANAGER_IMPL_H_ #define THIRD_PARTY_NEARBY_SHARING_CONTACTS_NEARBY_SHARE_CONTACT_MANAGER_IMPL_H_ -#include - #include -#include -#include -#include -#include #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" -#include "sharing/proto/rpc_resources.pb.h" namespace nearby { namespace sharing { -// Implementation of NearbyShareContactManager that persists the set of allowed -// contact IDs--for selected-contacts visibility mode--in prefs. Other -// contact data is downloaded from People API, via the NearbyShare server, as -// needed. -// -// The Nearby Share server must be explicitly informed of all contacts this -// device is aware of--needed for all-contacts visibility mode--as well as what -// contacts are allowed for selected-contacts visibility mode. These uploaded -// contact lists are used by the server to distribute the device's public -// certificates accordingly. This implementation persists a hash of the last -// uploaded contact data, and after every contacts download, a subsequent upload -// request is made if we detect that the contact list or allowlist has changed -// since the last successful upload. We also schedule periodic contact uploads -// just in case the server removed the record. -// -// In addition to supporting on-demand contact downloads, this implementation -// periodically checks in with the Nearby Share server to see if the user's -// contact list has changed since the last upload. class NearbyShareContactManagerImpl : public NearbyShareContactManager { public: - class Factory { - public: - static std::unique_ptr Create( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory); - static void SetFactoryForTesting(Factory* test_factory); - - protected: - virtual ~Factory(); - virtual std::unique_ptr CreateInstance( - Context* context, AccountManager& account_manager, - nearby::sharing::api::SharingRpcClientFactory* - nearby_client_factory) = 0; - - private: - static Factory* test_factory_; - }; - - ~NearbyShareContactManagerImpl() override; - - private: - // Class for maintaining a single instance of contacts download request. It - // is responsible for downloading all available pages and making the results - // or error available. - class ContactDownloadContext { - public: - ContactDownloadContext( - nearby::sharing::api::SharingRpcClient* nearby_share_client, - ContactsCallback download_callback) - : nearby_share_client_(nearby_share_client), - download_callback_(std::move(download_callback)) {} - - // Fetches the next page of contacts. - // If |next_page_token_| is empty, it fetches the first page. - // On successful download, if page token in the response is empty, the - // |download_callback_| is invoked with all downloaded contacts. - void FetchNextPage(); - - private: - nearby::sharing::api::SharingRpcClient* const nearby_share_client_; - std::optional next_page_token_; - int page_number_ = 1; - std::vector contacts_; - ContactsCallback download_callback_; - }; - NearbyShareContactManagerImpl( Context* context, AccountManager& account_manager, nearby::sharing::api::SharingRpcClientFactory* nearby_client_factory); + ~NearbyShareContactManagerImpl() override = default; + + private: // NearbyShareContactsManager: void GetContacts(ContactsCallback callback) override; diff --git a/sharing/contacts/nearby_share_contact_manager_impl_test.cc b/sharing/contacts/nearby_share_contact_manager_impl_test.cc index 870f7c00..e9f5d345 100644 --- a/sharing/contacts/nearby_share_contact_manager_impl_test.cc +++ b/sharing/contacts/nearby_share_contact_manager_impl_test.cc @@ -26,14 +26,11 @@ #include "absl/time/time.h" #include "internal/platform/implementation/account_manager.h" #include "internal/test/fake_account_manager.h" -#include "sharing/contacts/nearby_share_contact_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" #include "sharing/proto/rpc_resources.pb.h" -#include "sharing/scheduling/fake_nearby_share_scheduler_factory.h" -#include "sharing/scheduling/nearby_share_scheduler_factory.h" namespace nearby::sharing { namespace { @@ -61,19 +58,17 @@ class NearbyShareContactManagerImplTest ~NearbyShareContactManagerImplTest() override = default; void SetUp() override { - NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_); AccountManager::Account account; account.id = kTestAccountId; account.email = kTestProfileUserName; fake_account_manager_.SetAccount(account); - manager_ = NearbyShareContactManagerImpl::Factory::Create( + manager_ = std::make_unique( &fake_context_, fake_account_manager_, &nearby_client_factory_); } void TearDown() override { manager_.reset(); - NearbyShareSchedulerFactory::SetFactoryForTesting(nullptr); } void Sync() { @@ -101,8 +96,7 @@ class NearbyShareContactManagerImplTest FakeNearbyShareClientFactory nearby_client_factory_; FakeNearbyShareLocalDeviceDataManager local_device_data_manager_; std::unique_ptr account_manager_; - FakeNearbyShareSchedulerFactory scheduler_factory_; - std::unique_ptr manager_; + std::unique_ptr manager_; }; } // namespace diff --git a/sharing/nearby_sharing_service_factory.cc b/sharing/nearby_sharing_service_factory.cc index d0770162..01afe82c 100644 --- a/sharing/nearby_sharing_service_factory.cc +++ b/sharing/nearby_sharing_service_factory.cc @@ -14,13 +14,13 @@ #include "sharing/nearby_sharing_service_factory.h" -#include #include #include #include "internal/analytics/event_logger.h" #include "internal/platform/task_runner.h" #include "sharing/analytics/analytics_recorder.h" +#include "sharing/contacts/nearby_share_contact_manager_impl.h" #include "sharing/internal/api/sharing_platform.h" #include "sharing/internal/public/context_impl.h" #include "sharing/nearby_connections_manager_factory.h" @@ -54,9 +54,19 @@ NearbySharingService* NearbySharingServiceFactory::CreateSharingService( service_thread.get(), context_.get(), sharing_platform.GetDeviceInfo(), event_logger); + auto nearby_share_client_factory = + sharing_platform.CreateSharingRpcClientFactory(context_->GetClock(), + analytics_recorder); + auto nearby_share_contact_manager = + std::make_unique( + context_.get(), sharing_platform.GetAccountManager(), + nearby_share_client_factory.get()); + nearby_sharing_service_ = std::make_unique( std::move(service_thread), context_.get(), sharing_platform, - std::move(nearby_connections_manager), analytics_recorder); + std::move(nearby_share_client_factory), + std::move(nearby_connections_manager), + std::move(nearby_share_contact_manager), analytics_recorder); return nearby_sharing_service_.get(); } diff --git a/sharing/nearby_sharing_service_impl.cc b/sharing/nearby_sharing_service_impl.cc index 4d576622..d9686fe4 100644 --- a/sharing/nearby_sharing_service_impl.cc +++ b/sharing/nearby_sharing_service_impl.cc @@ -63,7 +63,6 @@ #include "sharing/common/nearby_share_prefs.h" #include "sharing/constants.h" #include "sharing/contacts/nearby_share_contact_manager.h" -#include "sharing/contacts/nearby_share_contact_manager_impl.h" #include "sharing/fast_initiation/nearby_fast_initiation.h" #include "sharing/fast_initiation/nearby_fast_initiation_impl.h" #include "sharing/file_attachment.h" @@ -72,6 +71,7 @@ #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" @@ -112,6 +112,7 @@ using ::location::nearby::proto::sharing::OSType; using ::location::nearby::proto::sharing::ResponseToIntroduction; using ::location::nearby::proto::sharing::SessionStatus; using ::nearby::sharing::api::SharingPlatform; +using ::nearby::sharing::api::SharingRpcClientFactory; using ::nearby::sharing::proto::DataUsage; using ::nearby::sharing::proto::DeviceVisibility; using ::nearby::sharing::service::proto::ConnectionResponseFrame; @@ -212,7 +213,9 @@ std::string GenerateDeviceId() { NearbySharingServiceImpl::NearbySharingServiceImpl( std::unique_ptr service_thread, Context* context, SharingPlatform& sharing_platform, + std::unique_ptr nearby_share_client_factory, std::unique_ptr nearby_connections_manager, + std::unique_ptr contact_manager, analytics::AnalyticsRecorder* analytics_recorder) : service_thread_(std::move(service_thread)), context_(context), @@ -221,14 +224,11 @@ NearbySharingServiceImpl::NearbySharingServiceImpl( account_manager_(sharing_platform.GetAccountManager()), analytics_recorder_(*analytics_recorder), nearby_connections_manager_(std::move(nearby_connections_manager)), - nearby_share_client_factory_( - sharing_platform.CreateSharingRpcClientFactory(context_->GetClock(), - &analytics_recorder_)), + nearby_share_client_factory_(std::move(nearby_share_client_factory)), local_device_data_manager_( NearbyShareLocalDeviceDataManagerImpl::Factory::Create( preference_manager_, account_manager_, device_info_)), - contact_manager_(NearbyShareContactManagerImpl::Factory::Create( - context_, account_manager_, nearby_share_client_factory_.get())), + contact_manager_(std::move(contact_manager)), nearby_fast_initiation_( NearbyFastInitiationImpl::Factory::Create(context_)), settings_(std::make_unique( diff --git a/sharing/nearby_sharing_service_impl.h b/sharing/nearby_sharing_service_impl.h index 2abf26e1..b488abab 100644 --- a/sharing/nearby_sharing_service_impl.h +++ b/sharing/nearby_sharing_service_impl.h @@ -102,7 +102,10 @@ class NearbySharingServiceImpl NearbySharingServiceImpl( std::unique_ptr service_thread, Context* context, nearby::sharing::api::SharingPlatform& sharing_platform, + std::unique_ptr + nearby_share_client_factory, std::unique_ptr nearby_connections_manager, + std::unique_ptr contact_manager, analytics::AnalyticsRecorder* analytics_recorder); ~NearbySharingServiceImpl() override; diff --git a/sharing/nearby_sharing_service_impl_test.cc b/sharing/nearby_sharing_service_impl_test.cc index d2aaded4..f98550a9 100644 --- a/sharing/nearby_sharing_service_impl_test.cc +++ b/sharing/nearby_sharing_service_impl_test.cc @@ -64,7 +64,6 @@ #include "sharing/common/nearby_share_prefs.h" #include "sharing/constants.h" #include "sharing/contacts/fake_nearby_share_contact_manager.h" -#include "sharing/contacts/nearby_share_contact_manager_impl.h" #include "sharing/fake_nearby_connections_manager.h" #include "sharing/fast_initiation/fake_nearby_fast_initiation.h" #include "sharing/fast_initiation/nearby_fast_initiation_impl.h" @@ -408,8 +407,6 @@ class NearbySharingServiceImplTest : public testing::Test { .WillOnce(Return(std::move(mock_app_info))); NearbyShareLocalDeviceDataManagerImpl::Factory::SetFactoryForTesting( &local_device_data_manager_factory_); - NearbyShareContactManagerImpl::Factory::SetFactoryForTesting( - &contact_manager_factory_); NearbyShareCertificateManagerImpl::Factory::SetFactoryForTesting( &certificate_manager_factory_); nearby_fast_initiation_factory_ = @@ -424,6 +421,7 @@ class NearbySharingServiceImplTest : public testing::Test { auto fake_task_runner = std::make_unique(fake_context_.fake_clock(), 1); sharing_service_task_runner_ = fake_task_runner.get(); + contact_manager_ = new FakeNearbyShareContactManager(); fake_nearby_connections_manager_ = new FakeNearbyConnectionsManager(); connection_ = std::make_unique(fake_device_info_); fake_nearby_connections_manager_->set_send_payload_callback( @@ -463,7 +461,6 @@ class NearbySharingServiceImplTest : public testing::Test { true); NearbyShareLocalDeviceDataManagerImpl::Factory::SetFactoryForTesting( nullptr); - NearbyShareContactManagerImpl::Factory::SetFactoryForTesting(nullptr); NearbyShareCertificateManagerImpl::Factory::SetFactoryForTesting(nullptr); NearbyFlags::GetInstance().ResetOverridedValues(); nearby_fast_initiation_factory_.reset(); @@ -480,7 +477,9 @@ class NearbySharingServiceImplTest : public testing::Test { std::unique_ptr task_runner) { return std::make_unique( std::move(task_runner), &fake_context_, mock_sharing_platform_, + /*nearby_share_client_factory=*/nullptr, absl::WrapUnique(fake_nearby_connections_manager_), + absl::WrapUnique(contact_manager_), analytics_recorder_.get()); } @@ -1257,7 +1256,7 @@ class NearbySharingServiceImplTest : public testing::Test { FakeNearbyConnectionsManager* fake_nearby_connections_manager_ = nullptr; FakeNearbyShareLocalDeviceDataManager::Factory local_device_data_manager_factory_; - FakeNearbyShareContactManager::Factory contact_manager_factory_; + FakeNearbyShareContactManager* contact_manager_ = nullptr; FakeNearbyShareCertificateManager::Factory certificate_manager_factory_; std::unique_ptr nearby_fast_initiation_factory_;