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

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

Issue 1973603002: arc: Make Play Store item persistance in shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 7 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
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 <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" 16 #include "chrome/browser/chromeos/arc/arc_auth_notification.h"
17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
18 #include "chrome/browser/chromeos/arc/arc_support_host.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/extensions/extension_util.h" 20 #include "chrome/browser/extensions/extension_util.h"
20 #include "chrome/browser/policy/profile_policy_connector.h" 21 #include "chrome/browser/policy/profile_policy_connector.h"
21 #include "chrome/browser/policy/profile_policy_connector_factory.h" 22 #include "chrome/browser/policy/profile_policy_connector_factory.h"
22 #include "chrome/browser/prefs/pref_service_syncable_util.h" 23 #include "chrome/browser/prefs/pref_service_syncable_util.h"
23 #include "chrome/browser/profiles/profile.h" 24 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 25 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
25 #include "chrome/browser/signin/signin_manager_factory.h" 26 #include "chrome/browser/signin/signin_manager_factory.h"
26 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" 27 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h"
28 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
27 #include "chrome/browser/ui/extensions/app_launch_params.h" 29 #include "chrome/browser/ui/extensions/app_launch_params.h"
28 #include "chrome/browser/ui/extensions/application_launch.h" 30 #include "chrome/browser/ui/extensions/application_launch.h"
29 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
30 #include "chrome/grit/generated_resources.h" 32 #include "chrome/grit/generated_resources.h"
31 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
32 #include "components/arc/arc_bridge_service.h" 34 #include "components/arc/arc_bridge_service.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 35 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/prefs/pref_service.h" 36 #include "components/prefs/pref_service.h"
35 #include "components/signin/core/browser/profile_oauth2_token_service.h" 37 #include "components/signin/core/browser/profile_oauth2_token_service.h"
36 #include "components/signin/core/browser/signin_manager_base.h" 38 #include "components/signin/core/browser/signin_manager_base.h"
(...skipping 10 matching lines...) Expand all
47 namespace arc { 49 namespace arc {
48 50
49 namespace { 51 namespace {
50 52
51 // Weak pointer. This class is owned by ArcServiceManager. 53 // Weak pointer. This class is owned by ArcServiceManager.
52 ArcAuthService* arc_auth_service = nullptr; 54 ArcAuthService* arc_auth_service = nullptr;
53 55
54 base::LazyInstance<base::ThreadChecker> thread_checker = 56 base::LazyInstance<base::ThreadChecker> thread_checker =
55 LAZY_INSTANCE_INITIALIZER; 57 LAZY_INSTANCE_INITIALIZER;
56 58
57 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa";
58 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei";
59 const char kArcSupportStorageId[] = "arc_support";
60
61 // Skip creating UI in unit tests 59 // Skip creating UI in unit tests
62 bool disable_ui_for_testing = false; 60 bool disable_ui_for_testing = false;
63 61
64 const char kStateStopped[] = "STOPPED"; 62 const char kStateStopped[] = "STOPPED";
65 const char kStateFetchingCode[] = "FETCHING_CODE"; 63 const char kStateFetchingCode[] = "FETCHING_CODE";
66 const char kStateActive[] = "ACTIVE"; 64 const char kStateActive[] = "ACTIVE";
67 } // namespace 65 } // namespace
68 66
69 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) 67 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service)
70 : ArcService(bridge_service), binding_(this) { 68 : ArcService(bridge_service), binding_(this) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 void ArcAuthService::DisableUIForTesting() { 103 void ArcAuthService::DisableUIForTesting() {
106 disable_ui_for_testing = true; 104 disable_ui_for_testing = true;
107 } 105 }
108 106
109 // static 107 // static
110 bool ArcAuthService::IsOptInVerificationDisabled() { 108 bool ArcAuthService::IsOptInVerificationDisabled() {
111 return base::CommandLine::ForCurrentProcess()->HasSwitch( 109 return base::CommandLine::ForCurrentProcess()->HasSwitch(
112 chromeos::switches::kDisableArcOptInVerification); 110 chromeos::switches::kDisableArcOptInVerification);
113 } 111 }
114 112
113 // static
114 bool ArcAuthService::IsAllowedForProfile(const Profile* profile) {
115 if (!arc::ArcBridgeService::GetEnabled(
116 base::CommandLine::ForCurrentProcess())) {
117 VLOG(1) << "Arc is not enabled.";
118 return false;
119 }
120
121 user_manager::User const* const user =
122 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
123 if (profile->IsLegacySupervised()) {
124 VLOG(1) << "Supervised users are not supported in ARC.";
125 return false;
126 }
127 if (!user->HasGaiaAccount()) {
128 VLOG(1) << "Users without GAIA accounts are not supported in ARC.";
129 return false;
130 }
131
132 if (user_manager::UserManager::Get()
133 ->IsCurrentUserCryptohomeDataEphemeral()) {
134 VLOG(2) << "Users with ephemeral data are not supported in Arc.";
135 return false;
136 }
137
138 return true;
139 }
140
115 void ArcAuthService::OnAuthInstanceReady() { 141 void ArcAuthService::OnAuthInstanceReady() {
116 arc_bridge_service()->auth_instance()->Init( 142 arc_bridge_service()->auth_instance()->Init(
117 binding_.CreateInterfacePtrAndBind()); 143 binding_.CreateInterfacePtrAndBind());
118 } 144 }
119 145
120 std::string ArcAuthService::GetAndResetAuthCode() { 146 std::string ArcAuthService::GetAndResetAuthCode() {
121 DCHECK(thread_checker.Get().CalledOnValidThread()); 147 DCHECK(thread_checker.Get().CalledOnValidThread());
122 std::string auth_code; 148 std::string auth_code;
123 auth_code_.swap(auth_code); 149 auth_code_.swap(auth_code);
124 return auth_code; 150 return auth_code;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 237 }
212 238
213 void ArcAuthService::SetState(State state) { 239 void ArcAuthService::SetState(State state) {
214 if (state_ == state) 240 if (state_ == state)
215 return; 241 return;
216 242
217 state_ = state; 243 state_ = state;
218 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_)); 244 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_));
219 } 245 }
220 246
247 bool ArcAuthService::IsAllowed() const {
248 DCHECK(thread_checker.Get().CalledOnValidThread());
249 return profile_ != nullptr;
250 }
251
221 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { 252 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
222 DCHECK(profile && profile != profile_); 253 DCHECK(profile && profile != profile_);
223 DCHECK(thread_checker.Get().CalledOnValidThread()); 254 DCHECK(thread_checker.Get().CalledOnValidThread());
224 255
225 Shutdown(); 256 Shutdown();
226 257
227 user_manager::User const* const user = 258 if (!IsAllowedForProfile(profile))
228 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
229 if (profile->IsLegacySupervised()) {
230 VLOG(1) << "Supervised users are not supported in ARC.";
231 return; 259 return;
232 }
233 if (!user->HasGaiaAccount()) {
234 VLOG(1) << "Users without GAIA accounts are not supported in ARC.";
235 return;
236 }
237
238 if (user_manager::UserManager::Get()
239 ->IsCurrentUserCryptohomeDataEphemeral()) {
240 VLOG(2) << "Users with ephemeral data are not supported in Arc.";
241 return;
242 }
243 260
244 profile_ = profile; 261 profile_ = profile;
245 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( 262 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
246 prefs::kArcEnabled, this); 263 prefs::kArcEnabled, this);
247 264
248 // Reuse storage used in ARC OptIn platform app. 265 // Reuse storage used in ARC OptIn platform app.
249 const std::string site_url = 266 const std::string site_url = base::StringPrintf(
250 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, 267 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId,
251 kArcSupportExtensionId, kArcSupportStorageId); 268 ArcSupportHost::kStorageId);
252 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 269 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
253 profile_, GURL(site_url)); 270 profile_, GURL(site_url));
254 CHECK(storage_partition_); 271 CHECK(storage_partition_);
255 272
256 // In case UI is disabled we assume that ARC is opted-in. 273 // In case UI is disabled we assume that ARC is opted-in.
257 if (!IsOptInVerificationDisabled()) { 274 if (!IsOptInVerificationDisabled()) {
258 pref_change_registrar_.Init(profile_->GetPrefs()); 275 pref_change_registrar_.Init(profile_->GetPrefs());
259 pref_change_registrar_.Add( 276 pref_change_registrar_.Add(
260 prefs::kArcEnabled, 277 prefs::kArcEnabled,
261 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 278 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 320 }
304 321
305 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { 322 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) {
306 if (disable_ui_for_testing || IsOptInVerificationDisabled()) 323 if (disable_ui_for_testing || IsOptInVerificationDisabled())
307 return; 324 return;
308 325
309 SetUIPage(page, status); 326 SetUIPage(page, status);
310 const extensions::AppWindowRegistry* const app_window_registry = 327 const extensions::AppWindowRegistry* const app_window_registry =
311 extensions::AppWindowRegistry::Get(profile_); 328 extensions::AppWindowRegistry::Get(profile_);
312 DCHECK(app_window_registry); 329 DCHECK(app_window_registry);
313 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) 330 if (app_window_registry->GetCurrentAppWindowForApp(
331 ArcSupportHost::kHostAppId)) {
314 return; 332 return;
333 }
315 334
316 const extensions::Extension* extension = 335 const extensions::Extension* extension =
317 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( 336 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
318 kArcSupportExtensionId); 337 ArcSupportHost::kHostAppId);
319 CHECK(extension && 338 CHECK(extension && extensions::util::IsAppLaunchable(
320 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); 339 ArcSupportHost::kHostAppId, profile_));
321 340
322 OpenApplication(CreateAppLaunchParamsUserContainer( 341 OpenApplication(CreateAppLaunchParamsUserContainer(
323 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); 342 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
324 } 343 }
325 344
326 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { 345 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) {
327 DCHECK(thread_checker.Get().CalledOnValidThread()); 346 DCHECK(thread_checker.Get().CalledOnValidThread());
328 347
329 DCHECK(!initial_opt_in_); 348 DCHECK(!initial_opt_in_);
330 context_prepared_ = true; 349 context_prepared_ = true;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (state_ != State::FETCHING_CODE) 502 if (state_ != State::FETCHING_CODE)
484 return; 503 return;
485 504
486 // Update UMA with user cancel only if error is not currently shown. 505 // Update UMA with user cancel only if error is not currently shown.
487 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) 506 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE)
488 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 507 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
489 508
490 DisableArc(); 509 DisableArc();
491 } 510 }
492 511
512 bool ArcAuthService::IsArcEnabled() {
513 DCHECK(thread_checker.Get().CalledOnValidThread());
514 DCHECK(profile_);
515 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
516 }
517
493 void ArcAuthService::EnableArc() { 518 void ArcAuthService::EnableArc() {
494 DCHECK(thread_checker.Get().CalledOnValidThread()); 519 DCHECK(thread_checker.Get().CalledOnValidThread());
520 DCHECK(profile_);
495 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 521 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
496 } 522 }
497 523
498 void ArcAuthService::DisableArc() { 524 void ArcAuthService::DisableArc() {
499 DCHECK(thread_checker.Get().CalledOnValidThread()); 525 DCHECK(thread_checker.Get().CalledOnValidThread());
526 DCHECK(profile_);
500 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 527 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
501 } 528 }
502 529
503 void ArcAuthService::PrepareContext() { 530 void ArcAuthService::PrepareContext() {
504 DCHECK(thread_checker.Get().CalledOnValidThread()); 531 DCHECK(thread_checker.Get().CalledOnValidThread());
505 532
506 // Get auth token to continue. 533 // Get auth token to continue.
507 ProfileOAuth2TokenService* token_service = 534 ProfileOAuth2TokenService* token_service =
508 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 535 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
509 SigninManagerBase* signin_manager = 536 SigninManagerBase* signin_manager =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return os << kStateFetchingCode; 575 return os << kStateFetchingCode;
549 case ArcAuthService::State::ACTIVE: 576 case ArcAuthService::State::ACTIVE:
550 return os << kStateActive; 577 return os << kStateActive;
551 default: 578 default:
552 NOTREACHED(); 579 NOTREACHED();
553 return os; 580 return os;
554 } 581 }
555 } 582 }
556 583
557 } // namespace arc 584 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698