OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/enrollment/enterprise_enrollment_helper_
impl.h" | 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_
impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() { | 85 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() { |
86 DCHECK(g_browser_process->IsShuttingDown() || !started_ || | 86 DCHECK(g_browser_process->IsShuttingDown() || !started_ || |
87 (finished_ && (success_ || auth_data_cleared_))); | 87 (finished_ && (success_ || auth_data_cleared_))); |
88 } | 88 } |
89 | 89 |
90 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode( | 90 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode( |
91 const std::string& auth_code, | 91 const std::string& auth_code, |
92 bool fetch_additional_token) { | 92 bool fetch_additional_token) { |
93 DCHECK(!started_); | 93 DCHECK(!started_); |
94 started_ = true; | 94 started_ = true; |
95 oauth_fetcher_.reset(new policy::PolicyOAuth2TokenFetcher()); | 95 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); |
96 oauth_fetcher_->StartWithAuthCode( | 96 oauth_fetcher_->StartWithAuthCode( |
97 auth_code, g_browser_process->system_request_context(), | 97 auth_code, g_browser_process->system_request_context(), |
98 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, | 98 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, |
99 weak_ptr_factory_.GetWeakPtr(), | 99 weak_ptr_factory_.GetWeakPtr(), |
100 fetch_additional_token /* is_additional_token */)); | 100 fetch_additional_token /* is_additional_token */)); |
101 } | 101 } |
102 | 102 |
103 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken( | 103 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken( |
104 const std::string& token) { | 104 const std::string& token) { |
105 DCHECK(!started_); | 105 DCHECK(!started_); |
106 started_ = true; | 106 started_ = true; |
107 DoEnrollUsingToken(token); | 107 DoEnrollUsingToken(token); |
108 } | 108 } |
109 | 109 |
110 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) { | 110 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) { |
111 // Do not revoke the additional token if enrollment has finished | 111 // Do not revoke the additional token if enrollment has finished |
112 // successfully. | 112 // successfully. |
113 if (!success_ && additional_token_.length()) | 113 if (!success_ && additional_token_.length()) |
114 (new TokenRevoker())->Start(additional_token_); | 114 (new TokenRevoker())->Start(additional_token_); |
115 | 115 |
116 if (oauth_fetcher_) { | 116 if (oauth_fetcher_) { |
117 if (!oauth_fetcher_->oauth2_access_token().empty()) | 117 if (!oauth_fetcher_->OAuth2AccessToken().empty()) |
118 (new TokenRevoker())->Start(oauth_fetcher_->oauth2_access_token()); | 118 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2AccessToken()); |
119 | 119 |
120 if (!oauth_fetcher_->oauth2_refresh_token().empty()) | 120 if (!oauth_fetcher_->OAuth2RefreshToken().empty()) |
121 (new TokenRevoker())->Start(oauth_fetcher_->oauth2_refresh_token()); | 121 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2RefreshToken()); |
122 | 122 |
123 oauth_fetcher_.reset(); | 123 oauth_fetcher_.reset(); |
124 } else if (oauth_token_.length()) { | 124 } else if (oauth_token_.length()) { |
125 // EnrollUsingToken was called. | 125 // EnrollUsingToken was called. |
126 (new TokenRevoker())->Start(oauth_token_); | 126 (new TokenRevoker())->Start(oauth_token_); |
127 } | 127 } |
128 | 128 |
129 chromeos::ProfileHelper::Get()->ClearSigninProfile( | 129 chromeos::ProfileHelper::Get()->ClearSigninProfile( |
130 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared, | 130 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared, |
131 weak_ptr_factory_.GetWeakPtr(), callback)); | 131 weak_ptr_factory_.GetWeakPtr(), callback)); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 status_consumer()->OnAuthError(error); | 203 status_consumer()->OnAuthError(error); |
204 return; | 204 return; |
205 } | 205 } |
206 | 206 |
207 if (!is_additional_token) { | 207 if (!is_additional_token) { |
208 DoEnrollUsingToken(token); | 208 DoEnrollUsingToken(token); |
209 return; | 209 return; |
210 } | 210 } |
211 | 211 |
212 additional_token_ = token; | 212 additional_token_ = token; |
213 std::string refresh_token = oauth_fetcher_->oauth2_refresh_token(); | 213 std::string refresh_token = oauth_fetcher_->OAuth2RefreshToken(); |
214 oauth_fetcher_.reset(new policy::PolicyOAuth2TokenFetcher()); | 214 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); |
215 oauth_fetcher_->StartWithRefreshToken( | 215 oauth_fetcher_->StartWithRefreshToken( |
216 refresh_token, g_browser_process->system_request_context(), | 216 refresh_token, g_browser_process->system_request_context(), |
217 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, | 217 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, |
218 weak_ptr_factory_.GetWeakPtr(), | 218 weak_ptr_factory_.GetWeakPtr(), |
219 false /* is_additional_token */)); | 219 false /* is_additional_token */)); |
220 } | 220 } |
221 | 221 |
222 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished( | 222 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished( |
223 policy::EnrollmentStatus status) { | 223 policy::EnrollmentStatus status) { |
224 ReportEnrollmentStatus(status); | 224 ReportEnrollmentStatus(status); |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 EnrollmentUMA(sample, enrollment_config_.mode); | 408 EnrollmentUMA(sample, enrollment_config_.mode); |
409 } | 409 } |
410 | 410 |
411 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( | 411 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( |
412 const base::Closure& callback) { | 412 const base::Closure& callback) { |
413 auth_data_cleared_ = true; | 413 auth_data_cleared_ = true; |
414 callback.Run(); | 414 callback.Run(); |
415 } | 415 } |
416 | 416 |
417 } // namespace chromeos | 417 } // namespace chromeos |
OLD | NEW |