diff --git a/internal/platform/device_info.h b/internal/platform/device_info.h index 8e913ad2..3cbb716f 100644 --- a/internal/platform/device_info.h +++ b/internal/platform/device_info.h @@ -34,7 +34,6 @@ class DeviceInfo { virtual std::string GetOsDeviceName() const = 0; virtual api::DeviceInfo::DeviceType GetDeviceType() const = 0; virtual api::DeviceInfo::OsType GetOsType() const = 0; - virtual std::optional GetGivenName() const = 0; virtual std::filesystem::path GetDownloadPath() const = 0; virtual std::filesystem::path GetAppDataPath() const = 0; diff --git a/internal/platform/device_info_impl.cc b/internal/platform/device_info_impl.cc index 915b91a9..f342dec4 100644 --- a/internal/platform/device_info_impl.cc +++ b/internal/platform/device_info_impl.cc @@ -43,10 +43,6 @@ api::DeviceInfo::OsType DeviceInfoImpl::GetOsType() const { return device_info_impl_->GetOsType(); } -std::optional DeviceInfoImpl::GetGivenName() const { - return device_info_impl_->GetGivenName(); -} - std::filesystem::path DeviceInfoImpl::GetDownloadPath() const { std::optional path = device_info_impl_->GetDownloadPath(); diff --git a/internal/platform/device_info_impl.h b/internal/platform/device_info_impl.h index eb50f3e7..efaa734d 100644 --- a/internal/platform/device_info_impl.h +++ b/internal/platform/device_info_impl.h @@ -38,8 +38,6 @@ class DeviceInfoImpl : public DeviceInfo { api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; - std::optional GetGivenName() const override; - std::filesystem::path GetDownloadPath() const override; std::filesystem::path GetAppDataPath() const override; std::filesystem::path GetTemporaryPath() const override; diff --git a/internal/platform/implementation/apple/device_info.h b/internal/platform/implementation/apple/device_info.h index 2a238989..de250744 100644 --- a/internal/platform/implementation/apple/device_info.h +++ b/internal/platform/implementation/apple/device_info.h @@ -34,8 +34,6 @@ class DeviceInfo : public api::DeviceInfo { api::DeviceInfo::OsType GetOsType() const override; - std::optional GetGivenName() const override; - std::optional GetDownloadPath() const override; std::optional GetLocalAppDataPath() const override; diff --git a/internal/platform/implementation/apple/device_info.mm b/internal/platform/implementation/apple/device_info.mm index 885ad93b..0e605df7 100644 --- a/internal/platform/implementation/apple/device_info.mm +++ b/internal/platform/implementation/apple/device_info.mm @@ -78,8 +78,6 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const { #endif } -std::optional DeviceInfo::GetGivenName() const { return std::nullopt; } - std::optional DeviceInfo::GetDownloadPath() const { NSFileManager *manager = [NSFileManager defaultManager]; diff --git a/internal/platform/implementation/device_info.h b/internal/platform/implementation/device_info.h index 05fc160f..8786d6b7 100644 --- a/internal/platform/implementation/device_info.h +++ b/internal/platform/implementation/device_info.h @@ -15,7 +15,7 @@ #ifndef PLATFORM_API_DEVICE_INFO_H_ #define PLATFORM_API_DEVICE_INFO_H_ -#include +#include // NOLINT #include #include #include @@ -45,9 +45,6 @@ class DeviceInfo { virtual DeviceType GetDeviceType() const = 0; virtual OsType GetOsType() const = 0; - // Gets basic information of current user. - virtual std::optional GetGivenName() const = 0; - // Gets known paths of current user. virtual std::optional GetDownloadPath() const = 0; virtual std::optional GetLocalAppDataPath() const = 0; diff --git a/internal/platform/implementation/g3/device_info.h b/internal/platform/implementation/g3/device_info.h index 9b2ad21b..49ed781c 100644 --- a/internal/platform/implementation/g3/device_info.h +++ b/internal/platform/implementation/g3/device_info.h @@ -42,10 +42,6 @@ class DeviceInfo : public api::DeviceInfo { return api::DeviceInfo::OsType::kChromeOs; } - std::optional GetGivenName() const override { - return "nearby"; - } - std::optional GetDownloadPath() const override { return std::filesystem::temp_directory_path(); } diff --git a/internal/platform/implementation/windows/device_info.cc b/internal/platform/implementation/windows/device_info.cc index cdb51c7b..390dea61 100644 --- a/internal/platform/implementation/windows/device_info.cc +++ b/internal/platform/implementation/windows/device_info.cc @@ -27,7 +27,6 @@ #include "absl/synchronization/mutex.h" #include "internal/base/files.h" #include "internal/platform/implementation/device_info.h" -#include "internal/platform/implementation/windows/generated/winrt/base.h" #include "internal/platform/implementation/windows/string_utils.h" #include "internal/platform/logging.h" #include "winrt/Windows.Foundation.Collections.h" @@ -89,48 +88,6 @@ api::DeviceInfo::OsType DeviceInfo::GetOsType() const { return api::DeviceInfo::OsType::kWindows; } -std::optional DeviceInfo::GetGivenName() const { - // FindAllAsync finds all users that are using this app. When we "Switch User" - // on Desktop,FindAllAsync() will still return the current user instead of all - // of them because the users who are switched out are not using the apps of - // the user who is switched in, so FindAllAsync() will not find them. (Under - // the UWP application model, each process runs under its own user account. - // That user account is different from the user account of the logged-in user. - // Processes aren't owned by the logged-in user for purposes of isolation.) - IVectorView users = - User::FindAllAsync(UserType::LocalUser, - UserAuthenticationStatus::LocallyAuthenticated) - .get(); - if (users == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving locally authenticated user."; - return std::nullopt; - } - - // On Windows Desktop apps, the first Windows.System.User instance - // returned in the IVectorView is always the current user. - // https://github.com/microsoft/Windows-task-snippets/blob/master/tasks/User-info.md - User current_user = users.GetAt(0); - - // Retrieve the human-readable properties for the current user - IAsyncOperation given_name_obj_async = - current_user.GetPropertyAsync(KnownUserProperties::FirstName()); - IInspectable given_name_obj = given_name_obj_async.get(); - if (given_name_obj == nullptr) { - LOG(ERROR) << __func__ << ": Error retrieving first name of user."; - return std::nullopt; - } - winrt::hstring given_name = given_name_obj.as(); - std::string given_name_str = winrt::to_string(given_name); - - if (given_name_str.empty()) { - LOG(ERROR) << __func__ - << ": Error unboxing string value for first name of user."; - return std::nullopt; - } - - return given_name_str; -} - std::optional DeviceInfo::GetDownloadPath() const { PWSTR path; HRESULT result = diff --git a/internal/platform/implementation/windows/device_info.h b/internal/platform/implementation/windows/device_info.h index dbd8153b..6d9de6a3 100644 --- a/internal/platform/implementation/windows/device_info.h +++ b/internal/platform/implementation/windows/device_info.h @@ -15,8 +15,10 @@ #ifndef PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_ #define PLATFORM_IMPL_WINDOWS_DEVICE_INFO_H_ +#include // NOLINT #include #include +#include #include "absl/base/thread_annotations.h" #include "absl/strings/string_view.h" @@ -34,7 +36,6 @@ class DeviceInfo : public api::DeviceInfo { std::optional GetOsDeviceName() const override; api::DeviceInfo::DeviceType GetDeviceType() const override; api::DeviceInfo::OsType GetOsType() const override; - std::optional GetGivenName() const override; std::optional GetDownloadPath() const override; std::optional GetLocalAppDataPath() const override; diff --git a/internal/platform/implementation/windows/device_info_test.cc b/internal/platform/implementation/windows/device_info_test.cc index 0fa23b26..6431e5ea 100644 --- a/internal/platform/implementation/windows/device_info_test.cc +++ b/internal/platform/implementation/windows/device_info_test.cc @@ -39,11 +39,6 @@ TEST(DeviceInfo, GetOsType) { EXPECT_EQ(DeviceInfo().GetOsType(), api::DeviceInfo::OsType::kWindows); } -TEST(DeviceInfo, DISABLED_GetGivenName) { - EXPECT_TRUE(DeviceInfo().GetGivenName().has_value()); -} - - TEST(DeviceInfo, DISABLED_GetLocalAppDataPath) { EXPECT_TRUE(DeviceInfo().GetLocalAppDataPath().has_value()); } diff --git a/internal/test/fake_device_info.h b/internal/test/fake_device_info.h index b6975d93..b7349a29 100644 --- a/internal/test/fake_device_info.h +++ b/internal/test/fake_device_info.h @@ -40,10 +40,6 @@ class FakeDeviceInfo : public DeviceInfo { api::DeviceInfo::OsType GetOsType() const override { return os_type_; } - std::optional GetGivenName() const override { - return given_name_; - } - std::filesystem::path GetDownloadPath() const override { return download_path_; } @@ -96,14 +92,6 @@ class FakeDeviceInfo : public DeviceInfo { void SetOsType(api::DeviceInfo::OsType os_type) { os_type_ = os_type; } - void SetGivenName(std::optional given_name) { - if (given_name.has_value() && !given_name->empty()) { - given_name_ = given_name; - } else { - given_name_ = std::nullopt; - } - } - void SetDownloadPath(std::filesystem::path path) { download_path_ = path; } void SetAppDataPath(std::filesystem::path path) { app_data_path_ = path; } @@ -133,7 +121,6 @@ class FakeDeviceInfo : public DeviceInfo { api::DeviceInfo::DeviceType device_type_ = api::DeviceInfo::DeviceType::kLaptop; api::DeviceInfo::OsType os_type_ = api::DeviceInfo::OsType::kWindows; - std::optional given_name_ = "Nearby"; std::filesystem::path download_path_ = std::filesystem::temp_directory_path(); std::filesystem::path app_data_path_ = std::filesystem::temp_directory_path(); std::filesystem::path temp_path_ = std::filesystem::temp_directory_path(); diff --git a/internal/test/fake_device_info_test.cc b/internal/test/fake_device_info_test.cc index 05449289..7c575c52 100644 --- a/internal/test/fake_device_info_test.cc +++ b/internal/test/fake_device_info_test.cc @@ -43,14 +43,6 @@ TEST(FakeDeviceInfo, OsType) { EXPECT_EQ(device_info.GetOsType(), api::DeviceInfo::OsType::kWindows); } -TEST(FakeDeviceInfo, GivenName) { - FakeDeviceInfo device_info; - device_info.SetGivenName("windows"); - EXPECT_EQ(device_info.GetGivenName(), "windows"); - device_info.SetGivenName(std::nullopt); - EXPECT_FALSE(device_info.GetGivenName().has_value()); -} - TEST(FakeDeviceInfo, GetDownloadPath) { FakeDeviceInfo device_info; EXPECT_EQ(device_info.GetDownloadPath(), diff --git a/sharing/BUILD b/sharing/BUILD index eff7f304..bea9515a 100644 --- a/sharing/BUILD +++ b/sharing/BUILD @@ -247,7 +247,6 @@ cc_library( "nearby_connections_service.cc", "nearby_connections_service_impl.cc", "nearby_connections_stream_buffer_manager.cc", - "nearby_share_profile_info_provider_impl.cc", "nearby_sharing_service.cc", "nearby_sharing_service_factory.cc", "nearby_sharing_service_impl.cc", @@ -264,7 +263,6 @@ cc_library( "nearby_connections_service.h", "nearby_connections_service_impl.h", "nearby_connections_stream_buffer_manager.h", - "nearby_share_profile_info_provider_impl.h", "nearby_sharing_service.h", "nearby_sharing_service_extension.h", "nearby_sharing_service_factory.h", @@ -627,19 +625,6 @@ cc_test( ], ) -cc_test( - name = "nearby_share_profile_info_provider_impl_test", - srcs = ["nearby_share_profile_info_provider_impl_test.cc"], - deps = [ - ":nearby_sharing_service", - "//internal/platform/implementation:account_manager", - "//internal/platform/implementation/g3", # fixdeps: keep - "//internal/test", - "@com_github_protobuf_matchers//protobuf-matchers", - "@com_google_googletest//:gtest_main", - ], -) - cc_test( name = "nearby_sharing_service_extension_test", srcs = ["nearby_sharing_service_extension_test.cc"], diff --git a/sharing/common/BUILD b/sharing/common/BUILD index f0cc2b86..5e6e365e 100644 --- a/sharing/common/BUILD +++ b/sharing/common/BUILD @@ -22,7 +22,6 @@ cc_library( ], hdrs = [ "nearby_share_prefs.h", - "nearby_share_profile_info_provider.h", "nearby_share_switches.h", ], visibility = ["//visibility:public"], @@ -35,20 +34,6 @@ cc_library( ], ) -cc_library( - name = "test_support", - testonly = True, - srcs = [ - "fake_nearby_share_profile_info_provider.cc", - ], - hdrs = [ - "fake_nearby_share_profile_info_provider.h", - "nearby_share_profile_info_provider.h", - ], - visibility = ["//visibility:public"], - deps = [], -) - cc_library( name = "enum", hdrs = ["nearby_share_enums.h"], diff --git a/sharing/common/fake_nearby_share_profile_info_provider.cc b/sharing/common/fake_nearby_share_profile_info_provider.cc deleted file mode 100644 index e0290a90..00000000 --- a/sharing/common/fake_nearby_share_profile_info_provider.cc +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2021 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/common/fake_nearby_share_profile_info_provider.h" - -#include -#include - -namespace nearby { -namespace sharing { - -FakeNearbyShareProfileInfoProvider::FakeNearbyShareProfileInfoProvider() = - default; - -FakeNearbyShareProfileInfoProvider::~FakeNearbyShareProfileInfoProvider() = - default; - -std::optional FakeNearbyShareProfileInfoProvider::GetGivenName() - const { - return given_name_; -} - -} // namespace sharing -} // namespace nearby diff --git a/sharing/common/fake_nearby_share_profile_info_provider.h b/sharing/common/fake_nearby_share_profile_info_provider.h deleted file mode 100644 index 14ba91fa..00000000 --- a/sharing/common/fake_nearby_share_profile_info_provider.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2021 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_COMMON_FAKE_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ -#define THIRD_PARTY_NEARBY_SHARING_COMMON_FAKE_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ - -#include -#include - -#include "sharing/common/nearby_share_profile_info_provider.h" - -namespace nearby { -namespace sharing { - -class FakeNearbyShareProfileInfoProvider - : public NearbyShareProfileInfoProvider { - public: - FakeNearbyShareProfileInfoProvider(); - ~FakeNearbyShareProfileInfoProvider() override; - - // NearbyShareProfileInfoProvider: - std::optional GetGivenName() const override; - - void set_given_name(const std::optional& given_name) { - given_name_ = given_name; - } - - private: - std::optional given_name_; -}; - -} // namespace sharing -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_SHARING_COMMON_FAKE_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ diff --git a/sharing/common/nearby_share_profile_info_provider.h b/sharing/common/nearby_share_profile_info_provider.h deleted file mode 100644 index 8cb28f17..00000000 --- a/sharing/common/nearby_share_profile_info_provider.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2021 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_COMMON_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ -#define THIRD_PARTY_NEARBY_SHARING_COMMON_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ - -#include -#include - -namespace nearby { -namespace sharing { -class NearbyShareProfileInfoProvider { - public: - NearbyShareProfileInfoProvider() = default; - virtual ~NearbyShareProfileInfoProvider() = default; - - // Returns UTF-8 encoded given name of current account. - // Returns absl::nullopt if a valid given name cannot be returned. - virtual std::optional GetGivenName() const = 0; -}; -} // namespace sharing -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_SHARING_COMMON_NEARBY_SHARE_PROFILE_INFO_PROVIDER_H_ diff --git a/sharing/local_device_data/BUILD b/sharing/local_device_data/BUILD index 1af8a627..46f9a213 100644 --- a/sharing/local_device_data/BUILD +++ b/sharing/local_device_data/BUILD @@ -79,7 +79,6 @@ cc_test( "//internal/test", "//sharing/common", "//sharing/common:enum", - "//sharing/common:test_support", "//sharing/internal/api:mock_sharing_platform", "//sharing/internal/test:nearby_test", "//sharing/proto:share_cc_proto", diff --git a/sharing/local_device_data/fake_nearby_share_local_device_data_manager.cc b/sharing/local_device_data/fake_nearby_share_local_device_data_manager.cc index abd347d8..cd623735 100644 --- a/sharing/local_device_data/fake_nearby_share_local_device_data_manager.cc +++ b/sharing/local_device_data/fake_nearby_share_local_device_data_manager.cc @@ -31,7 +31,6 @@ namespace nearby { namespace sharing { class NearbyShareClientFactory; -class NearbyShareProfileInfoProvider; namespace { @@ -48,10 +47,8 @@ FakeNearbyShareLocalDeviceDataManager::Factory::~Factory() = default; std::unique_ptr FakeNearbyShareLocalDeviceDataManager::Factory::CreateInstance( - nearby::Context* context, SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider) { + nearby::Context* context, SharingRpcClientFactory* rpc_client_factory) { latest_rpc_client_factory_ = rpc_client_factory; - latest_profile_info_provider_ = profile_info_provider; auto instance = std::make_unique( kDefaultDeviceName); diff --git a/sharing/local_device_data/fake_nearby_share_local_device_data_manager.h b/sharing/local_device_data/fake_nearby_share_local_device_data_manager.h index 35cac526..f7ba4bb2 100644 --- a/sharing/local_device_data/fake_nearby_share_local_device_data_manager.h +++ b/sharing/local_device_data/fake_nearby_share_local_device_data_manager.h @@ -57,21 +57,16 @@ class FakeNearbyShareLocalDeviceDataManager return latest_rpc_client_factory_; } - NearbyShareProfileInfoProvider* latest_profile_info_provider() const { - return latest_profile_info_provider_; - } - protected: std::unique_ptr CreateInstance( nearby::Context* context, - nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider) override; + nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory) + override; private: std::vector instances_; nearby::sharing::api::SharingRpcClientFactory* latest_rpc_client_factory_ = nullptr; - NearbyShareProfileInfoProvider* latest_profile_info_provider_ = nullptr; }; struct UploadContactsCall { diff --git a/sharing/local_device_data/nearby_share_local_device_data_manager_impl.cc b/sharing/local_device_data/nearby_share_local_device_data_manager_impl.cc index 49366ec6..d17ae98a 100644 --- a/sharing/local_device_data/nearby_share_local_device_data_manager_impl.cc +++ b/sharing/local_device_data/nearby_share_local_device_data_manager_impl.cc @@ -37,7 +37,6 @@ #include "internal/platform/implementation/device_info.h" #include "sharing/common/nearby_share_enums.h" #include "sharing/common/nearby_share_prefs.h" -#include "sharing/common/nearby_share_profile_info_provider.h" #include "sharing/internal/api/preference_manager.h" #include "sharing/internal/api/sharing_rpc_client.h" #include "sharing/internal/base/utf_string_conversions.h" @@ -108,16 +107,14 @@ std::unique_ptr NearbyShareLocalDeviceDataManagerImpl::Factory::Create( Context* context, PreferenceManager& preference_manager, AccountManager& account_manager, nearby::DeviceInfo& device_info, - SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider) { + SharingRpcClientFactory* rpc_client_factory) { if (test_factory_) { - return test_factory_->CreateInstance(context, rpc_client_factory, - profile_info_provider); + return test_factory_->CreateInstance(context, rpc_client_factory); } return absl::WrapUnique(new NearbyShareLocalDeviceDataManagerImpl( context, preference_manager, account_manager, device_info, - rpc_client_factory, profile_info_provider)); + rpc_client_factory)); } // static @@ -131,12 +128,10 @@ NearbyShareLocalDeviceDataManagerImpl::Factory::~Factory() = default; NearbyShareLocalDeviceDataManagerImpl::NearbyShareLocalDeviceDataManagerImpl( Context* context, PreferenceManager& preference_manager, AccountManager& account_manager, nearby::DeviceInfo& device_info, - SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider) + SharingRpcClientFactory* rpc_client_factory) : preference_manager_(preference_manager), account_manager_(account_manager), device_info_(device_info), - profile_info_provider_(profile_info_provider), nearby_share_client_(rpc_client_factory->CreateInstance()), device_id_(GetId()), download_device_data_scheduler_( @@ -222,17 +217,17 @@ DeviceNameValidationResult NearbyShareLocalDeviceDataManagerImpl::SetDeviceName( void NearbyShareLocalDeviceDataManagerImpl::DownloadDeviceData() { executor_->PostTask([&]() { - NL_LOG(INFO) << __func__ << ": started"; + LOG(INFO) << __func__ << ": started"; if (!is_running()) { - NL_LOG(WARNING) << "DownloadDeviceData: skip to download device data due " - "to manager is stopped."; + LOG(WARNING) << "DownloadDeviceData: skip to download device data due " + "to manager is stopped."; return; } if (!account_manager_.GetCurrentAccount().has_value()) { - NL_LOG(WARNING) << __func__ - << ": skip to download device data due " - "to no login account."; + LOG(WARNING) << __func__ + << ": skip to download device data due " + "to no login account."; download_device_data_scheduler_->HandleResult(/*success=*/true); return; } @@ -244,17 +239,17 @@ void NearbyShareLocalDeviceDataManagerImpl::DownloadDeviceData() { request, [this](const absl::StatusOr& response) { // check whether the manager is running again if (!is_running()) { - NL_LOG(WARNING) + LOG(WARNING) << "DownloadDeviceData: skip to download device data due " "to manager is stopped."; return; } if (response.ok()) { - NL_LOG(WARNING) << "DownloadDeviceData: Got response from backend."; + LOG(WARNING) << "DownloadDeviceData: Got response from backend."; HandleUpdateDeviceResponse(*response); } else { - NL_LOG(WARNING) + LOG(WARNING) << "DownloadDeviceData: Failed to get response from backend: " << response.status(); } @@ -270,18 +265,18 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadContacts( UploadCompleteCallback callback) { executor_->PostTask( [&, contacts = std::move(contacts), callback = std::move(callback)]() { - NL_LOG(INFO) << __func__ << ": size=" << contacts.size(); + LOG(INFO) << __func__ << ": size=" << contacts.size(); if (!is_running()) { - NL_LOG(WARNING) << "UploadContacts: skip to upload contacts due " - "to manager is stopped."; + LOG(WARNING) << "UploadContacts: skip to upload contacts due " + "to manager is stopped."; callback(false); return; } if (!account_manager_.GetCurrentAccount().has_value()) { - NL_LOG(WARNING) << __func__ - << ": skip to upload contacts due " - "to no login account."; + LOG(WARNING) << __func__ + << ": skip to upload contacts due " + "to no login account."; callback(/*success=*/true); return; } @@ -297,7 +292,7 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadContacts( request, [callback = std::move(callback)]( const absl::StatusOr& response) { if (!response.ok()) { - NL_LOG(WARNING) + LOG(WARNING) << "UploadContacts: Failed to get response from backend: " << response.status(); } @@ -311,19 +306,19 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadCertificates( UploadCompleteCallback callback) { executor_->PostTask([&, certificates = std::move(certificates), callback = std::move(callback)]() { - NL_LOG(INFO) << __func__ << ": Upload " << certificates.size() - << " certificates."; + LOG(INFO) << __func__ << ": Upload " << certificates.size() + << " certificates."; if (!is_running()) { - NL_LOG(WARNING) << "UploadContacts: skip to upload certificates due " - "to manager is stopped."; + LOG(WARNING) << "UploadContacts: skip to upload certificates due " + "to manager is stopped."; callback(false); return; } if (!account_manager_.GetCurrentAccount().has_value()) { - NL_LOG(WARNING) << __func__ - << ": skip to upload certificates due " - "to no login account."; + LOG(WARNING) << __func__ + << ": skip to upload certificates due " + "to no login account."; callback(/*success=*/true); return; } @@ -337,17 +332,17 @@ void NearbyShareLocalDeviceDataManagerImpl::UploadCertificates( std::string(kCertificatesFieldMaskPath)); nearby_share_client_->UpdateDevice( request, [this, callback = std::move(callback)]( - const absl::StatusOr& response) { + const absl::StatusOr& response) { // check whether the manager is running again if (!is_running()) { - NL_LOG(WARNING) + LOG(WARNING) << "DownloadDeviceData: skip to upload certificates due " "to manager is stopped."; callback(false); return; } if (!response.ok()) { - NL_LOG(WARNING) + LOG(WARNING) << "UploadCertificates: Failed to get response from backend: " << response.status(); } @@ -368,27 +363,29 @@ void NearbyShareLocalDeviceDataManagerImpl::OnStop() { std::string NearbyShareLocalDeviceDataManagerImpl::GetDefaultDeviceName() const { - std::string device_name = device_info_.GetOsDeviceName(); + std::optional account = + account_manager_.GetCurrentAccount(); DeviceInfo::OsType os_type = device_info_.GetOsType(); - std::string device_type = device_info_.GetDeviceTypeName(); - std::optional given_name = - profile_info_provider_->GetGivenName(); + // If not logged in or account has not given name, use machine name instead. // For iOS and macOS, the device name is already localized and generally works // well for Quick Share purposes (i.e. "Niko's MacBook Pro"), so avoid using // the non-localized account name and device type concatenation. if (os_type == DeviceInfo::OsType::kMacOS || - os_type == DeviceInfo::OsType::kIos || !given_name.has_value()) { + os_type == DeviceInfo::OsType::kIos || !account.has_value() || + account->given_name.empty()) { + std::string device_name = device_info_.GetOsDeviceName(); return GetTruncatedName(device_name, kNearbyShareDeviceNameMaxLength); } - + std::string given_name = account->given_name; + std::string device_type = device_info_.GetDeviceTypeName(); uint64_t untruncated_length = - absl::Substitute(kDefaultDeviceName, *given_name, device_type).length(); + absl::Substitute(kDefaultDeviceName, given_name, device_type).length(); uint64_t overflow_length = untruncated_length - kNearbyShareDeviceNameMaxLength; std::string truncated_name = - GetTruncatedName(*given_name, given_name->length() - overflow_length); + GetTruncatedName(given_name, given_name.length() - overflow_length); return absl::Substitute(kDefaultDeviceName, truncated_name, device_type); } diff --git a/sharing/local_device_data/nearby_share_local_device_data_manager_impl.h b/sharing/local_device_data/nearby_share_local_device_data_manager_impl.h index ebe5fdff..4ae626d7 100644 --- a/sharing/local_device_data/nearby_share_local_device_data_manager_impl.h +++ b/sharing/local_device_data/nearby_share_local_device_data_manager_impl.h @@ -51,16 +51,14 @@ class NearbyShareLocalDeviceDataManagerImpl Context* context, nearby::sharing::api::PreferenceManager& preference_manager, AccountManager& account_manager, nearby::DeviceInfo& device_info, - nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider); + nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory); static void SetFactoryForTesting(Factory* test_factory); protected: virtual ~Factory(); virtual std::unique_ptr CreateInstance( Context* context, - nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider) = 0; + nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory) = 0; private: static Factory* test_factory_; @@ -73,8 +71,7 @@ class NearbyShareLocalDeviceDataManagerImpl Context* context, nearby::sharing::api::PreferenceManager& preference_manager, AccountManager& account_manager, nearby::DeviceInfo& device_info, - nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory, - NearbyShareProfileInfoProvider* profile_info_provider); + nearby::sharing::api::SharingRpcClientFactory* rpc_client_factory); // NearbyShareLocalDeviceDataManager: std::string GetId() override; @@ -108,7 +105,6 @@ class NearbyShareLocalDeviceDataManagerImpl nearby::sharing::api::PreferenceManager& preference_manager_; AccountManager& account_manager_; nearby::DeviceInfo& device_info_; - NearbyShareProfileInfoProvider* const profile_info_provider_; std::unique_ptr nearby_share_client_; const std::string device_id_; std::unique_ptr download_device_data_scheduler_; diff --git a/sharing/local_device_data/nearby_share_local_device_data_manager_impl_test.cc b/sharing/local_device_data/nearby_share_local_device_data_manager_impl_test.cc index e45ba4c2..5a90b1c3 100644 --- a/sharing/local_device_data/nearby_share_local_device_data_manager_impl_test.cc +++ b/sharing/local_device_data/nearby_share_local_device_data_manager_impl_test.cc @@ -33,7 +33,6 @@ #include "internal/test/fake_account_manager.h" #include "internal/test/fake_device_info.h" #include "internal/test/fake_task_runner.h" -#include "sharing/common/fake_nearby_share_profile_info_provider.h" #include "sharing/common/nearby_share_enums.h" #include "sharing/common/nearby_share_prefs.h" #include "sharing/internal/api/fake_nearby_share_client.h" @@ -130,11 +129,11 @@ class NearbyShareLocalDeviceDataManagerImplTest FakeTaskRunner::ResetPendingTasksCount(); prefs::RegisterNearbySharingPrefs(preference_manager_); NearbyShareSchedulerFactory::SetFactoryForTesting(&scheduler_factory_); - profile_info_provider()->set_given_name(kFakeGivenName); AccountManager::Account account; account.id = kTestAccountId; account.email = kTestProfileUserName; + account.given_name = kFakeGivenName; fake_account_manager_.SetAccount(account); } @@ -153,7 +152,7 @@ class NearbyShareLocalDeviceDataManagerImplTest void CreateManager() { manager_ = NearbyShareLocalDeviceDataManagerImpl::Factory::Create( &context_, preference_manager_, fake_account_manager_, - fake_device_info_, &nearby_client_factory_, &profile_info_provider_); + fake_device_info_, &nearby_client_factory_); manager_->AddObserver(this); ++num_manager_creations_; num_download_device_data_ = 0; @@ -247,9 +246,7 @@ class NearbyShareLocalDeviceDataManagerImplTest NearbyShareLocalDeviceDataManager* manager() { return manager_.get(); } - FakeNearbyShareProfileInfoProvider* profile_info_provider() { - return &profile_info_provider_; - } + FakeAccountManager& fake_account_manager() { return fake_account_manager_; } const std::vector& notifications() { return notifications_; @@ -299,7 +296,6 @@ class NearbyShareLocalDeviceDataManagerImplTest size_t num_download_device_data_ = 0; std::vector notifications_; FakeNearbyShareClientFactory nearby_client_factory_; - FakeNearbyShareProfileInfoProvider profile_info_provider_; FakeNearbyShareSchedulerFactory scheduler_factory_; std::unique_ptr manager_; }; @@ -322,14 +318,15 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, DeviceId) { TEST_F(NearbyShareLocalDeviceDataManagerImplTest, DefaultDeviceName) { CreateManager(); - // If given name is null, only return the device type. - profile_info_provider()->set_given_name(std::nullopt); + AccountManager::Account account = *fake_account_manager().GetCurrentAccount(); + // Clear login account. + fake_account_manager().SetAccount(std::nullopt); EXPECT_EQ(manager()->GetDeviceName(), GetDeviceName()); // Set given name and expect full default device name of the form // "'s ." - profile_info_provider()->set_given_name(kFakeGivenName); + fake_account_manager().SetAccount(account); EXPECT_EQ(absl::Substitute(kDefaultDeviceName, kFakeGivenName, GetDeviceTypeName()), @@ -337,7 +334,8 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, DefaultDeviceName) { // Make sure that when we use a given name that is very long we truncate // correctly. - profile_info_provider()->set_given_name(kFakeTooLongGivenName); + account.given_name = kFakeTooLongGivenName; + fake_account_manager().SetAccount(account); EXPECT_EQ(kNearbyShareDeviceNameMaxLength, manager()->GetDeviceName().size()); } @@ -356,7 +354,6 @@ TEST_F(NearbyShareLocalDeviceDataManagerImplTest, ValidateDeviceName) { TEST_F(NearbyShareLocalDeviceDataManagerImplTest, SetDeviceName) { CreateManager(); - profile_info_provider()->set_given_name(kFakeGivenName); std::string expected_default_device_name = absl::Substitute(kDefaultDeviceName, kFakeGivenName, GetDeviceTypeName()); EXPECT_EQ(manager()->GetDeviceName(), expected_default_device_name); diff --git a/sharing/nearby_share_profile_info_provider_impl.cc b/sharing/nearby_share_profile_info_provider_impl.cc deleted file mode 100644 index bcace6fa..00000000 --- a/sharing/nearby_share_profile_info_provider_impl.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2022-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/nearby_share_profile_info_provider_impl.h" - -#include -#include - -#include "internal/platform/device_info.h" -#include "internal/platform/implementation/account_manager.h" - -namespace nearby { -namespace sharing { - -NearbyShareProfileInfoProviderImpl::NearbyShareProfileInfoProviderImpl( - nearby::DeviceInfo& device_info, AccountManager& account_manager) - : device_info_(device_info), account_manager_(account_manager) {} - -NearbyShareProfileInfoProviderImpl::~NearbyShareProfileInfoProviderImpl() = - default; - -std::optional NearbyShareProfileInfoProviderImpl::GetGivenName() - const { - // Use the given name when the user logs in to the backend. - std::optional account = - account_manager_.GetCurrentAccount(); - - if (account.has_value() && !account->given_name.empty()) { - return account->given_name; - } - - return device_info_.GetGivenName(); -} - -} // namespace sharing -} // namespace nearby diff --git a/sharing/nearby_share_profile_info_provider_impl.h b/sharing/nearby_share_profile_info_provider_impl.h deleted file mode 100644 index cbf71291..00000000 --- a/sharing/nearby_share_profile_info_provider_impl.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2022-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_NEARBY_SHARE_PROFILE_INFO_PROVIDER_IMPL_H_ -#define THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARE_PROFILE_INFO_PROVIDER_IMPL_H_ - -#include -#include - -#include "internal/platform/device_info.h" -#include "internal/platform/implementation/account_manager.h" -#include "sharing/common/nearby_share_profile_info_provider.h" - -namespace nearby { -namespace sharing { - -// An implementation of NearbyShareProfileInfoProvider that accesses the actual -// profile data. -class NearbyShareProfileInfoProviderImpl - : public NearbyShareProfileInfoProvider { - public: - NearbyShareProfileInfoProviderImpl(nearby::DeviceInfo& device_info, - AccountManager& account_manager); - NearbyShareProfileInfoProviderImpl( - const NearbyShareProfileInfoProviderImpl&) = delete; - NearbyShareProfileInfoProviderImpl& operator=( - const NearbyShareProfileInfoProviderImpl&) = delete; - ~NearbyShareProfileInfoProviderImpl() override; - - // NearbyShareProfileInfoProvider: - std::optional GetGivenName() const override; - - private: - nearby::DeviceInfo& device_info_; - AccountManager& account_manager_; -}; - -} // namespace sharing -} // namespace nearby - -#endif // THIRD_PARTY_NEARBY_SHARING_NEARBY_SHARE_PROFILE_INFO_PROVIDER_IMPL_H_ diff --git a/sharing/nearby_share_profile_info_provider_impl_test.cc b/sharing/nearby_share_profile_info_provider_impl_test.cc deleted file mode 100644 index 39c51e64..00000000 --- a/sharing/nearby_share_profile_info_provider_impl_test.cc +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2022-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/nearby_share_profile_info_provider_impl.h" - -#include -#include - -#include "gtest/gtest.h" -#include "internal/platform/implementation/account_manager.h" -#include "internal/test/fake_account_manager.h" -#include "internal/test/fake_device_info.h" - -namespace nearby { -namespace sharing { -namespace { - -constexpr char kTestAccountId[] = "test_account_id"; -constexpr char kTestAccountGivenName[] = "given_name"; -constexpr char kExpectedTestAccountGivenName[] = "given_name"; -constexpr char kProfileGivenName[] = "Barack"; - -} // namespace - -class NearbyShareProfileInfoProviderImplTest : public ::testing::Test { - protected: - NearbyShareProfileInfoProviderImplTest() = default; - ~NearbyShareProfileInfoProviderImplTest() override = default; - - void SetUp() override { - fake_device_info_.SetGivenName(std::nullopt); - } - - void SetUserGivenName(const std::string& name) { - fake_device_info_.SetGivenName(name); - } - - FakeDeviceInfo& fake_device_info() { - return fake_device_info_; - } - - FakeAccountManager& fake_account_manager() { return fake_account_manager_; } - - private: - FakeAccountManager fake_account_manager_; - FakeDeviceInfo fake_device_info_; -}; - -TEST_F(NearbyShareProfileInfoProviderImplTest, GivenName) { - NearbyShareProfileInfoProviderImpl profile_info_provider( - fake_device_info(), fake_account_manager()); - - // If no user, return std::nullopt. - EXPECT_FALSE(profile_info_provider.GetGivenName()); - - // If given name is empty, return std::nullopt. - SetUserGivenName(std::string()); - EXPECT_FALSE(profile_info_provider.GetGivenName()); - - SetUserGivenName(kProfileGivenName); - EXPECT_EQ(profile_info_provider.GetGivenName(), kProfileGivenName); -} - -TEST_F(NearbyShareProfileInfoProviderImplTest, GivenNameUseLoginAccount) { - AccountManager::Account account; - account.id = kTestAccountId; - account.given_name = kTestAccountGivenName; - fake_account_manager().SetAccount(account); - SetUserGivenName(kProfileGivenName); - - NearbyShareProfileInfoProviderImpl profile_info_provider( - fake_device_info(), fake_account_manager()); - EXPECT_EQ(profile_info_provider.GetGivenName(), - kExpectedTestAccountGivenName); -} - -TEST_F(NearbyShareProfileInfoProviderImplTest, - GivenNameNotUseLoginAccountWhenGivenNameEmpty) { - AccountManager::Account account; - account.id = kTestAccountId; - fake_account_manager().SetAccount(account); - SetUserGivenName(kProfileGivenName); - - NearbyShareProfileInfoProviderImpl profile_info_provider( - fake_device_info(), fake_account_manager()); - EXPECT_EQ(profile_info_provider.GetGivenName(), kProfileGivenName); -} - -} // namespace sharing -} // namespace nearby diff --git a/sharing/nearby_sharing_service_impl.cc b/sharing/nearby_sharing_service_impl.cc index f365c692..225be246 100644 --- a/sharing/nearby_sharing_service_impl.cc +++ b/sharing/nearby_sharing_service_impl.cc @@ -86,7 +86,6 @@ #include "sharing/nearby_connections_manager.h" #include "sharing/nearby_connections_types.h" #include "sharing/nearby_file_handler.h" -#include "sharing/nearby_share_profile_info_provider_impl.h" #include "sharing/nearby_sharing_decoder.h" #include "sharing/nearby_sharing_service.h" #include "sharing/nearby_sharing_service_extension.h" @@ -202,14 +201,10 @@ NearbySharingServiceImpl::NearbySharingServiceImpl( nearby_connections_manager_(std::move(nearby_connections_manager)), nearby_share_client_factory_( sharing_platform.CreateSharingRpcClientFactory(&analytics_recorder_)), - profile_info_provider_( - std::make_unique( - device_info_, account_manager_)), local_device_data_manager_( NearbyShareLocalDeviceDataManagerImpl::Factory::Create( context_, preference_manager_, account_manager_, device_info_, - nearby_share_client_factory_.get(), - profile_info_provider_.get())), + nearby_share_client_factory_.get())), contact_manager_(NearbyShareContactManagerImpl::Factory::Create( context_, preference_manager_, account_manager_, nearby_share_client_factory_.get(), diff --git a/sharing/nearby_sharing_service_impl.h b/sharing/nearby_sharing_service_impl.h index 991f4578..36b8757b 100644 --- a/sharing/nearby_sharing_service_impl.h +++ b/sharing/nearby_sharing_service_impl.h @@ -47,7 +47,6 @@ #include "sharing/certificates/nearby_share_decrypted_public_certificate.h" #include "sharing/certificates/nearby_share_private_certificate.h" #include "sharing/common/nearby_share_enums.h" -#include "sharing/common/nearby_share_profile_info_provider.h" #include "sharing/fast_initiation/nearby_fast_initiation.h" #include "sharing/incoming_share_session.h" #include "sharing/internal/api/app_info.h" @@ -481,7 +480,6 @@ class NearbySharingServiceImpl std::unique_ptr nearby_connections_manager_; std::unique_ptr nearby_share_client_factory_; - std::unique_ptr profile_info_provider_; std::unique_ptr local_device_data_manager_; std::unique_ptr contact_manager_; std::unique_ptr certificate_manager_;