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