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

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

Powered by Google App Engine
This is Rietveld 408576698