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.h" | 5 #include "chrome/browser/policy/profile_policy_connector.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/policy/browser_policy_connector.h" | 11 #include "chrome/browser/policy/browser_policy_connector.h" |
12 #include "chrome/browser/policy/configuration_policy_provider.h" | 12 #include "chrome/browser/policy/configuration_policy_provider.h" |
13 #include "chrome/browser/policy/policy_service_impl.h" | 13 #include "chrome/browser/policy/policy_service_impl.h" |
14 | 14 |
15 #if defined(ENABLE_MANAGED_USERS) | 15 #if defined(ENABLE_MANAGED_USERS) |
16 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 16 #include "chrome/browser/policy/managed_mode_policy_provider.h" |
17 #endif | 17 #endif |
18 | 18 |
19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
20 #include "base/bind.h" | 20 #include "base/bind.h" |
21 #include "base/prefs/pref_service.h" | 21 #include "base/prefs/pref_service.h" |
22 #include "chrome/browser/chromeos/login/user.h" | 22 #include "chrome/browser/chromeos/login/user.h" |
23 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_manager.h" |
24 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" | 24 #include "chrome/browser/chromeos/policy/device_local_account_policy_provider.h" |
25 #include "chrome/browser/chromeos/policy/login_profile_policy_provider.h" | |
26 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" | 25 #include "chrome/browser/chromeos/policy/network_configuration_updater.h" |
27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 26 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
28 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 27 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
29 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
30 #include "chrome/browser/policy/policy_service.h" | |
31 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
32 #include "chromeos/dbus/cryptohome_client.h" | 30 #include "chromeos/dbus/cryptohome_client.h" |
33 #include "chromeos/dbus/dbus_thread_manager.h" | 31 #include "chromeos/dbus/dbus_thread_manager.h" |
34 #else | 32 #else |
35 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" | 33 #include "chrome/browser/policy/cloud/user_cloud_policy_manager.h" |
36 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" | 34 #include "chrome/browser/policy/cloud/user_cloud_policy_manager_factory.h" |
37 #endif | 35 #endif |
38 | 36 |
39 namespace policy { | 37 namespace policy { |
40 | 38 |
(...skipping 16 matching lines...) Expand all Loading... |
57 std::vector<ConfigurationPolicyProvider*> providers; | 55 std::vector<ConfigurationPolicyProvider*> providers; |
58 | 56 |
59 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
60 UserCloudPolicyManagerChromeOS* cloud_policy_manager = | 58 UserCloudPolicyManagerChromeOS* cloud_policy_manager = |
61 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile_); | 59 UserCloudPolicyManagerFactoryChromeOS::GetForProfile(profile_); |
62 if (cloud_policy_manager) | 60 if (cloud_policy_manager) |
63 providers.push_back(cloud_policy_manager); | 61 providers.push_back(cloud_policy_manager); |
64 | 62 |
65 bool is_managed = false; | 63 bool is_managed = false; |
66 std::string username; | 64 std::string username; |
67 if (chromeos::ProfileHelper::IsSigninProfile(profile_)) { | 65 if (!chromeos::ProfileHelper::IsSigninProfile(profile_)) { |
68 special_user_policy_provider_.reset(new LoginProfilePolicyProvider( | |
69 connector->GetPolicyService())); | |
70 special_user_policy_provider_->Init(); | |
71 } else { | |
72 // |user| should never be NULL except for the signin profile. | 66 // |user| should never be NULL except for the signin profile. |
73 // TODO(joaodasilva): get the |user| that corresponds to the |profile_| | 67 // TODO(joaodasilva): get the |user| that corresponds to the |profile_| |
74 // from the ProfileHelper, once that's ready. | 68 // from the ProfileHelper, once that's ready. |
75 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 69 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
76 chromeos::User* user = user_manager->GetActiveUser(); | 70 chromeos::User* user = user_manager->GetActiveUser(); |
77 CHECK(user); | 71 CHECK(user); |
78 // Check if |user| is managed, and if it's a public account. | 72 // Check if |user| is managed, and if it's a public account. |
79 username = user->email(); | 73 username = user->email(); |
80 is_managed = | 74 is_managed = |
81 connector->GetUserAffiliation(username) == USER_AFFILIATION_MANAGED; | 75 connector->GetUserAffiliation(username) == USER_AFFILIATION_MANAGED; |
82 is_primary_user_ = | 76 is_primary_user_ = |
83 chromeos::UserManager::Get()->GetLoggedInUsers().size() == 1; | 77 chromeos::UserManager::Get()->GetLoggedInUsers().size() == 1; |
84 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) | 78 if (user->GetType() == chromeos::User::USER_TYPE_PUBLIC_ACCOUNT) |
85 InitializeDeviceLocalAccountPolicyProvider(username); | 79 InitializeDeviceLocalAccountPolicyProvider(username); |
| 80 if (device_local_account_policy_provider_) |
| 81 providers.push_back(device_local_account_policy_provider_.get()); |
86 } | 82 } |
87 if (special_user_policy_provider_) | |
88 providers.push_back(special_user_policy_provider_.get()); | |
89 | |
90 #else | 83 #else |
91 UserCloudPolicyManager* cloud_policy_manager = | 84 UserCloudPolicyManager* cloud_policy_manager = |
92 UserCloudPolicyManagerFactory::GetForProfile(profile_); | 85 UserCloudPolicyManagerFactory::GetForProfile(profile_); |
93 if (cloud_policy_manager) | 86 if (cloud_policy_manager) |
94 providers.push_back(cloud_policy_manager); | 87 providers.push_back(cloud_policy_manager); |
95 #endif | 88 #endif |
96 | 89 |
97 #if defined(ENABLE_MANAGED_USERS) | 90 #if defined(ENABLE_MANAGED_USERS) |
98 managed_mode_policy_provider_ = ManagedModePolicyProvider::Create( | 91 managed_mode_policy_provider_ = ManagedModePolicyProvider::Create( |
99 profile_, sequenced_task_runner, force_immediate_load); | 92 profile_, sequenced_task_runner, force_immediate_load); |
100 managed_mode_policy_provider_->Init(); | 93 managed_mode_policy_provider_->Init(); |
101 providers.push_back(managed_mode_policy_provider_.get()); | 94 providers.push_back(managed_mode_policy_provider_.get()); |
102 #endif | 95 #endif |
103 | 96 |
104 policy_service_ = connector->CreatePolicyService(providers); | 97 policy_service_ = connector->CreatePolicyService(providers); |
105 | 98 |
106 #if defined(OS_CHROMEOS) | 99 #if defined(OS_CHROMEOS) |
107 if (is_primary_user_) { | 100 if (is_primary_user_) { |
108 if (cloud_policy_manager) | 101 if (cloud_policy_manager) { |
109 connector->SetUserPolicyDelegate(cloud_policy_manager); | 102 connector->SetUserPolicyDelegate(cloud_policy_manager); |
110 else if (special_user_policy_provider_) | 103 } else if (device_local_account_policy_provider_) { |
111 connector->SetUserPolicyDelegate(special_user_policy_provider_.get()); | 104 connector->SetUserPolicyDelegate( |
| 105 device_local_account_policy_provider_.get()); |
| 106 } |
112 | 107 |
113 chromeos::CryptohomeClient* cryptohome_client = | 108 chromeos::CryptohomeClient* cryptohome_client = |
114 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); | 109 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); |
115 cryptohome_client->GetSanitizedUsername( | 110 cryptohome_client->GetSanitizedUsername( |
116 username, | 111 username, |
117 base::Bind( | 112 base::Bind( |
118 &ProfilePolicyConnector::InitializeNetworkConfigurationUpdater, | 113 &ProfilePolicyConnector::InitializeNetworkConfigurationUpdater, |
119 weak_ptr_factory_.GetWeakPtr(), | 114 weak_ptr_factory_.GetWeakPtr(), |
120 is_managed)); | 115 is_managed)); |
121 } | 116 } |
122 #endif | 117 #endif |
123 } | 118 } |
124 | 119 |
125 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { | 120 void ProfilePolicyConnector::InitForTesting(scoped_ptr<PolicyService> service) { |
126 policy_service_ = service.Pass(); | 121 policy_service_ = service.Pass(); |
127 } | 122 } |
128 | 123 |
129 void ProfilePolicyConnector::Shutdown() { | 124 void ProfilePolicyConnector::Shutdown() { |
130 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
131 if (is_primary_user_) { | 126 if (is_primary_user_) { |
132 BrowserPolicyConnector* connector = | 127 BrowserPolicyConnector* connector = |
133 g_browser_process->browser_policy_connector(); | 128 g_browser_process->browser_policy_connector(); |
134 connector->SetUserPolicyDelegate(NULL); | 129 connector->SetUserPolicyDelegate(NULL); |
135 NetworkConfigurationUpdater* network_updater = | 130 NetworkConfigurationUpdater* network_updater = |
136 connector->GetNetworkConfigurationUpdater(); | 131 connector->GetNetworkConfigurationUpdater(); |
137 network_updater->UnsetUserPolicyService(); | 132 network_updater->UnsetUserPolicyService(); |
138 } | 133 } |
139 if (special_user_policy_provider_) | 134 if (device_local_account_policy_provider_) |
140 special_user_policy_provider_->Shutdown(); | 135 device_local_account_policy_provider_->Shutdown(); |
141 #endif | 136 #endif |
142 | 137 |
143 #if defined(ENABLE_MANAGED_USERS) | 138 #if defined(ENABLE_MANAGED_USERS) |
144 if (managed_mode_policy_provider_) | 139 if (managed_mode_policy_provider_) |
145 managed_mode_policy_provider_->Shutdown(); | 140 managed_mode_policy_provider_->Shutdown(); |
146 #endif | 141 #endif |
147 } | 142 } |
148 | 143 |
149 bool ProfilePolicyConnector::UsedPolicyCertificates() { | 144 bool ProfilePolicyConnector::UsedPolicyCertificates() { |
150 #if defined(OS_CHROMEOS) | 145 #if defined(OS_CHROMEOS) |
151 return profile_->GetPrefs()->GetBoolean(prefs::kUsedPolicyCertificatesOnce); | 146 return profile_->GetPrefs()->GetBoolean(prefs::kUsedPolicyCertificatesOnce); |
152 #else | 147 #else |
153 return false; | 148 return false; |
154 #endif | 149 #endif |
155 } | 150 } |
156 | 151 |
157 #if defined(OS_CHROMEOS) | 152 #if defined(OS_CHROMEOS) |
158 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( | 153 void ProfilePolicyConnector::InitializeDeviceLocalAccountPolicyProvider( |
159 const std::string& username) { | 154 const std::string& username) { |
160 BrowserPolicyConnector* connector = | 155 BrowserPolicyConnector* connector = |
161 g_browser_process->browser_policy_connector(); | 156 g_browser_process->browser_policy_connector(); |
162 DeviceLocalAccountPolicyService* device_local_account_policy_service = | 157 DeviceLocalAccountPolicyService* device_local_account_policy_service = |
163 connector->GetDeviceLocalAccountPolicyService(); | 158 connector->GetDeviceLocalAccountPolicyService(); |
164 if (!device_local_account_policy_service) | 159 if (!device_local_account_policy_service) |
165 return; | 160 return; |
166 special_user_policy_provider_.reset(new DeviceLocalAccountPolicyProvider( | 161 device_local_account_policy_provider_.reset( |
167 username, device_local_account_policy_service)); | 162 new DeviceLocalAccountPolicyProvider( |
168 special_user_policy_provider_->Init(); | 163 username, device_local_account_policy_service)); |
| 164 device_local_account_policy_provider_->Init(); |
169 } | 165 } |
170 | 166 |
171 void ProfilePolicyConnector::InitializeNetworkConfigurationUpdater( | 167 void ProfilePolicyConnector::InitializeNetworkConfigurationUpdater( |
172 bool is_managed, | 168 bool is_managed, |
173 chromeos::DBusMethodCallStatus status, | 169 chromeos::DBusMethodCallStatus status, |
174 const std::string& hashed_username) { | 170 const std::string& hashed_username) { |
175 // TODO(joaodasilva): create the NetworkConfigurationUpdater for user ONC | 171 // TODO(joaodasilva): create the NetworkConfigurationUpdater for user ONC |
176 // here, after splitting that class into an instance for device policy and | 172 // here, after splitting that class into an instance for device policy and |
177 // another per profile for user policy. | 173 // another per profile for user policy. |
178 BrowserPolicyConnector* connector = | 174 BrowserPolicyConnector* connector = |
179 g_browser_process->browser_policy_connector(); | 175 g_browser_process->browser_policy_connector(); |
180 NetworkConfigurationUpdater* network_updater = | 176 NetworkConfigurationUpdater* network_updater = |
181 connector->GetNetworkConfigurationUpdater(); | 177 connector->GetNetworkConfigurationUpdater(); |
182 network_updater->SetUserPolicyService( | 178 network_updater->SetUserPolicyService( |
183 is_managed, hashed_username, policy_service()); | 179 is_managed, hashed_username, policy_service()); |
184 } | 180 } |
185 #endif | 181 #endif |
186 | 182 |
187 } // namespace policy | 183 } // namespace policy |
OLD | NEW |