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

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

Issue 2723073002: Extract kArcEnabled preference from ArcSessionManager part 2. (Closed)
Patch Set: address comments Created 3 years, 9 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
(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 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_);
55 VLOG(1) << "Start observing Google Play Store enabled preference. "
56 << "Initial value: " << is_play_store_enabled;
57 UpdateArcSessionManager();
58
59 if (is_play_store_enabled)
60 return;
61
62 // Google Play Store is initially disabled, here.
63
64 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) {
65 // All users that can disable Google Play Store by themselves will have
66 // the |kARcDataRemoveRequested| pref set, so we don't need to eagerly
67 // remove the data for that case.
68 // For managed users, the preference can change when the Profile object is
69 // not alive, so we still need to check it here in case it was disabled to
70 // ensure that the data is deleted in case it was disabled between
71 // launches.
72 VLOG(1) << "Google Play Store is initially disabled for managed "
73 << "profile. Removing data.";
74 arc_session_manager_->RemoveArcData();
75 }
76
77 // ArcAuthNotification may need to be shown.
78 PrefServiceSyncableFromProfile(profile_)->AddObserver(this);
79 OnIsSyncingChanged();
80 }
81
82 void ArcPlayStoreEnabledPreferenceHandler::OnPreferenceChanged() {
83 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
84
85 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_);
86 if (!IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) {
87 // Update UMA only for non-Managed cases.
88 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN
89 : OptInActionType::OPTED_OUT);
90
91 if (!is_play_store_enabled) {
92 // Remove the pinned Play Store icon launcher in Shelf.
93 // This is only for non-Managed cases. In managed cases, it is expected
94 // to be "disabled" rather than "removed", so keep it here.
95 auto* shelf_delegate = ash::WmShell::HasInstance()
96 ? ash::WmShell::Get()->shelf_delegate()
97 : nullptr;
98 if (shelf_delegate)
99 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId);
100 }
101 }
102
103 // Hide auth notification if it was opened before and arc.enabled pref was
104 // explicitly set to true or false.
105 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled))
106 ArcAuthNotification::Hide();
107
108 UpdateArcSessionManager();
109
110 // Due to life time management, OnArcPlayStoreEnabledChanged() is notified
111 // via ArcSessionManager, so that external services can subscribe at almost
112 // any time.
113 arc_session_manager_->NotifyArcPlayStoreEnabledChanged(is_play_store_enabled);
114 }
115
116 void ArcPlayStoreEnabledPreferenceHandler::UpdateArcSessionManager() {
117 auto* support_host = arc_session_manager_->support_host();
118 if (support_host) {
119 support_host->SetArcManaged(
120 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_));
121 }
122
123 if (IsArcPlayStoreEnabledForProfile(profile_))
124 arc_session_manager_->RequestEnable();
125 else
126 arc_session_manager_->RequestDisable();
127 }
128
129 void ArcPlayStoreEnabledPreferenceHandler::OnIsSyncingChanged() {
130 sync_preferences::PrefServiceSyncable* const pref_service_syncable =
131 PrefServiceSyncableFromProfile(profile_);
132 if (!pref_service_syncable->IsSyncing())
133 return;
134 pref_service_syncable->RemoveObserver(this);
135
136 // TODO(hidehiko): Extract kEnableArcOOBEOptIn check as a utility method.
137 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
138 chromeos::switches::kEnableArcOOBEOptIn) &&
139 profile_->IsNewProfile() &&
140 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) {
141 ArcAuthNotification::Show(profile_);
142 }
143 }
144
145 } // namespace arc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698