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

Side by Side Diff: chrome/browser/chromeos/arc/arc_session_manager.h

Issue 2507073002: Split ArcSessionManager from ArcAuthService. (Closed)
Patch Set: Fix rebase mistake Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/observer_list.h" 14 #include "base/observer_list.h"
15 #include "base/timer/timer.h" 15 #include "base/timer/timer.h"
16 #include "chrome/browser/chromeos/arc/arc_support_host.h" 16 #include "chrome/browser/chromeos/arc/arc_support_host.h"
17 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observe r.h" 17 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observe r.h"
18 #include "chrome/browser/chromeos/policy/android_management_client.h" 18 #include "chrome/browser/chromeos/policy/android_management_client.h"
19 #include "components/arc/arc_bridge_service.h" 19 #include "components/arc/arc_bridge_service.h"
20 #include "components/arc/arc_service.h" 20 #include "components/arc/arc_service.h"
21 #include "components/arc/common/auth.mojom.h"
22 #include "components/arc/instance_holder.h"
23 #include "components/prefs/pref_change_registrar.h" 21 #include "components/prefs/pref_change_registrar.h"
24 #include "components/sync_preferences/pref_service_syncable_observer.h" 22 #include "components/sync_preferences/pref_service_syncable_observer.h"
25 #include "components/sync_preferences/synced_pref_observer.h" 23 #include "components/sync_preferences/synced_pref_observer.h"
26 #include "mojo/public/cpp/bindings/binding.h" 24 #include "mojo/public/cpp/bindings/binding.h"
27 25
28 class ArcAppLauncher; 26 class ArcAppLauncher;
29 class Profile; 27 class Profile;
30 28
31 namespace ash { 29 namespace ash {
32 class ShelfDelegate; 30 class ShelfDelegate;
33 } 31 }
34 32
35 namespace user_prefs { 33 namespace user_prefs {
36 class PrefRegistrySyncable; 34 class PrefRegistrySyncable;
37 } 35 }
38 36
39 namespace arc { 37 namespace arc {
40 38
41 class ArcAndroidManagementChecker; 39 class ArcAndroidManagementChecker;
42 class ArcAuthCodeFetcher; 40 class ArcAuthCodeFetcher;
43 class ArcAuthContext; 41 class ArcAuthContext;
44 class ArcOptInPreferenceHandler; 42 class ArcOptInPreferenceHandler;
45 class ArcRobotAuth; 43 class ArcRobotAuth;
46 enum class ProvisioningResult : int; 44 enum class ProvisioningResult : int;
47 45
48 // This class proxies the request from the client to fetch an auth code from 46 // This class proxies the request from the client to fetch an auth code from
49 // LSO. It lives on the UI thread. 47 // LSO. It lives on the UI thread.
50 class ArcAuthService : public ArcService, 48 class ArcSessionManager : public ArcService,
51 public mojom::AuthHost, 49 public ArcBridgeService::Observer,
52 public ArcBridgeService::Observer, 50 public ArcSupportHost::Observer,
53 public InstanceHolder<mojom::AuthInstance>::Observer, 51 public ArcOptInPreferenceHandlerObserver,
54 public ArcSupportHost::Observer, 52 public sync_preferences::PrefServiceSyncableObserver,
55 public ArcOptInPreferenceHandlerObserver, 53 public sync_preferences::SyncedPrefObserver {
56 public sync_preferences::PrefServiceSyncableObserver,
57 public sync_preferences::SyncedPrefObserver {
58 public: 54 public:
59 // Represents each State of ARC session. 55 // Represents each State of ARC session.
60 // NOT_INITIALIZED: represents the state that the Profile is not yet ready 56 // NOT_INITIALIZED: represents the state that the Profile is not yet ready
61 // so that this service is not yet initialized, or Chrome is being shut 57 // so that this service is not yet initialized, or Chrome is being shut
62 // down so that this is destroyed. 58 // down so that this is destroyed.
63 // STOPPED: ARC session is not running, or being terminated. 59 // STOPPED: ARC session is not running, or being terminated.
64 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support 60 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support
65 // Chrome app. 61 // Chrome app.
66 // CHECKING_ANDROID_MANAGEMENT: Checking Android management status. Note that 62 // CHECKING_ANDROID_MANAGEMENT: Checking Android management status. Note that
67 // the status is checked for each ARC session starting, but this is the 63 // the status is checked for each ARC session starting, but this is the
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Called to notify that ARC bridge is shut down. 107 // Called to notify that ARC bridge is shut down.
112 virtual void OnShutdownBridge() {} 108 virtual void OnShutdownBridge() {}
113 109
114 // Called to notify that ARC enabled state has been updated. 110 // Called to notify that ARC enabled state has been updated.
115 virtual void OnOptInEnabled(bool enabled) {} 111 virtual void OnOptInEnabled(bool enabled) {}
116 112
117 // Called to notify that ARC has been initialized successfully. 113 // Called to notify that ARC has been initialized successfully.
118 virtual void OnInitialStart() {} 114 virtual void OnInitialStart() {}
119 }; 115 };
120 116
121 explicit ArcAuthService(ArcBridgeService* bridge_service); 117 explicit ArcSessionManager(ArcBridgeService* bridge_service);
122 ~ArcAuthService() override; 118 ~ArcSessionManager() override;
123 119
124 static ArcAuthService* Get(); 120 static ArcSessionManager* Get();
125 121
126 // It is called from chrome/browser/prefs/browser_prefs.cc. 122 // It is called from chrome/browser/prefs/browser_prefs.cc.
127 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 123 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
128 124
129 static void DisableUIForTesting(); 125 static void DisableUIForTesting();
130 static void SetShelfDelegateForTesting(ash::ShelfDelegate* shelf_delegate); 126 static void SetShelfDelegateForTesting(ash::ShelfDelegate* shelf_delegate);
131 127
132 // Checks if OptIn verification was disabled by switch in command line. 128 // Checks if OptIn verification was disabled by switch in command line.
133 static bool IsOptInVerificationDisabled(); 129 static bool IsOptInVerificationDisabled();
134 130
135 static void EnableCheckAndroidManagementForTesting(); 131 static void EnableCheckAndroidManagementForTesting();
136 132
137 // Returns true if Arc is allowed to run for the given profile. 133 // Returns true if Arc is allowed to run for the given profile.
138 static bool IsAllowedForProfile(const Profile* profile); 134 static bool IsAllowedForProfile(const Profile* profile);
139 135
136 // Returns true if ARC should run under Kiosk mode.
137 static bool IsArcKioskMode();
138
140 // Returns true if Arc is allowed to run for the current session. 139 // Returns true if Arc is allowed to run for the current session.
141 bool IsAllowed() const; 140 bool IsAllowed() const;
142 141
143 void OnPrimaryUserProfilePrepared(Profile* profile); 142 void OnPrimaryUserProfilePrepared(Profile* profile);
144 void Shutdown(); 143 void Shutdown();
145 144
146 Profile* profile() { return profile_; } 145 Profile* profile() { return profile_; }
147 const Profile* profile() const { return profile_; } 146 const Profile* profile() const { return profile_; }
148 147
149 State state() const { return state_; } 148 State state() const { return state_; }
150 149
151 // Adds or removes observers. 150 // Adds or removes observers.
152 void AddObserver(Observer* observer); 151 void AddObserver(Observer* observer);
153 void RemoveObserver(Observer* observer); 152 void RemoveObserver(Observer* observer);
154 153
155 // ArcBridgeService::Observer: 154 // ArcBridgeService::Observer:
156 void OnBridgeStopped(ArcBridgeService::StopReason reason) override; 155 void OnBridgeStopped(ArcBridgeService::StopReason reason) override;
157 156
158 // InstanceHolder<mojom::AuthInstance>::Observer:
159 void OnInstanceReady() override;
160
161 // AuthHost:
162 void OnSignInComplete() override;
163 void OnSignInFailed(mojom::ArcSignInFailureReason reason) override;
164 void RequestAccountInfo() override;
165
166 // Deprecated methods:
167 // For security reason this code can be used only once and exists for specific
168 // period of time.
169 void GetAuthCodeDeprecated0(
170 const GetAuthCodeDeprecated0Callback& callback) override;
171 void GetAuthCodeDeprecated(
172 const GetAuthCodeDeprecatedCallback& callback) override;
173 void GetAuthCodeAndAccountTypeDeprecated(
174 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) override;
175 // Callback is called with a bool that indicates the management status of the
176 // user.
177 void GetIsAccountManagedDeprecated(
178 const GetIsAccountManagedDeprecatedCallback& callback) override;
179
180 // Called from Arc support platform app when user cancels signing. 157 // Called from Arc support platform app when user cancels signing.
181 void CancelAuthCode(); 158 void CancelAuthCode();
182 159
183 bool IsArcManaged() const; 160 bool IsArcManaged() const;
184 bool IsArcEnabled() const; 161 bool IsArcEnabled() const;
185 162
186 // This requires Arc to be allowed (|IsAllowed|)for current profile. 163 // This requires Arc to be allowed (|IsAllowed|)for current profile.
187 void EnableArc(); 164 void EnableArc();
188 void DisableArc(); 165 void DisableArc();
189 166
190 // Called from the Chrome OS metrics provider to record Arc.State 167 // Called from the Chrome OS metrics provider to record Arc.State
191 // periodically. 168 // periodically.
192 void RecordArcState(); 169 void RecordArcState();
193 170
194 // sync_preferences::PrefServiceSyncableObserver 171 // sync_preferences::PrefServiceSyncableObserver
195 void OnIsSyncingChanged() override; 172 void OnIsSyncingChanged() override;
196 173
197 // sync_preferences::SyncedPrefObserver 174 // sync_preferences::SyncedPrefObserver
198 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; 175 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override;
199 176
200 // ArcSupportHost::Observer: 177 // ArcSupportHost::Observer:
201 void OnWindowClosed() override; 178 void OnWindowClosed() override;
202 void OnTermsAgreed(bool is_metrics_enabled, 179 void OnTermsAgreed(bool is_metrics_enabled,
203 bool is_backup_and_restore_enabled, 180 bool is_backup_and_restore_enabled,
204 bool is_location_service_enabled) override; 181 bool is_location_service_enabled) override;
205 void OnAuthSucceeded(const std::string& auth_code) override;
206 void OnRetryClicked() override; 182 void OnRetryClicked() override;
207 void OnSendFeedbackClicked() override; 183 void OnSendFeedbackClicked() override;
208 184
209 // arc::ArcOptInPreferenceHandlerObserver: 185 // ArcOptInPreferenceHandlerObserver:
210 void OnMetricsModeChanged(bool enabled, bool managed) override; 186 void OnMetricsModeChanged(bool enabled, bool managed) override;
211 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; 187 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override;
212 void OnLocationServicesModeChanged(bool enabled, bool managed) override; 188 void OnLocationServicesModeChanged(bool enabled, bool managed) override;
213 189
214 // Stops ARC without changing ArcEnabled preference. 190 // Stops ARC without changing ArcEnabled preference.
215 void StopArc(); 191 void StopArc();
216 192
217 // StopArc(), then EnableArc(). Between them data clear may happens. 193 // StopArc(), then EnableArc(). Between them data clear may happens.
218 // This is a special method to support enterprise device lost case. 194 // This is a special method to support enterprise device lost case.
219 // This can be called only when ARC is running. 195 // This can be called only when ARC is running.
220 void StopAndEnableArc(); 196 void StopAndEnableArc();
221 197
222 // Removes the data if ARC is stopped. Otherwise, queue to remove the data 198 // Removes the data if ARC is stopped. Otherwise, queue to remove the data
223 // on ARC is stopped. 199 // on ARC is stopped.
224 void RemoveArcData(); 200 void RemoveArcData();
225 201
226 ArcSupportHost* support_host() { return support_host_.get(); } 202 ArcSupportHost* support_host() { return support_host_.get(); }
227 203
204 // TODO(hidehiko): Get rid of the getter by migration between ArcAuthContext
205 // and ArcAuthCodeFetcher.
206 ArcAuthContext* auth_context() { return context_.get(); }
207
228 void StartArc(); 208 void StartArc();
229 209
230 void OnProvisioningFinished(ProvisioningResult result); 210 void OnProvisioningFinished(ProvisioningResult result);
231 211
232 private: 212 private:
233 using AccountInfoCallback = base::Callback<void(mojom::AccountInfoPtr)>;
234 class AccountInfoNotifier;
235
236 // TODO(hidehiko): move UI methods/fields to ArcSupportHost. 213 // TODO(hidehiko): move UI methods/fields to ArcSupportHost.
237 void SetState(State state); 214 void SetState(State state);
238 void ShutdownBridge(); 215 void ShutdownBridge();
239 void OnOptInPreferenceChanged(); 216 void OnOptInPreferenceChanged();
240 void StartUI(); 217 void StartUI();
241 void OnAndroidManagementPassed(); 218 void OnAndroidManagementPassed();
242 void OnArcDataRemoved(bool success); 219 void OnArcDataRemoved(bool success);
243 void OnArcSignInTimeout(); 220 void OnArcSignInTimeout();
244 void FetchAuthCode(); 221 void FetchAuthCode();
245 void PrepareContextForAuthCodeRequest(); 222 void PrepareContextForAuthCodeRequest();
246 void RequestAccountInfoInternal(
247 std::unique_ptr<AccountInfoNotifier> account_info_notifier);
248 void OnAccountInfoReady(mojom::AccountInfoPtr account_info);
249
250 // Callback for Robot auth in Kiosk mode.
251 void OnRobotAuthCodeFetched(const std::string& auth_code);
252
253 // Callback for automatic auth code fetching when --arc-user-auth-endpoint
254 // flag is set.
255 void OnAuthCodeFetched(const std::string& auth_code);
256
257 // Common procedure across LSO auth code fetching, automatic auth code
258 // fetching, and Robot auth.
259 void OnAuthCodeObtained(const std::string& auth_code);
260 223
261 void StartArcAndroidManagementCheck(); 224 void StartArcAndroidManagementCheck();
262 225
263 // Called when the Android management check is done in opt-in flow or 226 // Called when the Android management check is done in opt-in flow or
264 // re-auth flow. 227 // re-auth flow.
265 void OnAndroidManagementChecked( 228 void OnAndroidManagementChecked(
266 policy::AndroidManagementClient::Result result); 229 policy::AndroidManagementClient::Result result);
267 230
268 // Called when the background Android management check is done. It is 231 // Called when the background Android management check is done. It is
269 // triggered when the second or later ARC boot timing. 232 // triggered when the second or later ARC boot timing.
270 void OnBackgroundAndroidManagementChecked( 233 void OnBackgroundAndroidManagementChecked(
271 policy::AndroidManagementClient::Result result); 234 policy::AndroidManagementClient::Result result);
272 235
273 // Called when HTTP context is prepared.
274 void OnContextPrepared(net::URLRequestContextGetter* request_context_getter);
275
276 // Unowned pointer. Keeps current profile. 236 // Unowned pointer. Keeps current profile.
277 Profile* profile_ = nullptr; 237 Profile* profile_ = nullptr;
278 238
279 // Registrar used to monitor ARC enabled state. 239 // Registrar used to monitor ARC enabled state.
280 PrefChangeRegistrar pref_change_registrar_; 240 PrefChangeRegistrar pref_change_registrar_;
281 241
282 mojo::Binding<AuthHost> binding_;
283 State state_ = State::NOT_INITIALIZED; 242 State state_ = State::NOT_INITIALIZED;
284 base::ObserverList<Observer> observer_list_; 243 base::ObserverList<Observer> observer_list_;
285 std::unique_ptr<ArcAppLauncher> playstore_launcher_; 244 std::unique_ptr<ArcAppLauncher> playstore_launcher_;
286 bool clear_required_ = false; 245 bool clear_required_ = false;
287 bool reenable_arc_ = false; 246 bool reenable_arc_ = false;
288 base::OneShotTimer arc_sign_in_timer_; 247 base::OneShotTimer arc_sign_in_timer_;
289 248
290 // Notifies the correct callback whenever the auth_code is ready.
291 std::unique_ptr<AccountInfoNotifier> account_info_notifier_;
292
293 // Temporarily keeps the ArcSupportHost instance. 249 // Temporarily keeps the ArcSupportHost instance.
294 // This should be moved to ArcSessionManager when the refactoring is 250 // This should be moved to ArcSessionManager when the refactoring is
295 // done. 251 // done.
296 std::unique_ptr<ArcSupportHost> support_host_; 252 std::unique_ptr<ArcSupportHost> support_host_;
297 // Handles preferences and metrics mode. 253 // Handles preferences and metrics mode.
298 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_; 254 std::unique_ptr<ArcOptInPreferenceHandler> preference_handler_;
299 255
300 std::unique_ptr<ArcAuthContext> context_; 256 std::unique_ptr<ArcAuthContext> context_;
301 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_;
302 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; 257 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_;
303 std::unique_ptr<ArcRobotAuth> arc_robot_auth_;
304 258
305 base::Time sign_in_time_; 259 base::Time sign_in_time_;
306 260
307 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; 261 base::WeakPtrFactory<ArcSessionManager> weak_ptr_factory_;
308 262
309 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); 263 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager);
310 }; 264 };
311 265
312 // Outputs the stringified |state| to |os|. This is only for logging purposes. 266 // Outputs the stringified |state| to |os|. This is only for logging purposes.
313 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); 267 std::ostream& operator<<(std::ostream& os,
268 const ArcSessionManager::State& state);
314 269
315 } // namespace arc 270 } // namespace arc
316 271
317 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 272 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_service_launcher.cc ('k') | chrome/browser/chromeos/arc/arc_session_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698