| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chromeos/policy/user_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/metrics/sparse_histogram.h" | 11 #include "base/metrics/sparse_histogram.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 14 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" | 15 #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chrom
eos.h" |
| 16 #include "chrome/browser/chromeos/policy/wildcard_login_checker.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/lifetime/application_lifetime.h" |
| 17 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" | 19 #include "components/policy/core/common/cloud/cloud_external_data_manager.h" |
| 18 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h" |
| 19 #include "components/policy/core/common/cloud/device_management_service.h" | 21 #include "components/policy/core/common/cloud/device_management_service.h" |
| 20 #include "components/policy/core/common/cloud/system_policy_request_context.h" | 22 #include "components/policy/core/common/cloud/system_policy_request_context.h" |
| 21 #include "components/policy/core/common/policy_pref_names.h" | 23 #include "components/policy/core/common/policy_pref_names.h" |
| 22 #include "content/public/common/content_client.h" | 24 #include "content/public/common/content_client.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 25 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 25 | 27 |
| 26 namespace em = enterprise_management; | 28 namespace em = enterprise_management; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token"; | 42 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayOAuth2Token"; |
| 41 const char kUMAInitialFetchDelayPolicyFetch[] = | 43 const char kUMAInitialFetchDelayPolicyFetch[] = |
| 42 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch"; | 44 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayPolicyFetch"; |
| 43 const char kUMAInitialFetchDelayTotal[] = | 45 const char kUMAInitialFetchDelayTotal[] = |
| 44 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal"; | 46 "Enterprise.UserPolicyChromeOS.InitialFetch.DelayTotal"; |
| 45 const char kUMAInitialFetchOAuth2Error[] = | 47 const char kUMAInitialFetchOAuth2Error[] = |
| 46 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; | 48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2Error"; |
| 47 const char kUMAInitialFetchOAuth2NetworkError[] = | 49 const char kUMAInitialFetchOAuth2NetworkError[] = |
| 48 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; | 50 "Enterprise.UserPolicyChromeOS.InitialFetch.OAuth2NetworkError"; |
| 49 | 51 |
| 52 void OnWildcardCheckCompleted(const std::string& username, bool result) { |
| 53 if (!result) { |
| 54 LOG(ERROR) << "Online wildcard login check failed, terminating session."; |
| 55 |
| 56 // TODO(mnissler): This only removes the user pod from the login screen, but |
| 57 // the cryptohome remains. This is because deleting the cryptohome for a |
| 58 // logged-in session is not possible. Fix this either by delaying the |
| 59 // cryptohome deletion operation or by getting rid of the in-session |
| 60 // wildcard check. |
| 61 chromeos::UserManager::Get()->RemoveUserFromList(username); |
| 62 chrome::AttemptUserExit(); |
| 63 } |
| 64 } |
| 65 |
| 50 } // namespace | 66 } // namespace |
| 51 | 67 |
| 52 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( | 68 UserCloudPolicyManagerChromeOS::UserCloudPolicyManagerChromeOS( |
| 53 scoped_ptr<CloudPolicyStore> store, | 69 scoped_ptr<CloudPolicyStore> store, |
| 54 scoped_ptr<CloudExternalDataManager> external_data_manager, | 70 scoped_ptr<CloudExternalDataManager> external_data_manager, |
| 55 const base::FilePath& component_policy_cache_path, | 71 const base::FilePath& component_policy_cache_path, |
| 56 bool wait_for_policy_fetch, | 72 bool wait_for_policy_fetch, |
| 57 base::TimeDelta initial_policy_fetch_timeout, | 73 base::TimeDelta initial_policy_fetch_timeout, |
| 58 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 74 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
| 59 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, | 75 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 if (service()->IsInitializationComplete()) { | 134 if (service()->IsInitializationComplete()) { |
| 119 OnInitializationCompleted(service()); | 135 OnInitializationCompleted(service()); |
| 120 } else { | 136 } else { |
| 121 service()->AddObserver(this); | 137 service()->AddObserver(this); |
| 122 } | 138 } |
| 123 } | 139 } |
| 124 | 140 |
| 125 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( | 141 void UserCloudPolicyManagerChromeOS::OnAccessTokenAvailable( |
| 126 const std::string& access_token) { | 142 const std::string& access_token) { |
| 127 access_token_ = access_token; | 143 access_token_ = access_token; |
| 144 |
| 145 if (!wildcard_username_.empty()) { |
| 146 wildcard_login_checker_.reset(new WildcardLoginChecker()); |
| 147 wildcard_login_checker_->StartWithAccessToken( |
| 148 access_token, |
| 149 base::Bind(&OnWildcardCheckCompleted, wildcard_username_)); |
| 150 } |
| 151 |
| 128 if (service() && service()->IsInitializationComplete() && | 152 if (service() && service()->IsInitializationComplete() && |
| 129 client() && !client()->is_registered()) { | 153 client() && !client()->is_registered()) { |
| 130 OnOAuth2PolicyTokenFetched( | 154 OnOAuth2PolicyTokenFetched( |
| 131 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | 155 access_token, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); |
| 132 } | 156 } |
| 133 } | 157 } |
| 134 | 158 |
| 135 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const { | 159 bool UserCloudPolicyManagerChromeOS::IsClientRegistered() const { |
| 136 return client() && client()->is_registered(); | 160 return client() && client()->is_registered(); |
| 137 } | 161 } |
| 138 | 162 |
| 163 void UserCloudPolicyManagerChromeOS::EnableWildcardLoginCheck( |
| 164 const std::string& username) { |
| 165 DCHECK(access_token_.empty()); |
| 166 wildcard_username_ = username; |
| 167 } |
| 168 |
| 139 void UserCloudPolicyManagerChromeOS::Shutdown() { | 169 void UserCloudPolicyManagerChromeOS::Shutdown() { |
| 140 if (client()) | 170 if (client()) |
| 141 client()->RemoveObserver(this); | 171 client()->RemoveObserver(this); |
| 142 if (service()) | 172 if (service()) |
| 143 service()->RemoveObserver(this); | 173 service()->RemoveObserver(this); |
| 144 token_fetcher_.reset(); | 174 token_fetcher_.reset(); |
| 145 external_data_manager_->Disconnect(); | 175 external_data_manager_->Disconnect(); |
| 146 CloudPolicyManager::Shutdown(); | 176 CloudPolicyManager::Shutdown(); |
| 147 } | 177 } |
| 148 | 178 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 174 // | 204 // |
| 175 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder | 205 // If |wait_for_policy_fetch_| is false then the UserCloudPolicyTokenForwarder |
| 176 // service will eventually call OnAccessTokenAvailable() once an access token | 206 // service will eventually call OnAccessTokenAvailable() once an access token |
| 177 // is available. That call may have already happened while waiting for | 207 // is available. That call may have already happened while waiting for |
| 178 // initialization of the CloudPolicyService, so in that case check if an | 208 // initialization of the CloudPolicyService, so in that case check if an |
| 179 // access token is already available. | 209 // access token is already available. |
| 180 if (!client()->is_registered()) { | 210 if (!client()->is_registered()) { |
| 181 if (wait_for_policy_fetch_) { | 211 if (wait_for_policy_fetch_) { |
| 182 FetchPolicyOAuthTokenUsingSigninProfile(); | 212 FetchPolicyOAuthTokenUsingSigninProfile(); |
| 183 } else if (!access_token_.empty()) { | 213 } else if (!access_token_.empty()) { |
| 184 OnOAuth2PolicyTokenFetched( | 214 OnAccessTokenAvailable(access_token_); |
| 185 access_token_, GoogleServiceAuthError(GoogleServiceAuthError::NONE)); | |
| 186 } | 215 } |
| 187 } | 216 } |
| 188 | 217 |
| 189 if (!wait_for_policy_fetch_) { | 218 if (!wait_for_policy_fetch_) { |
| 190 // If this isn't blocking on a policy fetch then | 219 // If this isn't blocking on a policy fetch then |
| 191 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. | 220 // CloudPolicyManager::OnStoreLoaded() already published the cached policy. |
| 192 // Start the refresh scheduler now, which will eventually refresh the | 221 // Start the refresh scheduler now, which will eventually refresh the |
| 193 // cached policy or make the first fetch once the OAuth2 token is | 222 // cached policy or make the first fetch once the OAuth2 token is |
| 194 // available. | 223 // available. |
| 195 StartRefreshSchedulerIfReady(); | 224 StartRefreshSchedulerIfReady(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 g_browser_process->system_request_context(), | 289 g_browser_process->system_request_context(), |
| 261 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, | 290 base::Bind(&UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched, |
| 262 base::Unretained(this)))); | 291 base::Unretained(this)))); |
| 263 token_fetcher_->Start(); | 292 token_fetcher_->Start(); |
| 264 } | 293 } |
| 265 | 294 |
| 266 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( | 295 void UserCloudPolicyManagerChromeOS::OnOAuth2PolicyTokenFetched( |
| 267 const std::string& policy_token, | 296 const std::string& policy_token, |
| 268 const GoogleServiceAuthError& error) { | 297 const GoogleServiceAuthError& error) { |
| 269 DCHECK(!client()->is_registered()); | 298 DCHECK(!client()->is_registered()); |
| 270 | |
| 271 time_token_available_ = base::Time::Now(); | 299 time_token_available_ = base::Time::Now(); |
| 272 if (wait_for_policy_fetch_) { | 300 if (wait_for_policy_fetch_) { |
| 273 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayOAuth2Token, | 301 UMA_HISTOGRAM_MEDIUM_TIMES(kUMAInitialFetchDelayOAuth2Token, |
| 274 time_token_available_ - time_init_completed_); | 302 time_token_available_ - time_init_completed_); |
| 275 } | 303 } |
| 276 | 304 |
| 277 if (error.state() == GoogleServiceAuthError::NONE) { | 305 if (error.state() == GoogleServiceAuthError::NONE) { |
| 278 // Start client registration. Either OnRegistrationStateChanged() or | 306 // Start client registration. Either OnRegistrationStateChanged() or |
| 279 // OnClientError() will be called back. | 307 // OnClientError() will be called back. |
| 280 client()->Register(em::DeviceRegisterRequest::USER, | 308 client()->Register(em::DeviceRegisterRequest::USER, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 // OnComponentCloudPolicyUpdated() once it's ready. | 370 // OnComponentCloudPolicyUpdated() once it's ready. |
| 343 return; | 371 return; |
| 344 } | 372 } |
| 345 | 373 |
| 346 core()->StartRefreshScheduler(); | 374 core()->StartRefreshScheduler(); |
| 347 core()->TrackRefreshDelayPref(local_state_, | 375 core()->TrackRefreshDelayPref(local_state_, |
| 348 policy_prefs::kUserPolicyRefreshRate); | 376 policy_prefs::kUserPolicyRefreshRate); |
| 349 } | 377 } |
| 350 | 378 |
| 351 } // namespace policy | 379 } // namespace policy |
| OLD | NEW |