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) |
92 chromeos::User* user = NULL; | 93 chromeos::User* user = NULL; |
93 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { | 94 SchemaRegistry* schema_registry = NULL; |
95 if (chromeos::ProfileHelper::IsSigninProfile(profile)) { | |
96 schema_registry = SchemaRegistryServiceFactory::GetForContext(profile); | |
Joao da Silva
2013/11/13 09:45:58
The schema_registry is also needed for non-signin
| |
97 } else { | |
94 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 98 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
95 user = user_manager->GetUserByProfile(profile); | 99 user = user_manager->GetUserByProfile(profile); |
96 CHECK(user); | 100 CHECK(user); |
97 } | 101 } |
98 CloudPolicyManager* user_cloud_policy_manager = | 102 CloudPolicyManager* user_cloud_policy_manager = |
99 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); | 103 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); |
100 #else | 104 #else |
101 CloudPolicyManager* user_cloud_policy_manager = | 105 CloudPolicyManager* user_cloud_policy_manager = |
102 UserCloudPolicyManagerFactory::GetForBrowserContext(profile); | 106 UserCloudPolicyManagerFactory::GetForBrowserContext(profile); |
103 #endif | 107 #endif |
104 #else | 108 #else |
105 CloudPolicyManager* user_cloud_policy_manager = NULL; | 109 CloudPolicyManager* user_cloud_policy_manager = NULL; |
106 #endif | 110 #endif |
107 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); | 111 ProfilePolicyConnector* connector = new ProfilePolicyConnector(); |
108 connector->Init(force_immediate_load, | 112 connector->Init(force_immediate_load, |
109 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) | 113 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) |
110 user, | 114 user, |
115 schema_registry, | |
111 #endif | 116 #endif |
112 user_cloud_policy_manager); | 117 user_cloud_policy_manager); |
113 connectors_[profile] = connector; | 118 connectors_[profile] = connector; |
114 return make_scoped_ptr(connector); | 119 return make_scoped_ptr(connector); |
115 } | 120 } |
116 | 121 |
117 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 122 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
118 content::BrowserContext* context) { | 123 content::BrowserContext* context) { |
119 Profile* profile = static_cast<Profile*>(context); | 124 Profile* profile = static_cast<Profile*>(context); |
120 if (profile->IsOffTheRecord()) | 125 if (profile->IsOffTheRecord()) |
121 return; | 126 return; |
122 ConnectorMap::iterator it = connectors_.find(profile); | 127 ConnectorMap::iterator it = connectors_.find(profile); |
123 if (it != connectors_.end()) | 128 if (it != connectors_.end()) |
124 it->second->Shutdown(); | 129 it->second->Shutdown(); |
125 } | 130 } |
126 | 131 |
127 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( | 132 void ProfilePolicyConnectorFactory::BrowserContextDestroyed( |
128 content::BrowserContext* context) { | 133 content::BrowserContext* context) { |
129 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); | 134 ConnectorMap::iterator it = connectors_.find(static_cast<Profile*>(context)); |
130 if (it != connectors_.end()) | 135 if (it != connectors_.end()) |
131 connectors_.erase(it); | 136 connectors_.erase(it); |
132 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); | 137 BrowserContextKeyedBaseFactory::BrowserContextDestroyed(context); |
133 } | 138 } |
134 | 139 |
135 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( | 140 void ProfilePolicyConnectorFactory::RegisterProfilePrefs( |
136 user_prefs::PrefRegistrySyncable* registry) { | 141 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) | 142 #if defined(OS_ANDROID) |
144 registry->RegisterListPref( | 143 registry->RegisterListPref( |
145 prefs::kManagedBookmarks, | 144 prefs::kManagedBookmarks, |
146 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 145 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
147 #endif | 146 #endif |
148 } | 147 } |
149 | 148 |
150 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( | 149 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( |
151 content::BrowserContext* context) {} | 150 content::BrowserContext* context) {} |
152 | 151 |
153 void ProfilePolicyConnectorFactory::CreateServiceNow( | 152 void ProfilePolicyConnectorFactory::CreateServiceNow( |
154 content::BrowserContext* context) {} | 153 content::BrowserContext* context) {} |
155 | 154 |
156 } // namespace policy | 155 } // namespace policy |
OLD | NEW |