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 "chrome/browser/policy/profile_policy_connector.h" | 9 #include "chrome/browser/policy/profile_policy_connector.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
11 #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" |
12 #include "components/user_prefs/pref_registry_syncable.h" | 13 #include "components/user_prefs/pref_registry_syncable.h" |
13 | 14 |
14 #if defined(ENABLE_CONFIGURATION_POLICY) | 15 #if defined(ENABLE_CONFIGURATION_POLICY) |
15 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
| 17 #include "chrome/browser/chromeos/login/user.h" |
16 #include "chrome/browser/chromeos/login/user_manager.h" | 18 #include "chrome/browser/chromeos/login/user_manager.h" |
| 19 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
17 #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" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
18 #else | 22 #else |
| 23 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
19 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 24 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
20 #endif | 25 #endif |
21 #endif | 26 #endif |
22 | 27 |
23 namespace policy { | 28 namespace policy { |
24 | 29 |
25 // static | 30 // static |
26 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { | 31 ProfilePolicyConnectorFactory* ProfilePolicyConnectorFactory::GetInstance() { |
27 return Singleton<ProfilePolicyConnectorFactory>::get(); | 32 return Singleton<ProfilePolicyConnectorFactory>::get(); |
28 } | 33 } |
29 | 34 |
30 // static | 35 // static |
31 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( | 36 ProfilePolicyConnector* ProfilePolicyConnectorFactory::GetForProfile( |
32 Profile* profile) { | 37 Profile* profile) { |
33 return GetInstance()->GetForProfileInternal(profile); | 38 return GetInstance()->GetForProfileInternal(profile); |
34 } | 39 } |
35 | 40 |
36 // static | 41 // static |
37 scoped_ptr<ProfilePolicyConnector> | 42 scoped_ptr<ProfilePolicyConnector> |
38 ProfilePolicyConnectorFactory::CreateForProfile( | 43 ProfilePolicyConnectorFactory::CreateForProfile(Profile* profile, |
39 Profile* profile, | 44 bool force_immediate_load) { |
40 bool force_immediate_load) { | |
41 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load); | 45 return GetInstance()->CreateForProfileInternal(profile, force_immediate_load); |
42 } | 46 } |
43 | 47 |
44 void ProfilePolicyConnectorFactory::SetServiceForTesting( | 48 void ProfilePolicyConnectorFactory::SetServiceForTesting( |
45 Profile* profile, | 49 Profile* profile, |
46 ProfilePolicyConnector* connector) { | 50 ProfilePolicyConnector* connector) { |
47 ProfilePolicyConnector*& map_entry = connectors_[profile]; | 51 ProfilePolicyConnector*& map_entry = connectors_[profile]; |
48 CHECK(!map_entry); | 52 CHECK(!map_entry); |
49 map_entry = connector; | 53 map_entry = connector; |
50 } | 54 } |
(...skipping 19 matching lines...) Expand all Loading... |
70 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { | 74 ProfilePolicyConnectorFactory::GetForProfileInternal(Profile* profile) { |
71 // Get the connector for the original Profile, so that the incognito Profile | 75 // Get the connector for the original Profile, so that the incognito Profile |
72 // gets managed settings from the same PolicyService. | 76 // gets managed settings from the same PolicyService. |
73 ConnectorMap::const_iterator it = | 77 ConnectorMap::const_iterator it = |
74 connectors_.find(profile->GetOriginalProfile()); | 78 connectors_.find(profile->GetOriginalProfile()); |
75 CHECK(it != connectors_.end()); | 79 CHECK(it != connectors_.end()); |
76 return it->second; | 80 return it->second; |
77 } | 81 } |
78 | 82 |
79 scoped_ptr<ProfilePolicyConnector> | 83 scoped_ptr<ProfilePolicyConnector> |
80 ProfilePolicyConnectorFactory::CreateForProfileInternal( | 84 ProfilePolicyConnectorFactory::CreateForProfileInternal( |
81 Profile* profile, | 85 Profile* profile, |
82 bool force_immediate_load) { | 86 bool force_immediate_load) { |
83 DCHECK(connectors_.find(profile) == connectors_.end()); | 87 DCHECK(connectors_.find(profile) == connectors_.end()); |
| 88 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 89 #if defined(OS_CHROMEOS) |
| 90 chromeos::User* user = NULL; |
| 91 if (!chromeos::ProfileHelper::IsSigninProfile(profile)) { |
| 92 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 93 user = user_manager->GetUserByProfile(profile); |
| 94 CHECK(user); |
| 95 } |
| 96 CloudPolicyManager* user_cloud_policy_manager = |
| 97 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile); |
| 98 #else |
| 99 CloudPolicyManager* user_cloud_policy_manager = |
| 100 UserCloudPolicyManagerFactory::GetForProfile(profile); |
| 101 #endif |
| 102 #else |
| 103 CloudPolicyManager* user_cloud_policy_manager = NULL; |
| 104 #endif |
84 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); | 105 ProfilePolicyConnector* connector = new ProfilePolicyConnector(profile); |
85 connector->Init(force_immediate_load); | 106 connector->Init(force_immediate_load, |
| 107 #if defined(ENABLE_CONFIGURATION_POLICY) && defined(OS_CHROMEOS) |
| 108 user, |
| 109 #endif |
| 110 user_cloud_policy_manager); |
86 connectors_[profile] = connector; | 111 connectors_[profile] = connector; |
87 return scoped_ptr<ProfilePolicyConnector>(connector); | 112 return make_scoped_ptr(connector); |
88 } | 113 } |
89 | 114 |
90 void ProfilePolicyConnectorFactory::BrowserContextShutdown( | 115 void ProfilePolicyConnectorFactory::BrowserContextShutdown( |
91 content::BrowserContext* context) { | 116 content::BrowserContext* context) { |
92 Profile* profile = static_cast<Profile*>(context); | 117 Profile* profile = static_cast<Profile*>(context); |
93 if (profile->IsOffTheRecord()) | 118 if (profile->IsOffTheRecord()) |
94 return; | 119 return; |
95 ConnectorMap::iterator it = connectors_.find(profile); | 120 ConnectorMap::iterator it = connectors_.find(profile); |
96 if (it != connectors_.end()) | 121 if (it != connectors_.end()) |
97 it->second->Shutdown(); | 122 it->second->Shutdown(); |
(...skipping 22 matching lines...) Expand all Loading... |
120 #endif | 145 #endif |
121 } | 146 } |
122 | 147 |
123 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( | 148 void ProfilePolicyConnectorFactory::SetEmptyTestingFactory( |
124 content::BrowserContext* context) {} | 149 content::BrowserContext* context) {} |
125 | 150 |
126 void ProfilePolicyConnectorFactory::CreateServiceNow( | 151 void ProfilePolicyConnectorFactory::CreateServiceNow( |
127 content::BrowserContext* context) {} | 152 content::BrowserContext* context) {} |
128 | 153 |
129 } // namespace policy | 154 } // namespace policy |
OLD | NEW |