1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator_factory.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/invalidation/invalidation_service_factory.h"
9 #include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
12 #include "components/policy/core/common/policy_switches.h"
13 #if defined(OS_CHROMEOS)
14 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h"
15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.h"
17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
18 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
24 UserCloudPolicyInvalidatorFactory
*
25 UserCloudPolicyInvalidatorFactory::GetInstance() {
26 return Singleton
<UserCloudPolicyInvalidatorFactory
>::get();
29 UserCloudPolicyInvalidatorFactory::UserCloudPolicyInvalidatorFactory()
30 : BrowserContextKeyedServiceFactory(
31 "UserCloudPolicyInvalidator",
32 BrowserContextDependencyManager::GetInstance()) {
33 DependsOn(invalidation::InvalidationServiceFactory::GetInstance());
34 #if defined(OS_CHROMEOS)
35 DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance());
37 DependsOn(UserCloudPolicyManagerFactory::GetInstance());
41 UserCloudPolicyInvalidatorFactory::~UserCloudPolicyInvalidatorFactory() {}
43 BrowserContextKeyedService
*
44 UserCloudPolicyInvalidatorFactory::BuildServiceInstanceFor(
45 content::BrowserContext
* context
) const {
46 if (CommandLine::ForCurrentProcess()->HasSwitch(
47 switches::kDisableCloudPolicyPush
)) {
51 Profile
* profile
= static_cast<Profile
*>(context
);
52 #if defined(OS_CHROMEOS)
53 CloudPolicyManager
* policy_manager
=
54 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile
);
56 CloudPolicyManager
* policy_manager
=
57 UserCloudPolicyManagerFactory::GetForBrowserContext(context
);
62 return new UserCloudPolicyInvalidator(profile
, policy_manager
);
65 bool UserCloudPolicyInvalidatorFactory::
66 ServiceIsCreatedWithBrowserContext() const {
67 // Must be automatically created to enable user policy invalidations.
71 bool UserCloudPolicyInvalidatorFactory::ServiceIsNULLWhileTesting() const {