OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 5 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "chrome/browser/policy/profile_policy_connector.h" | 9 #include "chrome/browser/policy/profile_policy_connector.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
12 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 12 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
13 #include "components/user_prefs/pref_registry_syncable.h" | 13 #include "components/user_prefs/pref_registry_syncable.h" |
14 | 14 |
15 #if defined(ENABLE_CONFIGURATION_POLICY) | 15 #if defined(ENABLE_CONFIGURATION_POLICY) |
16 #include "chrome/browser/policy/schema_registry_service_factory.h" | |
17 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
18 #include "chrome/browser/chromeos/login/user.h" | 17 #include "chrome/browser/chromeos/login/user.h" |
19 #include "chrome/browser/chromeos/login/user_manager.h" | 18 #include "chrome/browser/chromeos/login/user_manager.h" |
20 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
21 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 20 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 22 #include "chrome/browser/policy/schema_registry_service.h" |
| 23 #include "chrome/browser/policy/schema_registry_service_factory.h" |
23 #else | 24 #else |
24 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 25 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
25 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 26 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
26 #endif | 27 #endif |
27 #endif | 28 #endif |
28 | 29 |
29 namespace policy { | 30 namespace policy { |
30 | 31 |
31 // static | 32 // static |
32 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { | 33 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { |
(...skipping 19 matching lines...) Expand all Loading... |
52 ProfilePolicyConnector*& map_entry = connectors_[profile]; | 53 ProfilePolicyConnector*& map_entry = connectors_[profile]; |
53 CHECK(!map_entry); | 54 CHECK(!map_entry); |
54 map_entry = connector; | 55 map_entry = connector; |
55 } | 56 } |
56 | 57 |
57 ProfilePolicyConnectorFactory::ProfilePolicyConnectorFactory() | 58 ProfilePolicyConnectorFactory::ProfilePolicyConnectorFactory() |
58 : BrowserContextKeyedBaseFactory( | 59 : BrowserContextKeyedBaseFactory( |
59 "ProfilePolicyConnector", | 60 "ProfilePolicyConnector", |
60 BrowserContextDependencyManager::GetInstance()) { | 61 BrowserContextDependencyManager::GetInstance()) { |
61 #if defined(ENABLE_CONFIGURATION_POLICY) | 62 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 63 #if defined(OS_CHROMEOS) |
62 DependsOn(SchemaRegistryServiceFactory::GetInstance()); | 64 DependsOn(SchemaRegistryServiceFactory::GetInstance()); |
63 #if defined(OS_CHROMEOS) | |
64 DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance()); | 65 DependsOn(UserCloudPolicyManagerFactoryChromeOS::GetInstance()); |
65 #else | 66 #else |
66 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); | 67 DependsOn(UserCloudPolicyManagerFactory::GetInstance()); |
67 #endif | 68 #endif |
68 #endif | 69 #endif |
69 } | 70 } |
70 | 71 |
71 ProfilePolicyConnectorFactory::~ProfilePolicyConnectorFactory() { | 72 ProfilePolicyConnectorFactory::~ProfilePolicyConnectorFactory() { |
72 DCHECK(connectors_.empty()); | 73 DCHECK(connectors_.empty()); |
73 } | 74 } |
74 | 75 |
75 ProfilePolicyConnector* | 76 ProfilePolicyConnector* |
76 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { | 77 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { |
77 // Get the connector for the original Profile, so that the incognito Profile | 78 // Get the connector for the original Profile, so that the incognito Profile |
78 // gets managed settings from the same PolicyService. | 79 // gets managed settings from the same PolicyService. |
79 ConnectorMap::const_iterator it = | 80 ConnectorMap::const_iterator it = |
80 connectors_.find(profile->GetOriginalProfile()); | 81 connectors_.find(profile->GetOriginalProfile()); |
81 CHECK(it != connectors_.end()); | 82 CHECK(it != connectors_.end()); |
82 return it->second; | 83 return it->second; |
83 } | 84 } |
84 | 85 |
85 scoped_ptr<ProfilePolicyConnector> | 86 scoped_ptr<ProfilePolicyConnector> |
86 ProfilePolicyConnectorFactory::CreateForProfileInternal( | 87 ProfilePolicyConnectorFactory::CreateForProfileInternal( |
87 Profile* profile, | 88 Profile* profile, |
88 bool force_immediate_load) { | 89 bool force_immediate_load) { |
89 DCHECK(connectors_.find(profile) == connectors_.end()); | 90 DCHECK(connectors_.find(profile) == connectors_.end()); |
90 #if defined(ENABLE_CONFIGURATION_POLICY) | 91 #if defined(ENABLE_CONFIGURATION_POLICY) |
91 #if defined(OS_CHROMEOS) | 92 #if defined(OS_CHROMEOS) |
| 93 SchemaRegistry* schema_registry = |
| 94 SchemaRegistryServiceFactory::GetForContext(profile); |
92 chromeos::User* user = NULL; | 95 chromeos::User* user = NULL; |
93 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { | 96 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { |
94 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 97 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
95 user = user_manager->GetUserByProfile(profile); | 98 user = user_manager->GetUserByProfile(profile); |
96 CHECK(user); | 99 CHECK(user); |
97 } | 100 } |
98 CloudPolicyManager* user_cloud_policy_manager = | 101 CloudPolicyManager* user_cloud_policy_manager = |
99 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | 102 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); |
100 #else | 103 #else |
101 CloudPolicyManager* user_cloud_policy_manager = | 104 CloudPolicyManager* user_cloud_policy_manager = |
102 UserCloudPolicyManagerFactory::GetForBrowserContext(profile); | 105 UserCloudPolicyManagerFactory::GetForBrowserContext(profile); |
103 #endif | 106 #endif |
104 #else | 107 #else |
105 CloudPolicyManager* user_cloud_policy_manager = NULL; | 108 CloudPolicyManager* user_cloud_policy_manager = NULL; |
106 #endif | 109 #endif |
107 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); | 110 ProfilePolicyConnector* connector = new ProfilePolicyConnector(); |
108 connector->Init(force_immediate_load, | 111 connector->Init(force_immediate_load, |
109 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) | 112 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) |
110 user, | 113 user, |
| 114 schema_registry, |
111 #endif | 115 #endif |
112 user_cloud_policy_manager); | 116 user_cloud_policy_manager); |
113 connectors_[profile] = connector; | 117 connectors_[profile] = connector; |
114 return make_scoped_ptr(connector); | 118 return make_scoped_ptr(connector); |
115 } | 119 } |
116 | 120 |
117 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 121 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
118 content::BrowserContext* context) { | 122 content::BrowserContext* context) { |
119 Profile* profile = static_cast<Profile*>(context); | 123 Profile* profile = static_cast<Profile*>(context); |
120 if (profile->IsOffTheRecord()) | 124 if (profile->IsOffTheRecord()) |
121 return; | 125 return; |
122 ConnectorMap::iterator it = connectors_.find(profile); | 126 ConnectorMap::iterator it = connectors_.find(profile); |
123 if (it != connectors_.end()) | 127 if (it != connectors_.end()) |
124 it->second->Shutdown(); | 128 it->second->Shutdown(); |
125 } | 129 } |
126 | 130 |
127 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( | 131 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( |
128 content::BrowserContext* context) { | 132 content::BrowserContext* context) { |
129 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); | 133 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); |
130 if (it != connectors_.end()) | 134 if (it != connectors_.end()) |
131 connectors_.erase(it); | 135 connectors_.erase(it); |
132 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); | 136 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); |
133 } | 137 } |
134 | 138 |
135 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( | 139 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( |
136 user_prefs::PrefRegistrySyncable* registry) { | 140 user_prefs::PrefRegistrySyncable* registry) { |
137 #if defined(OS_CHROMEOS) | |
138 registry->RegisterBooleanPref( | |
139 prefs::kUsedPolicyCertificatesOnce, | |
140 false, | |
141 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
142 #endif | |
143 #if defined(OS_ANDROID) | 141 #if defined(OS_ANDROID) |
144 registry->RegisterListPref( | 142 registry->RegisterListPref( |
145 prefs::kManagedBookmarks, | 143 prefs::kManagedBookmarks, |
146 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 144 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
147 #endif | 145 #endif |
148 } | 146 } |
149 | 147 |
150 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( | 148 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( |
151 content::BrowserContext* context) {} | 149 content::BrowserContext* context) {} |
152 | 150 |
153 void ProfilePolicyConnectorFactory::CreateServiceNow( | 151 void ProfilePolicyConnectorFactory::CreateServiceNow( |
154 content::BrowserContext* context) {} | 152 content::BrowserContext* context) {} |
155 | 153 |
156 } // namespace policy | 154 } // namespace policy |
OLD | NEW |