Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/arc/arc_play_store_enabled_preference_handler. h" | |
| 6 | |
| 7 #include "ash/common/shelf/shelf_delegate.h" | |
| 8 #include "ash/common/wm_shell.h" | |
| 9 #include "base/bind.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | |
| 13 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | |
| 14 #include "chrome/browser/chromeos/arc/arc_session_manager.h" | |
| 15 #include "chrome/browser/chromeos/arc/arc_support_host.h" | |
| 16 #include "chrome/browser/chromeos/arc/arc_util.h" | |
| 17 #include "chrome/browser/prefs/pref_service_syncable_util.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "chromeos/chromeos_switches.h" | |
| 21 #include "components/sync_preferences/pref_service_syncable.h" | |
| 22 #include "content/public/browser/browser_thread.h" | |
| 23 | |
| 24 namespace arc { | |
| 25 | |
| 26 ArcPlayStoreEnabledPreferenceHandler::ArcPlayStoreEnabledPreferenceHandler( | |
| 27 Profile* profile, | |
| 28 ArcSessionManager* arc_session_manager) | |
| 29 : profile_(profile), | |
| 30 arc_session_manager_(arc_session_manager), | |
| 31 weak_ptr_factory_(this) { | |
| 32 DCHECK(profile_); | |
| 33 DCHECK(arc_session_manager_); | |
| 34 } | |
| 35 | |
| 36 ArcPlayStoreEnabledPreferenceHandler::~ArcPlayStoreEnabledPreferenceHandler() { | |
| 37 ArcAuthNotification::Hide(); | |
| 38 sync_preferences::PrefServiceSyncable* pref_service_syncable = | |
| 39 PrefServiceSyncableFromProfile(profile_); | |
| 40 pref_service_syncable->RemoveObserver(this); | |
| 41 pref_change_registrar_.RemoveAll(); | |
| 42 } | |
| 43 | |
| 44 void ArcPlayStoreEnabledPreferenceHandler::Start() { | |
| 45 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 46 | |
| 47 // Start observing Google Play Store enabled preference. | |
| 48 pref_change_registrar_.Init(profile_->GetPrefs()); | |
| 49 pref_change_registrar_.Add( | |
| 50 prefs::kArcEnabled, | |
| 51 base::Bind(&ArcPlayStoreEnabledPreferenceHandler::OnPreferenceChanged, | |
| 52 weak_ptr_factory_.GetWeakPtr())); | |
| 53 | |
| 54 // Set initial managed state to ArcSupportHost to update the message. | |
| 55 auto* support_host = arc_session_manager_->support_host(); | |
| 56 if (support_host) { | |
| 57 support_host->SetArcManaged( | |
| 58 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)); | |
| 59 } | |
| 60 | |
| 61 // Update the state based on the initial Google Play Store enabled value. | |
| 62 if (IsArcPlayStoreEnabledForProfile(profile_)) { | |
| 63 VLOG(1) << "Google Play Store is already enabled."; | |
| 64 arc_session_manager_->RequestEnable(); | |
| 65 } else { | |
| 66 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) { | |
| 67 // All users that can disable Google Play Store by themselves will have | |
| 68 // the |kARcDataRemoveRequested| pref set, so we don't need to eagerly | |
| 69 // remove the data for that case. | |
| 70 // For managed users, the preference can change when the Profile object is | |
| 71 // not alive, so we still need to check it here in case it was disabled to | |
| 72 // ensure that the data is deleted in case it was disabled between | |
| 73 // launches. | |
| 74 VLOG(1) << "Google Play Store is initially disabled for managed " | |
| 75 << "profile. Removing data."; | |
| 76 arc_session_manager_->RemoveArcData(); | |
| 77 } | |
| 78 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | |
| 79 OnIsSyncingChanged(); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void ArcPlayStoreEnabledPreferenceHandler::OnPreferenceChanged() { | |
| 84 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 85 | |
| 86 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_); | |
|
Luis Héctor Chávez
2017/03/02 00:09:17
Is it possible to merge the implementations of Sta
hidehiko
2017/03/02 02:21:57
Could you elaborate your intention a bit more?
IIU
Luis Héctor Chávez
2017/03/02 03:21:09
That's correct, but that's also the bulk of ArcPla
hidehiko
2017/03/02 16:37:08
Thank you for explanation. I believe I understand
| |
| 87 const bool is_play_store_managed = | |
| 88 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); | |
| 89 if (!is_play_store_managed) { | |
| 90 // Update UMA only for non-Managed cases. | |
| 91 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN | |
| 92 : OptInActionType::OPTED_OUT); | |
| 93 | |
| 94 if (!is_play_store_enabled) { | |
| 95 // Remove the pinned Play Store icon launcher in Shelf. | |
| 96 // This is only for non-Managed cases. In managed cases, it is expected | |
| 97 // to be "disabled" rather than "removed", so keep it here. | |
| 98 auto* shelf_delegate = ash::WmShell::HasInstance() | |
| 99 ? ash::WmShell::Get()->shelf_delegate() | |
| 100 : nullptr; | |
| 101 if (shelf_delegate) | |
| 102 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 auto* support_host = arc_session_manager_->support_host(); | |
| 107 if (support_host) | |
| 108 support_host->SetArcManaged(is_play_store_managed); | |
| 109 | |
| 110 // Hide auth notification if it was opened before and arc.enabled pref was | |
| 111 // explicitly set to true or false. | |
| 112 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) | |
| 113 ArcAuthNotification::Hide(); | |
| 114 | |
| 115 if (is_play_store_enabled) | |
| 116 arc_session_manager_->RequestEnable(); | |
| 117 else | |
| 118 arc_session_manager_->RequestDisable(); | |
| 119 | |
| 120 // Due to life time management, OnArcPlayStoreEnabledChanged() is notified | |
| 121 // via ArcSessionManager, so that external services can subscribe at almost | |
| 122 // any time. | |
| 123 arc_session_manager_->NotifyArcPlayStoreEnabledChanged(is_play_store_enabled); | |
| 124 } | |
| 125 | |
| 126 void ArcPlayStoreEnabledPreferenceHandler::OnIsSyncingChanged() { | |
| 127 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | |
| 128 PrefServiceSyncableFromProfile(profile_); | |
| 129 if (!pref_service_syncable->IsSyncing()) | |
| 130 return; | |
| 131 pref_service_syncable->RemoveObserver(this); | |
| 132 | |
| 133 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
|
Yusuke Sato
2017/03/01 18:09:26
qq: should we move this to c/a/arc_util.cc? (I'm n
hidehiko
2017/03/01 19:21:31
I think it's nice to have. Let's do it in another
Yusuke Sato
2017/03/01 19:50:19
sgtm, please add a TODO unless you already have a
hidehiko
2017/03/02 02:21:57
Done.
| |
| 134 chromeos::switches::kEnableArcOOBEOptIn) && | |
| 135 profile_->IsNewProfile() && | |
| 136 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | |
| 137 ArcAuthNotification::Show(profile_); | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 } // namespace arc | |
| OLD | NEW |