Commit 6da431cd authored by Hidehiko Abe's avatar Hidehiko Abe Committed by Commit Bot

Migrate ArcService to BrowserContextKeyedService part 18.

This CL migrates ArcProvisionNotificationService.

BUG=672829
TEST=Ran try.

Change-Id: If15cda269ecfad203efbb7ebfc4fb88114a9b843
Reviewed-on: https://chromium-review.googlesource.com/573000
Commit-Queue: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: default avatarYusuke Sato (in China Mon-Thurs, may be offline) <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487018}
parent db5e34d7
...@@ -106,8 +106,6 @@ void ArcServiceLauncher::Initialize() { ...@@ -106,8 +106,6 @@ void ArcServiceLauncher::Initialize() {
base::MakeUnique<ArcPolicyBridge>(arc_bridge_service)); base::MakeUnique<ArcPolicyBridge>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcProcessService>(arc_bridge_service)); base::MakeUnique<ArcProcessService>(arc_bridge_service));
arc_service_manager_->AddService(
base::MakeUnique<ArcProvisionNotificationService>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
base::MakeUnique<ArcSettingsService>(arc_bridge_service)); base::MakeUnique<ArcSettingsService>(arc_bridge_service));
arc_service_manager_->AddService( arc_service_manager_->AddService(
...@@ -191,6 +189,7 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) { ...@@ -191,6 +189,7 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcObbMounterBridge::GetForBrowserContext(profile); ArcObbMounterBridge::GetForBrowserContext(profile);
ArcPowerBridge::GetForBrowserContext(profile); ArcPowerBridge::GetForBrowserContext(profile);
ArcPrintService::GetForBrowserContext(profile); ArcPrintService::GetForBrowserContext(profile);
ArcProvisionNotificationService::GetForBrowserContext(profile);
arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>( arc_service_manager_->AddService(base::MakeUnique<ArcBootPhaseMonitorBridge>(
arc_service_manager_->arc_bridge_service(), arc_service_manager_->arc_bridge_service(),
......
...@@ -8,10 +8,12 @@ ...@@ -8,10 +8,12 @@
#include "ash/system/devicetype_utils.h" #include "ash/system/devicetype_utils.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/singleton.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/arc/arc_util.h" #include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/grit/theme_resources.h" #include "chrome/grit/theme_resources.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/signin/core/account_id/account_id.h" #include "components/signin/core/account_id/account_id.h"
#include "components/user_manager/user.h" #include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h" #include "components/user_manager/user_manager.h"
...@@ -69,36 +71,67 @@ void DelegateImpl::RemoveManagedProvisionNotification() { ...@@ -69,36 +71,67 @@ void DelegateImpl::RemoveManagedProvisionNotification() {
kManagedProvisionNotificationId, false); kManagedProvisionNotificationId, false);
} }
// Singleton factory for ArcProvisionNotificationService.
class ArcProvisionNotificationServiceFactory
: public internal::ArcBrowserContextKeyedServiceFactoryBase<
ArcProvisionNotificationService,
ArcProvisionNotificationServiceFactory> {
public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase.
static constexpr const char* kName = "ArcProvisionNotificationServiceFactory";
static ArcProvisionNotificationServiceFactory* GetInstance() {
return base::Singleton<ArcProvisionNotificationServiceFactory>::get();
}
private:
friend base::DefaultSingletonTraits<ArcProvisionNotificationServiceFactory>;
ArcProvisionNotificationServiceFactory() = default;
~ArcProvisionNotificationServiceFactory() override = default;
};
} // namespace } // namespace
ArcProvisionNotificationService::Delegate::Delegate() = default; ArcProvisionNotificationService::Delegate::Delegate() = default;
ArcProvisionNotificationService::Delegate::~Delegate() = default; ArcProvisionNotificationService::Delegate::~Delegate() = default;
// static
ArcProvisionNotificationService*
ArcProvisionNotificationService::GetForBrowserContext(
content::BrowserContext* context) {
return ArcProvisionNotificationServiceFactory::GetForBrowserContext(context);
}
ArcProvisionNotificationService::ArcProvisionNotificationService( ArcProvisionNotificationService::ArcProvisionNotificationService(
content::BrowserContext* context,
ArcBridgeService* bridge_service) ArcBridgeService* bridge_service)
: ArcProvisionNotificationService(bridge_service, : ArcProvisionNotificationService(base::MakeUnique<DelegateImpl>()) {}
base::MakeUnique<DelegateImpl>()) {}
ArcProvisionNotificationService::~ArcProvisionNotificationService() { ArcProvisionNotificationService::~ArcProvisionNotificationService() {
// Make sure no notification is left being shown. // Make sure no notification is left being shown.
delegate_->RemoveManagedProvisionNotification(); delegate_->RemoveManagedProvisionNotification();
ArcSessionManager::Get()->RemoveObserver(this);
// TODO(hidehiko): Currently, the lifetime of ArcSessionManager and
// BrowserContextKeyedService is not nested.
// If ArcSessionManager::Get() returns nullptr, it is already destructed,
// so do not touch it.
auto* arc_session_manager = ArcSessionManager::Get();
if (arc_session_manager)
arc_session_manager->RemoveObserver(this);
} }
// static // static
std::unique_ptr<ArcProvisionNotificationService> std::unique_ptr<ArcProvisionNotificationService>
ArcProvisionNotificationService::CreateForTesting( ArcProvisionNotificationService::CreateForTesting(
ArcBridgeService* bridge_service,
std::unique_ptr<Delegate> delegate) { std::unique_ptr<Delegate> delegate) {
return base::WrapUnique<ArcProvisionNotificationService>( return base::WrapUnique<ArcProvisionNotificationService>(
new ArcProvisionNotificationService(bridge_service, std::move(delegate))); new ArcProvisionNotificationService(std::move(delegate)));
} }
ArcProvisionNotificationService::ArcProvisionNotificationService( ArcProvisionNotificationService::ArcProvisionNotificationService(
ArcBridgeService* bridge_service,
std::unique_ptr<Delegate> delegate) std::unique_ptr<Delegate> delegate)
: ArcService(bridge_service), delegate_(std::move(delegate)) { : delegate_(std::move(delegate)) {
ArcSessionManager::Get()->AddObserver(this); ArcSessionManager::Get()->AddObserver(this);
} }
......
...@@ -9,13 +9,17 @@ ...@@ -9,13 +9,17 @@
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/chromeos/arc/arc_session_manager.h" #include "chrome/browser/chromeos/arc/arc_session_manager.h"
#include "components/arc/arc_service.h" #include "components/keyed_service/core/keyed_service.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc { namespace arc {
// Watches for ARC provisioning status and displays a notification during // Watches for ARC provisioning status and displays a notification during
// provision when ARC opt-in flow happens silently due to configured policies. // provision when ARC opt-in flow happens silently due to configured policies.
class ArcProvisionNotificationService : public ArcService, class ArcProvisionNotificationService : public KeyedService,
public ArcSessionManager::Observer { public ArcSessionManager::Observer {
public: public:
// The delegate whose methods are used by the service for showing/hiding the // The delegate whose methods are used by the service for showing/hiding the
...@@ -31,21 +35,25 @@ class ArcProvisionNotificationService : public ArcService, ...@@ -31,21 +35,25 @@ class ArcProvisionNotificationService : public ArcService,
DISALLOW_COPY_AND_ASSIGN(Delegate); DISALLOW_COPY_AND_ASSIGN(Delegate);
}; };
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcProvisionNotificationService* GetForBrowserContext(
content::BrowserContext* context);
// Constructs with the default delegate implementation that uses message // Constructs with the default delegate implementation that uses message
// center for showing the notifications. // center for showing the notifications.
explicit ArcProvisionNotificationService(ArcBridgeService* bridge_service); ArcProvisionNotificationService(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcProvisionNotificationService() override; ~ArcProvisionNotificationService() override;
// Constructs an instance with the supplied delegate. // Constructs an instance with the supplied delegate.
static std::unique_ptr<ArcProvisionNotificationService> CreateForTesting( static std::unique_ptr<ArcProvisionNotificationService> CreateForTesting(
ArcBridgeService* bridge_service,
std::unique_ptr<Delegate> delegate); std::unique_ptr<Delegate> delegate);
private: private:
// Constructs with the supplied delegate. // Constructs with the supplied delegate.
ArcProvisionNotificationService(ArcBridgeService* bridge_service, explicit ArcProvisionNotificationService(std::unique_ptr<Delegate> delegate);
std::unique_ptr<Delegate> delegate);
// ArcSessionManager::Observer: // ArcSessionManager::Observer:
void OnArcPlayStoreEnabledChanged(bool enabled) override; void OnArcPlayStoreEnabledChanged(bool enabled) override;
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_session_manager_client.h" #include "chromeos/dbus/fake_session_manager_client.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/arc_util.h" #include "components/arc/arc_util.h"
#include "components/arc/test/fake_arc_session.h" #include "components/arc/test/fake_arc_session.h"
...@@ -79,7 +78,6 @@ class ArcProvisionNotificationServiceTest : public testing::Test { ...@@ -79,7 +78,6 @@ class ArcProvisionNotificationServiceTest : public testing::Test {
mock_arc_provision_notification_service_delegate.get(); mock_arc_provision_notification_service_delegate.get();
arc_provision_notification_service_ = arc_provision_notification_service_ =
ArcProvisionNotificationService::CreateForTesting( ArcProvisionNotificationService::CreateForTesting(
arc_bridge_service(),
std::move(mock_arc_provision_notification_service_delegate)); std::move(mock_arc_provision_notification_service_delegate));
const AccountId account_id(AccountId::FromUserEmailGaiaId( const AccountId account_id(AccountId::FromUserEmailGaiaId(
...@@ -104,9 +102,6 @@ class ArcProvisionNotificationServiceTest : public testing::Test { ...@@ -104,9 +102,6 @@ class ArcProvisionNotificationServiceTest : public testing::Test {
ArcServiceManager* arc_service_manager() { ArcServiceManager* arc_service_manager() {
return arc_service_manager_.get(); return arc_service_manager_.get();
} }
ArcBridgeService* arc_bridge_service() {
return arc_service_manager_->arc_bridge_service();
}
ArcSessionManager* arc_session_manager() { ArcSessionManager* arc_session_manager() {
return arc_session_manager_.get(); return arc_session_manager_.get();
} }
......
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