OLD | NEW |
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 "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
24 | 24 |
25 namespace arc { | 25 namespace arc { |
26 namespace { | 26 namespace { |
27 | 27 |
28 ArcAuthService* g_arc_auth_service = nullptr; | 28 ArcAuthService* g_arc_auth_service = nullptr; |
29 | 29 |
30 constexpr uint32_t kMinVersionForOnAccountInfoReady = 5; | |
31 | |
32 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. | 30 // Convers mojom::ArcSignInFailureReason into ProvisiningResult. |
33 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( | 31 ProvisioningResult ConvertArcSignInFailureReasonToProvisioningResult( |
34 mojom::ArcSignInFailureReason reason) { | 32 mojom::ArcSignInFailureReason reason) { |
35 using ArcSignInFailureReason = mojom::ArcSignInFailureReason; | 33 using ArcSignInFailureReason = mojom::ArcSignInFailureReason; |
36 | 34 |
37 #define MAP_PROVISIONING_RESULT(name) \ | 35 #define MAP_PROVISIONING_RESULT(name) \ |
38 case ArcSignInFailureReason::name: \ | 36 case ArcSignInFailureReason::name: \ |
39 return ProvisioningResult::name | 37 return ProvisioningResult::name |
40 | 38 |
41 switch (reason) { | 39 switch (reason) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 g_arc_auth_service = nullptr; | 136 g_arc_auth_service = nullptr; |
139 } | 137 } |
140 | 138 |
141 // static | 139 // static |
142 ArcAuthService* ArcAuthService::GetForTest() { | 140 ArcAuthService* ArcAuthService::GetForTest() { |
143 DCHECK(g_arc_auth_service); | 141 DCHECK(g_arc_auth_service); |
144 return g_arc_auth_service; | 142 return g_arc_auth_service; |
145 } | 143 } |
146 | 144 |
147 void ArcAuthService::OnInstanceReady() { | 145 void ArcAuthService::OnInstanceReady() { |
148 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod("Init"); | 146 auto* instance = |
| 147 ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), Init); |
149 DCHECK(instance); | 148 DCHECK(instance); |
150 instance->Init(binding_.CreateInterfacePtrAndBind()); | 149 instance->Init(binding_.CreateInterfacePtrAndBind()); |
151 } | 150 } |
152 | 151 |
153 void ArcAuthService::OnInstanceClosed() { | 152 void ArcAuthService::OnInstanceClosed() { |
154 fetcher_.reset(); | 153 fetcher_.reset(); |
155 notifier_.reset(); | 154 notifier_.reset(); |
156 } | 155 } |
157 | 156 |
158 void ArcAuthService::OnSignInComplete() { | 157 void ArcAuthService::OnSignInComplete() { |
159 ArcSessionManager::Get()->OnProvisioningFinished(ProvisioningResult::SUCCESS); | 158 ArcSessionManager::Get()->OnProvisioningFinished(ProvisioningResult::SUCCESS); |
160 } | 159 } |
161 | 160 |
162 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { | 161 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { |
163 ArcSessionManager::Get()->OnProvisioningFinished( | 162 ArcSessionManager::Get()->OnProvisioningFinished( |
164 ConvertArcSignInFailureReasonToProvisioningResult(reason)); | 163 ConvertArcSignInFailureReasonToProvisioningResult(reason)); |
165 } | 164 } |
166 | 165 |
167 void ArcAuthService::RequestAccountInfo() { | 166 void ArcAuthService::RequestAccountInfo() { |
168 RequestAccountInfoInternal( | 167 RequestAccountInfoInternal( |
169 base::MakeUnique<ArcAuthService::AccountInfoNotifier>( | 168 base::MakeUnique<ArcAuthService::AccountInfoNotifier>( |
170 base::Bind(&ArcAuthService::OnAccountInfoReady, | 169 base::Bind(&ArcAuthService::OnAccountInfoReady, |
171 weak_ptr_factory_.GetWeakPtr()))); | 170 weak_ptr_factory_.GetWeakPtr()))); |
172 } | 171 } |
173 | 172 |
174 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { | 173 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { |
175 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 174 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
176 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod( | 175 auto* instance = ARC_GET_INSTANCE_FOR_METHOD(arc_bridge_service()->auth(), |
177 "OnAccountInfoReady", kMinVersionForOnAccountInfoReady); | 176 OnAccountInfoReady); |
178 DCHECK(instance); | 177 DCHECK(instance); |
179 instance->OnAccountInfoReady(std::move(account_info)); | 178 instance->OnAccountInfoReady(std::move(account_info)); |
180 } | 179 } |
181 | 180 |
182 void ArcAuthService::GetAuthCodeDeprecated0( | 181 void ArcAuthService::GetAuthCodeDeprecated0( |
183 const GetAuthCodeDeprecated0Callback& callback) { | 182 const GetAuthCodeDeprecated0Callback& callback) { |
184 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 183 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
185 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; | 184 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; |
186 } | 185 } |
187 | 186 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 258 } |
260 | 259 |
261 notifier_->Notify( | 260 notifier_->Notify( |
262 !ArcSessionManager::IsOptInVerificationDisabled(), auth_code, | 261 !ArcSessionManager::IsOptInVerificationDisabled(), auth_code, |
263 GetAccountType(), | 262 GetAccountType(), |
264 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); | 263 policy_util::IsAccountManaged(ArcSessionManager::Get()->profile())); |
265 notifier_.reset(); | 264 notifier_.reset(); |
266 } | 265 } |
267 | 266 |
268 } // namespace arc | 267 } // namespace arc |
OLD | NEW |