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

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: nits 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 209 }
212 210
213 void ArcAuthService::SetState(State state) { 211 void ArcAuthService::SetState(State state) {
214 if (state_ == state) 212 if (state_ == state)
215 return; 213 return;
216 214
217 state_ = state; 215 state_ = state;
218 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_)); 216 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_));
219 } 217 }
220 218
219 bool ArcAuthService::IsAllowed() const {
220 DCHECK(thread_checker.Get().CalledOnValidThread());
221 return profile_ != nullptr;
222 }
223
221 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { 224 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
222 DCHECK(profile && profile != profile_); 225 DCHECK(profile && profile != profile_);
223 DCHECK(thread_checker.Get().CalledOnValidThread()); 226 DCHECK(thread_checker.Get().CalledOnValidThread());
224 227
225 Shutdown(); 228 Shutdown();
226 229
227 user_manager::User const* const user = 230 user_manager::User const* const user =
228 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 231 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
229 if (profile->IsLegacySupervised()) { 232 if (profile->IsLegacySupervised()) {
230 VLOG(1) << "Supervised users are not supported in ARC."; 233 VLOG(1) << "Supervised users are not supported in ARC.";
231 return; 234 return;
232 } 235 }
233 if (!user->HasGaiaAccount()) { 236 if (!user->HasGaiaAccount()) {
234 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; 237 VLOG(1) << "Users without GAIA accounts are not supported in ARC.";
235 return; 238 return;
236 } 239 }
237 240
238 if (user_manager::UserManager::Get() 241 if (user_manager::UserManager::Get()
239 ->IsCurrentUserCryptohomeDataEphemeral()) { 242 ->IsCurrentUserCryptohomeDataEphemeral()) {
240 VLOG(2) << "Users with ephemeral data are not supported in Arc."; 243 VLOG(2) << "Users with ephemeral data are not supported in Arc.";
241 return; 244 return;
242 } 245 }
243 246
244 profile_ = profile; 247 profile_ = profile;
245 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( 248 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver(
246 prefs::kArcEnabled, this); 249 prefs::kArcEnabled, this);
247 250
248 // Reuse storage used in ARC OptIn platform app. 251 // Reuse storage used in ARC OptIn platform app.
249 const std::string site_url = 252 const std::string site_url = base::StringPrintf(
250 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, 253 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId,
251 kArcSupportExtensionId, kArcSupportStorageId); 254 ArcSupportHost::kStorageId);
252 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( 255 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite(
253 profile_, GURL(site_url)); 256 profile_, GURL(site_url));
254 CHECK(storage_partition_); 257 CHECK(storage_partition_);
255 258
256 // In case UI is disabled we assume that ARC is opted-in. 259 // In case UI is disabled we assume that ARC is opted-in.
257 if (!IsOptInVerificationDisabled()) { 260 if (!IsOptInVerificationDisabled()) {
258 pref_change_registrar_.Init(profile_->GetPrefs()); 261 pref_change_registrar_.Init(profile_->GetPrefs());
259 pref_change_registrar_.Add( 262 pref_change_registrar_.Add(
260 prefs::kArcEnabled, 263 prefs::kArcEnabled,
261 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, 264 base::Bind(&ArcAuthService::OnOptInPreferenceChanged,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 306 }
304 307
305 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { 308 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) {
306 if (disable_ui_for_testing || IsOptInVerificationDisabled()) 309 if (disable_ui_for_testing || IsOptInVerificationDisabled())
307 return; 310 return;
308 311
309 SetUIPage(page, status); 312 SetUIPage(page, status);
310 const extensions::AppWindowRegistry* const app_window_registry = 313 const extensions::AppWindowRegistry* const app_window_registry =
311 extensions::AppWindowRegistry::Get(profile_); 314 extensions::AppWindowRegistry::Get(profile_);
312 DCHECK(app_window_registry); 315 DCHECK(app_window_registry);
313 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) 316 if (app_window_registry->GetCurrentAppWindowForApp(
317 ArcSupportHost::kHostAppId)) {
314 return; 318 return;
319 }
315 320
316 const extensions::Extension* extension = 321 const extensions::Extension* extension =
317 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( 322 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
318 kArcSupportExtensionId); 323 ArcSupportHost::kHostAppId);
319 CHECK(extension && 324 CHECK(extension && extensions::util::IsAppLaunchable(
320 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); 325 ArcSupportHost::kHostAppId, profile_));
321 326
322 OpenApplication(CreateAppLaunchParamsUserContainer( 327 OpenApplication(CreateAppLaunchParamsUserContainer(
323 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); 328 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL));
324 } 329 }
325 330
326 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { 331 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) {
327 DCHECK(thread_checker.Get().CalledOnValidThread()); 332 DCHECK(thread_checker.Get().CalledOnValidThread());
328 333
329 DCHECK(!initial_opt_in_); 334 DCHECK(!initial_opt_in_);
330 context_prepared_ = true; 335 context_prepared_ = true;
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 if (state_ != State::FETCHING_CODE) 488 if (state_ != State::FETCHING_CODE)
484 return; 489 return;
485 490
486 // Update UMA with user cancel only if error is not currently shown. 491 // Update UMA with user cancel only if error is not currently shown.
487 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) 492 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE)
488 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); 493 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL);
489 494
490 DisableArc(); 495 DisableArc();
491 } 496 }
492 497
498 bool ArcAuthService::IsArcEnabled() {
499 DCHECK(thread_checker.Get().CalledOnValidThread());
500 DCHECK(profile_);
501 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled);
502 }
503
493 void ArcAuthService::EnableArc() { 504 void ArcAuthService::EnableArc() {
494 DCHECK(thread_checker.Get().CalledOnValidThread()); 505 DCHECK(thread_checker.Get().CalledOnValidThread());
506 DCHECK(profile_);
495 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); 507 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true);
496 } 508 }
497 509
498 void ArcAuthService::DisableArc() { 510 void ArcAuthService::DisableArc() {
499 DCHECK(thread_checker.Get().CalledOnValidThread()); 511 DCHECK(thread_checker.Get().CalledOnValidThread());
512 DCHECK(profile_);
500 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); 513 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false);
501 } 514 }
502 515
503 void ArcAuthService::PrepareContext() { 516 void ArcAuthService::PrepareContext() {
504 DCHECK(thread_checker.Get().CalledOnValidThread()); 517 DCHECK(thread_checker.Get().CalledOnValidThread());
505 518
506 // Get auth token to continue. 519 // Get auth token to continue.
507 ProfileOAuth2TokenService* token_service = 520 ProfileOAuth2TokenService* token_service =
508 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); 521 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
509 SigninManagerBase* signin_manager = 522 SigninManagerBase* signin_manager =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return os << kStateFetchingCode; 561 return os << kStateFetchingCode;
549 case ArcAuthService::State::ACTIVE: 562 case ArcAuthService::State::ACTIVE:
550 return os << kStateActive; 563 return os << kStateActive;
551 default: 564 default:
552 NOTREACHED(); 565 NOTREACHED();
553 return os; 566 return os;
554 } 567 }
555 } 568 }
556 569
557 } // namespace arc 570 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698