Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.cc

Issue 2642783003: Move more utility functions to arc_util. (Closed)
Patch Set: address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/arc/arc_session_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/arc/arc_auth_service.h" 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 12 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
13 #include "chrome/browser/chromeos/arc/arc_session_manager.h" 13 #include "chrome/browser/chromeos/arc/arc_session_manager.h"
14 #include "chrome/browser/chromeos/arc/auth/arc_auth_code_fetcher.h" 14 #include "chrome/browser/chromeos/arc/auth/arc_auth_code_fetcher.h"
15 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h" 15 #include "chrome/browser/chromeos/arc/auth/arc_background_auth_code_fetcher.h"
16 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h" 16 #include "chrome/browser/chromeos/arc/auth/arc_manual_auth_code_fetcher.h"
17 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h" 17 #include "chrome/browser/chromeos/arc/auth/arc_robot_auth_code_fetcher.h"
18 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" 18 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
19 #include "chrome/browser/lifetime/application_lifetime.h" 19 #include "chrome/browser/lifetime/application_lifetime.h"
20 #include "chromeos/chromeos_switches.h" 20 #include "chromeos/chromeos_switches.h"
21 #include "components/arc/arc_bridge_service.h" 21 #include "components/arc/arc_bridge_service.h"
22 #include "components/arc/arc_features.h" 22 #include "components/arc/arc_features.h"
23 #include "components/arc/arc_util.h"
23 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
24 25
25 namespace arc { 26 namespace arc {
26 namespace { 27 namespace {
27 28
28 ArcAuthService* g_arc_auth_service = nullptr; 29 ArcAuthService* g_arc_auth_service = nullptr;
29 30
30 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. 31 // Convers mojom::ArcSignInFailureReason into ProvisiningResult.
31 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( 32 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult(
32 mojom::ArcSignInFailureReason reason) { 33 mojom::ArcSignInFailureReason reason) {
(...skipping 20 matching lines...) Expand all
53 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_TIMEOUT); 54 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_TIMEOUT);
54 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_INTERNAL_ERROR); 55 MAP_PROVISIONING_RESULT(CLOUD_PROVISION_FLOW_INTERNAL_ERROR);
55 } 56 }
56 #undef MAP_PROVISIONING_RESULT 57 #undef MAP_PROVISIONING_RESULT
57 58
58 NOTREACHED() << "unknown reason: " << static_cast<int>(reason); 59 NOTREACHED() << "unknown reason: " << static_cast<int>(reason);
59 return ProvisioningResult::UNKNOWN_ERROR; 60 return ProvisioningResult::UNKNOWN_ERROR;
60 } 61 }
61 62
62 mojom::ChromeAccountType GetAccountType() { 63 mojom::ChromeAccountType GetAccountType() {
63 return ArcSessionManager::IsArcKioskMode() 64 return IsArcKioskMode() ? mojom::ChromeAccountType::ROBOT_ACCOUNT
64 ? mojom::ChromeAccountType::ROBOT_ACCOUNT 65 : mojom::ChromeAccountType::USER_ACCOUNT;
65 : mojom::ChromeAccountType::USER_ACCOUNT;
66 } 66 }
67 67
68 } // namespace 68 } // namespace
69 69
70 // TODO(lhchavez): Get rid of this class once we can safely remove all the 70 // TODO(lhchavez): Get rid of this class once we can safely remove all the
71 // deprecated interfaces and only need to care about one type of callback. 71 // deprecated interfaces and only need to care about one type of callback.
72 class ArcAuthService::AccountInfoNotifier { 72 class ArcAuthService::AccountInfoNotifier {
73 public: 73 public:
74 explicit AccountInfoNotifier( 74 explicit AccountInfoNotifier(
75 const GetAuthCodeDeprecatedCallback& auth_callback) 75 const GetAuthCodeDeprecatedCallback& auth_callback)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 void ArcAuthService::GetAuthCodeDeprecated0( 181 void ArcAuthService::GetAuthCodeDeprecated0(
182 const GetAuthCodeDeprecated0Callback& callback) { 182 const GetAuthCodeDeprecated0Callback& callback) {
183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
184 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; 184 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable";
185 } 185 }
186 186
187 void ArcAuthService::GetAuthCodeDeprecated( 187 void ArcAuthService::GetAuthCodeDeprecated(
188 const GetAuthCodeDeprecatedCallback& callback) { 188 const GetAuthCodeDeprecatedCallback& callback) {
189 // For robot account we must use RequestAccountInfo because it allows 189 // For robot account we must use RequestAccountInfo because it allows
190 // to specify account type. 190 // to specify account type.
191 DCHECK(!ArcSessionManager::IsArcKioskMode()); 191 DCHECK(!IsArcKioskMode());
192 RequestAccountInfoInternal( 192 RequestAccountInfoInternal(
193 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); 193 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback));
194 } 194 }
195 195
196 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( 196 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated(
197 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { 197 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) {
198 RequestAccountInfoInternal( 198 RequestAccountInfoInternal(
199 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); 199 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback));
200 } 200 }
201 201
202 void ArcAuthService::GetIsAccountManagedDeprecated( 202 void ArcAuthService::GetIsAccountManagedDeprecated(
203 const GetIsAccountManagedDeprecatedCallback& callback) { 203 const GetIsAccountManagedDeprecatedCallback& callback) {
204 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 204 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
205 callback.Run( 205 callback.Run(
206 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); 206 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile()));
207 } 207 }
208 208
209 void ArcAuthService::RequestAccountInfoInternal( 209 void ArcAuthService::RequestAccountInfoInternal(
210 std::unique_ptr<AccountInfoNotifier> notifier) { 210 std::unique_ptr<AccountInfoNotifier> notifier) {
211 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 211 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
212 // No other auth code-related operation may be in progress. 212 // No other auth code-related operation may be in progress.
213 DCHECK(!notifier_); 213 DCHECK(!notifier_);
214 DCHECK(!fetcher_); 214 DCHECK(!fetcher_);
215 215
216 if (ArcSessionManager::IsOptInVerificationDisabled()) { 216 if (IsArcOptInVerificationDisabled()) {
217 notifier->Notify( 217 notifier->Notify(
218 false /* = is_enforced */, std::string(), GetAccountType(), 218 false /* = is_enforced */, std::string(), GetAccountType(),
219 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); 219 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile()));
220 return; 220 return;
221 } 221 }
222 222
223 // Hereafter asynchronous operation. Remember the notifier. 223 // Hereafter asynchronous operation. Remember the notifier.
224 notifier_ = std::move(notifier); 224 notifier_ = std::move(notifier);
225 225
226 if (ArcSessionManager::IsArcKioskMode()) { 226 if (IsArcKioskMode()) {
227 // In Kiosk mode, use Robot auth code fetching. 227 // In Kiosk mode, use Robot auth code fetching.
228 fetcher_ = base::MakeUnique<ArcRobotAuthCodeFetcher>(); 228 fetcher_ = base::MakeUnique<ArcRobotAuthCodeFetcher>();
229 } else if (base::FeatureList::IsEnabled(arc::kArcUseAuthEndpointFeature)) { 229 } else if (base::FeatureList::IsEnabled(arc::kArcUseAuthEndpointFeature)) {
230 // Optionally retrieve auth code in silent mode. 230 // Optionally retrieve auth code in silent mode.
231 fetcher_ = base::MakeUnique<ArcBackgroundAuthCodeFetcher>( 231 fetcher_ = base::MakeUnique<ArcBackgroundAuthCodeFetcher>(
232 ArcSessionManager::Get()->profile(), 232 ArcSessionManager::Get()->profile(),
233 ArcSessionManager::Get()->auth_context()); 233 ArcSessionManager::Get()->auth_context());
234 } else { 234 } else {
235 // Report that silent auth code is not activated. All other states are 235 // Report that silent auth code is not activated. All other states are
236 // reported in ArcBackgroundAuthCodeFetcher. 236 // reported in ArcBackgroundAuthCodeFetcher.
237 UpdateSilentAuthCodeUMA(OptInSilentAuthCode::DISABLED); 237 UpdateSilentAuthCodeUMA(OptInSilentAuthCode::DISABLED);
238 // Otherwise, show LSO page and let user click "Sign in" button. 238 // Otherwise, show LSO page and let user click "Sign in" button.
239 // Here, support_host should be available always. The case support_host is 239 // Here, support_host should be available always. The case support_host is
240 // not created is when 1) IsOptInVerificationDisabled() is true or 2) 240 // not created is when 1) IsArcOptInVerificationDisabled() is true or 2)
241 // IsArcKioskMode() is true. Both cases are handled above. 241 // IsArcKioskMode() is true. Both cases are handled above.
242 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>( 242 fetcher_ = base::MakeUnique<ArcManualAuthCodeFetcher>(
243 ArcSessionManager::Get()->auth_context(), 243 ArcSessionManager::Get()->auth_context(),
244 ArcSessionManager::Get()->support_host()); 244 ArcSessionManager::Get()->support_host());
245 } 245 }
246 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, 246 fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched,
247 weak_ptr_factory_.GetWeakPtr())); 247 weak_ptr_factory_.GetWeakPtr()));
248 } 248 }
249 249
250 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) { 250 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) {
251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
252 fetcher_.reset(); 252 fetcher_.reset();
253 253
254 if (auth_code.empty()) { 254 if (auth_code.empty()) {
255 ArcSessionManager::Get()->OnProvisioningFinished( 255 ArcSessionManager::Get()->OnProvisioningFinished(
256 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); 256 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR);
257 return; 257 return;
258 } 258 }
259 259
260 notifier_->Notify( 260 notifier_->Notify(
261 !ArcSessionManager::IsOptInVerificationDisabled(), auth_code, 261 !IsArcOptInVerificationDisabled(), auth_code, GetAccountType(),
262 GetAccountType(),
263 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); 262 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile()));
264 notifier_.reset(); 263 notifier_.reset();
265 } 264 }
266 265
267 } // namespace arc 266 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/BUILD.gn ('k') | chrome/browser/chromeos/arc/arc_session_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698