Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / policy / cloud / user_cloud_policy_invalidator_factory.cc
blobd91d31e2f5b953e551d5142e914e0c01a2898be9
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"
16 #else
17 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h"
18 #include "components/policy/core/common/cloud/user_cloud_policy_manager.h"
19 #endif
21 namespace policy {
23 // static
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());
36 #else
37 DependsOn(UserCloudPolicyManagerFactory::GetInstance());
38 #endif
41 UserCloudPolicyInvalidatorFactory::~UserCloudPolicyInvalidatorFactory() {}
43 BrowserContextKeyedService*
44 UserCloudPolicyInvalidatorFactory::BuildServiceInstanceFor(
45 content::BrowserContext* context) const {
46 if (CommandLine::ForCurrentProcess()->HasSwitch(
47 switches::kDisableCloudPolicyPush)) {
48 return NULL;
51 Profile* profile = static_cast<Profile*>(context);
52 #if defined(OS_CHROMEOS)
53 CloudPolicyManager* policy_manager =
54 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile);
55 #else
56 CloudPolicyManager* policy_manager =
57 UserCloudPolicyManagerFactory::GetForBrowserContext(context);
58 #endif
59 if (!policy_manager)
60 return NULL;
62 return new UserCloudPolicyInvalidator(profile, policy_manager);
65 bool UserCloudPolicyInvalidatorFactory::
66 ServiceIsCreatedWithBrowserContext() const {
67 // Must be automatically created to enable user policy invalidations.
68 return true;
71 bool UserCloudPolicyInvalidatorFactory::ServiceIsNULLWhileTesting() const {
72 // Not used in tests.
73 return true;
76 } // namespace policy