Commit 9bf3aa3f authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Create FakePhoneHubManager.

* Moves PhoneHubManager to PhoneHubManagerImpl.
* PhoneHubManagerImpl and FakePhoneHubManager are now derived classes.
* FakePhoneHubManager will be used by the debug UI to be added in a
  later CL.

Bug: 1106937
Change-Id: Iee1c6b4b787f36a7a50eb83fcd1ae1e626f7eecc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2375740Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801852}
parent 736fbd4a
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chromeos/components/phonehub/notification_access_manager_impl.h" #include "chromeos/components/phonehub/notification_access_manager_impl.h"
#include "chromeos/components/phonehub/phone_hub_manager.h" #include "chromeos/components/phonehub/phone_hub_manager_impl.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/services/multidevice_setup/public/cpp/prefs.h" #include "chromeos/services/multidevice_setup/public/cpp/prefs.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h" #include "components/keyed_service/content/browser_context_dependency_manager.h"
...@@ -41,7 +41,7 @@ bool IsLoggedInAsPrimaryUser(Profile* profile) { ...@@ -41,7 +41,7 @@ bool IsLoggedInAsPrimaryUser(Profile* profile) {
// static // static
PhoneHubManager* PhoneHubManagerFactory::GetForProfile(Profile* profile) { PhoneHubManager* PhoneHubManagerFactory::GetForProfile(Profile* profile) {
return static_cast<PhoneHubManager*>( return static_cast<PhoneHubManagerImpl*>(
PhoneHubManagerFactory::GetInstance()->GetServiceForBrowserContext( PhoneHubManagerFactory::GetInstance()->GetServiceForBrowserContext(
profile, /*create=*/true)); profile, /*create=*/true));
} }
...@@ -75,7 +75,7 @@ KeyedService* PhoneHubManagerFactory::BuildServiceInstanceFor( ...@@ -75,7 +75,7 @@ KeyedService* PhoneHubManagerFactory::BuildServiceInstanceFor(
if (IsProhibitedByPolicy(profile)) if (IsProhibitedByPolicy(profile))
return nullptr; return nullptr;
PhoneHubManager* phone_hub_manager = new PhoneHubManager( PhoneHubManagerImpl* phone_hub_manager = new PhoneHubManagerImpl(
profile->GetPrefs(), profile->GetPrefs(),
device_sync::DeviceSyncClientFactory::GetForProfile(profile), device_sync::DeviceSyncClientFactory::GetForProfile(profile),
multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(profile)); multidevice_setup::MultiDeviceSetupClientFactory::GetForProfile(profile));
......
...@@ -334,8 +334,9 @@ void MultiDeviceSection::AddHandlers(content::WebUI* web_ui) { ...@@ -334,8 +334,9 @@ void MultiDeviceSection::AddHandlers(content::WebUI* web_ui) {
web_ui->AddMessageHandler( web_ui->AddMessageHandler(
std::make_unique<chromeos::settings::MultideviceHandler>( std::make_unique<chromeos::settings::MultideviceHandler>(
pref_service_, multidevice_setup_client_, pref_service_, multidevice_setup_client_,
phone_hub_manager_ ? phone_hub_manager_->notification_access_manager() phone_hub_manager_
: nullptr, ? phone_hub_manager_->GetNotificationAccessManager()
: nullptr,
android_sms_service_ android_sms_service_
? android_sms_service_->android_sms_pairing_state_tracker() ? android_sms_service_->android_sms_pairing_state_tracker()
: nullptr, : nullptr,
......
...@@ -423,8 +423,9 @@ void SettingsUI::InitBrowserSettingsWebUIHandlers() { ...@@ -423,8 +423,9 @@ void SettingsUI::InitBrowserSettingsWebUIHandlers() {
profile->GetPrefs(), profile->GetPrefs(),
chromeos::multidevice_setup::MultiDeviceSetupClientFactory:: chromeos::multidevice_setup::MultiDeviceSetupClientFactory::
GetForProfile(profile), GetForProfile(profile),
phone_hub_manager ? phone_hub_manager->notification_access_manager() phone_hub_manager
: nullptr, ? phone_hub_manager->GetNotificationAccessManager()
: nullptr,
android_sms_service android_sms_service
? android_sms_service->android_sms_pairing_state_tracker() ? android_sms_service->android_sms_pairing_state_tracker()
: nullptr, : nullptr,
......
...@@ -24,8 +24,9 @@ static_library("phonehub") { ...@@ -24,8 +24,9 @@ static_library("phonehub") {
"notification_access_manager_impl.h", "notification_access_manager_impl.h",
"notification_access_setup_operation.cc", "notification_access_setup_operation.cc",
"notification_access_setup_operation.h", "notification_access_setup_operation.h",
"phone_hub_manager.cc",
"phone_hub_manager.h", "phone_hub_manager.h",
"phone_hub_manager_impl.cc",
"phone_hub_manager_impl.h",
"phone_model.cc", "phone_model.cc",
"phone_model.h", "phone_model.h",
"phone_status_model.cc", "phone_status_model.cc",
...@@ -60,6 +61,8 @@ static_library("test_support") { ...@@ -60,6 +61,8 @@ static_library("test_support") {
"fake_feature_status_provider.h", "fake_feature_status_provider.h",
"fake_notification_access_manager.cc", "fake_notification_access_manager.cc",
"fake_notification_access_manager.h", "fake_notification_access_manager.h",
"fake_phone_hub_manager.cc",
"fake_phone_hub_manager.h",
"fake_tether_controller.cc", "fake_tether_controller.cc",
"fake_tether_controller.h", "fake_tether_controller.h",
"phone_model_test_util.cc", "phone_model_test_util.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/components/phonehub/fake_phone_hub_manager.h"
#include "chromeos/components/phonehub/fake_feature_status_provider.h"
#include "chromeos/components/phonehub/fake_notification_access_manager.h"
#include "chromeos/components/phonehub/fake_tether_controller.h"
#include "chromeos/components/phonehub/mutable_phone_model.h"
namespace chromeos {
namespace phonehub {
FakePhoneHubManager::FakePhoneHubManager()
: fake_feature_status_provider_(
std::make_unique<FakeFeatureStatusProvider>()),
fake_notification_access_manager_(
std::make_unique<FakeNotificationAccessManager>()),
mutable_phone_model_(std::make_unique<MutablePhoneModel>()),
fake_tether_controller_(std::make_unique<FakeTetherController>()) {}
FakePhoneHubManager::~FakePhoneHubManager() = default;
FeatureStatusProvider* FakePhoneHubManager::GetFeatureStatusProvider() {
return fake_feature_status_provider_.get();
}
NotificationAccessManager* FakePhoneHubManager::GetNotificationAccessManager() {
return fake_notification_access_manager_.get();
}
PhoneModel* FakePhoneHubManager::GetPhoneModel() {
return mutable_phone_model_.get();
}
TetherController* FakePhoneHubManager::GetTetherController() {
return fake_tether_controller_.get();
}
} // namespace phonehub
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_PHONEHUB_FAKE_PHONE_HUB_MANAGER_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_FAKE_PHONE_HUB_MANAGER_H_
#include <memory>
#include "chromeos/components/phonehub/phone_hub_manager.h"
namespace chromeos {
namespace phonehub {
class FakeFeatureStatusProvider;
class FakeNotificationAccessManager;
class MutablePhoneModel;
class FakeTetherController;
// This class initializes fake versions of the core business logic of Phone Hub.
class FakePhoneHubManager : public PhoneHubManager {
public:
FakePhoneHubManager();
~FakePhoneHubManager() override;
FakeFeatureStatusProvider* fake_feature_status_provider() {
return fake_feature_status_provider_.get();
}
FakeNotificationAccessManager* fake_notification_access_manager() {
return fake_notification_access_manager_.get();
}
MutablePhoneModel* mutable_phone_model() {
return mutable_phone_model_.get();
}
FakeTetherController* fake_tether_controller() {
return fake_tether_controller_.get();
}
private:
// PhoneHubManager:
FeatureStatusProvider* GetFeatureStatusProvider() override;
NotificationAccessManager* GetNotificationAccessManager() override;
PhoneModel* GetPhoneModel() override;
TetherController* GetTetherController() override;
std::unique_ptr<FakeFeatureStatusProvider> fake_feature_status_provider_;
std::unique_ptr<FakeNotificationAccessManager>
fake_notification_access_manager_;
std::unique_ptr<MutablePhoneModel> mutable_phone_model_;
std::unique_ptr<FakeTetherController> fake_tether_controller_;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_FAKE_PHONE_HUB_MANAGER_H_
...@@ -5,23 +5,7 @@ ...@@ -5,23 +5,7 @@
#ifndef CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_H_ #ifndef CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_H_ #define CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_H_
#include <memory>
#include "base/callback_forward.h"
#include "components/keyed_service/core/keyed_service.h"
class PrefService;
namespace chromeos { namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
} // namespace device_sync
namespace multidevice_setup {
class MultiDeviceSetupClient;
} // namespace multidevice_setup
namespace phonehub { namespace phonehub {
class FeatureStatusProvider; class FeatureStatusProvider;
...@@ -29,40 +13,25 @@ class NotificationAccessManager; ...@@ -29,40 +13,25 @@ class NotificationAccessManager;
class PhoneModel; class PhoneModel;
class TetherController; class TetherController;
// Implements the core logic of the Phone Hub feature and exposes interfaces via // Responsible for the core logic of the Phone Hub feature and exposes
// its public API. Implemented as a KeyedService which is keyed by the primary // interfaces via its public API. This class is intended to be a singleton.
// Profile; since there is only one primary Profile, the class is intended to be class PhoneHubManager {
// a singleton.
class PhoneHubManager : public KeyedService {
public: public:
PhoneHubManager( virtual ~PhoneHubManager() = default;
PrefService* pref_service,
device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
PhoneHubManager(const PhoneHubManager&) = delete; PhoneHubManager(const PhoneHubManager&) = delete;
PhoneHubManager& operator=(const PhoneHubManager&) = delete; PhoneHubManager& operator=(const PhoneHubManager&) = delete;
~PhoneHubManager() override;
FeatureStatusProvider* feature_status_provider() {
return feature_status_provider_.get();
}
NotificationAccessManager* notification_access_manager() { virtual FeatureStatusProvider* GetFeatureStatusProvider() = 0;
return notification_access_manager_.get();
}
PhoneModel* phone_model() { return phone_model_.get(); } virtual NotificationAccessManager* GetNotificationAccessManager() = 0;
TetherController* tether_controller() { return tether_controller_.get(); } virtual PhoneModel* GetPhoneModel() = 0;
private: virtual TetherController* GetTetherController() = 0;
// KeyedService:
void Shutdown() override;
std::unique_ptr<FeatureStatusProvider> feature_status_provider_; protected:
std::unique_ptr<NotificationAccessManager> notification_access_manager_; PhoneHubManager() = default;
std::unique_ptr<PhoneModel> phone_model_;
std::unique_ptr<TetherController> tether_controller_;
}; };
} // namespace phonehub } // namespace phonehub
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/components/phonehub/phone_hub_manager.h" #include "chromeos/components/phonehub/phone_hub_manager_impl.h"
#include "base/callback.h"
#include "base/no_destructor.h"
#include "chromeos/components/phonehub/feature_status_provider_impl.h" #include "chromeos/components/phonehub/feature_status_provider_impl.h"
#include "chromeos/components/phonehub/mutable_phone_model.h" #include "chromeos/components/phonehub/mutable_phone_model.h"
#include "chromeos/components/phonehub/notification_access_manager_impl.h" #include "chromeos/components/phonehub/notification_access_manager_impl.h"
...@@ -14,7 +12,7 @@ ...@@ -14,7 +12,7 @@
namespace chromeos { namespace chromeos {
namespace phonehub { namespace phonehub {
PhoneHubManager::PhoneHubManager( PhoneHubManagerImpl::PhoneHubManagerImpl(
PrefService* pref_service, PrefService* pref_service,
device_sync::DeviceSyncClient* device_sync_client, device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client) multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client)
...@@ -27,9 +25,25 @@ PhoneHubManager::PhoneHubManager( ...@@ -27,9 +25,25 @@ PhoneHubManager::PhoneHubManager(
tether_controller_( tether_controller_(
std::make_unique<TetherControllerImpl>(multidevice_setup_client)) {} std::make_unique<TetherControllerImpl>(multidevice_setup_client)) {}
PhoneHubManager::~PhoneHubManager() = default; PhoneHubManagerImpl::~PhoneHubManagerImpl() = default;
void PhoneHubManager::Shutdown() { FeatureStatusProvider* PhoneHubManagerImpl::GetFeatureStatusProvider() {
return feature_status_provider_.get();
}
NotificationAccessManager* PhoneHubManagerImpl::GetNotificationAccessManager() {
return notification_access_manager_.get();
}
PhoneModel* PhoneHubManagerImpl::GetPhoneModel() {
return phone_model_.get();
}
TetherController* PhoneHubManagerImpl::GetTetherController() {
return tether_controller_.get();
}
void PhoneHubManagerImpl::Shutdown() {
tether_controller_.reset(); tether_controller_.reset();
phone_model_.reset(); phone_model_.reset();
notification_access_manager_.reset(); notification_access_manager_.reset();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_IMPL_H_
#define CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_IMPL_H_
#include <memory>
#include "chromeos/components/phonehub/phone_hub_manager.h"
#include "components/keyed_service/core/keyed_service.h"
class PrefService;
namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
} // namespace device_sync
namespace multidevice_setup {
class MultiDeviceSetupClient;
} // namespace multidevice_setup
namespace phonehub {
// Implemented as a KeyedService which is keyed by the primary Profile.
class PhoneHubManagerImpl : public PhoneHubManager, public KeyedService {
public:
PhoneHubManagerImpl(
PrefService* pref_service,
device_sync::DeviceSyncClient* device_sync_client,
multidevice_setup::MultiDeviceSetupClient* multidevice_setup_client);
~PhoneHubManagerImpl() override;
// PhoneHubManager:
FeatureStatusProvider* GetFeatureStatusProvider() override;
NotificationAccessManager* GetNotificationAccessManager() override;
PhoneModel* GetPhoneModel() override;
TetherController* GetTetherController() override;
private:
// KeyedService:
void Shutdown() override;
std::unique_ptr<FeatureStatusProvider> feature_status_provider_;
std::unique_ptr<NotificationAccessManager> notification_access_manager_;
std::unique_ptr<PhoneModel> phone_model_;
std::unique_ptr<TetherController> tether_controller_;
};
} // namespace phonehub
} // namespace chromeos
#endif // CHROMEOS_COMPONENTS_PHONEHUB_PHONE_HUB_MANAGER_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment