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

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

Issue 2475073003: Refactor ArcSupportHost and ArcAuthService part 1. (Closed)
Patch Set: 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_AUTH_SERVICE_H_
6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_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_auth_code_fetcher_delegate.h" 16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher_delegate.h"
17 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h" 17 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h"
18 #include "chrome/browser/chromeos/arc/arc_support_host.h"
19 #include "chrome/browser/chromeos/arc/optin/arc_optin_preference_handler_observe r.h"
18 #include "chrome/browser/chromeos/policy/android_management_client.h" 20 #include "chrome/browser/chromeos/policy/android_management_client.h"
19 #include "components/arc/arc_bridge_service.h" 21 #include "components/arc/arc_bridge_service.h"
20 #include "components/arc/arc_service.h" 22 #include "components/arc/arc_service.h"
21 #include "components/arc/common/auth.mojom.h" 23 #include "components/arc/common/auth.mojom.h"
22 #include "components/arc/instance_holder.h" 24 #include "components/arc/instance_holder.h"
23 #include "components/prefs/pref_change_registrar.h" 25 #include "components/prefs/pref_change_registrar.h"
24 #include "components/sync_preferences/pref_service_syncable_observer.h" 26 #include "components/sync_preferences/pref_service_syncable_observer.h"
25 #include "components/sync_preferences/synced_pref_observer.h" 27 #include "components/sync_preferences/synced_pref_observer.h"
26 #include "mojo/public/cpp/bindings/binding.h" 28 #include "mojo/public/cpp/bindings/binding.h"
27 29
28 class ArcAppLauncher; 30 class ArcAppLauncher;
29 class Profile; 31 class Profile;
30 32
31 namespace ash { 33 namespace ash {
32 class ShelfDelegate; 34 class ShelfDelegate;
33 } 35 }
34 36
35 namespace user_prefs { 37 namespace user_prefs {
36 class PrefRegistrySyncable; 38 class PrefRegistrySyncable;
37 } 39 }
38 40
39 class ArcSupportHost;
40
41 namespace arc { 41 namespace arc {
42 42
43 class ArcAndroidManagementChecker; 43 class ArcAndroidManagementChecker;
44 class ArcAuthCodeFetcher; 44 class ArcAuthCodeFetcher;
45 class ArcAuthContext; 45 class ArcAuthContext;
46 class ArcOptInPreferenceHandler;
46 enum class ProvisioningResult : int; 47 enum class ProvisioningResult : int;
47 48
48 // This class proxies the request from the client to fetch an auth code from 49 // This class proxies the request from the client to fetch an auth code from
49 // LSO. It lives on the UI thread. 50 // LSO. It lives on the UI thread.
50 class ArcAuthService : public ArcService, 51 class ArcAuthService : public ArcService,
51 public mojom::AuthHost, 52 public mojom::AuthHost,
52 public ArcBridgeService::Observer, 53 public ArcBridgeService::Observer,
53 public InstanceHolder<mojom::AuthInstance>::Observer, 54 public InstanceHolder<mojom::AuthInstance>::Observer,
55 public ArcSupportHost::Observer,
56 public ArcOptInPreferenceHandlerObserver,
54 public ArcAuthContextDelegate, 57 public ArcAuthContextDelegate,
55 public ArcAuthCodeFetcherDelegate, 58 public ArcAuthCodeFetcherDelegate,
56 public sync_preferences::PrefServiceSyncableObserver, 59 public sync_preferences::PrefServiceSyncableObserver,
57 public sync_preferences::SyncedPrefObserver { 60 public sync_preferences::SyncedPrefObserver {
58 public: 61 public:
59 enum class State { 62 enum class State {
60 NOT_INITIALIZED, // Service is not initialized. 63 NOT_INITIALIZED, // Service is not initialized.
61 STOPPED, // ARC is not running. 64 STOPPED, // ARC is not running.
62 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. 65 FETCHING_CODE, // ARC may be running or not. Auth code is fetching.
63 ACTIVE, // ARC is running. 66 ACTIVE, // ARC is running.
64 }; 67 };
65 68
66 enum class UIPage {
67 NO_PAGE, // Hide everything.
68 TERMS, // Terms content page.
69 LSO_PROGRESS, // LSO loading progress page.
70 LSO, // LSO page to enter user's credentials.
71 START_PROGRESS, // Arc starting progress page.
72 ERROR, // Arc start error page.
73 ERROR_WITH_FEEDBACK, // Arc start error page, plus feedback button.
74 };
75
76 class Observer { 69 class Observer {
77 public: 70 public:
78 virtual ~Observer() = default; 71 virtual ~Observer() = default;
79 72
80 // Called whenever Opt-In state of the ARC has been changed. 73 // Called whenever Opt-In state of the ARC has been changed.
81 virtual void OnOptInChanged(State state) {} 74 virtual void OnOptInChanged(State state) {}
82 75
83 // Called to notify that ARC bridge is shut down. 76 // Called to notify that ARC bridge is shut down.
84 virtual void OnShutdownBridge() {} 77 virtual void OnShutdownBridge() {}
85 78
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; 165 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override;
173 166
174 // ArcAuthContextDelegate: 167 // ArcAuthContextDelegate:
175 void OnContextReady() override; 168 void OnContextReady() override;
176 void OnPrepareContextFailed() override; 169 void OnPrepareContextFailed() override;
177 170
178 // ArcAuthCodeFetcherDelegate: 171 // ArcAuthCodeFetcherDelegate:
179 void OnAuthCodeSuccess(const std::string& auth_code) override; 172 void OnAuthCodeSuccess(const std::string& auth_code) override;
180 void OnAuthCodeFailed() override; 173 void OnAuthCodeFailed() override;
181 174
175 // ArcSupportHost::Observer:
176 void OnWindowClosed() override;
177 void OnTermsAgreed(bool is_metrics_enabled,
178 bool is_backup_and_restore_enabled,
179 bool is_location_service_enabled) override;
180 void OnAuthSucceeded(const std::string& auth_code) override;
181 void OnSendFeedbackClicked() override;
182
183 // arc::ArcOptInPreferenceHandlerObserver:
184 void OnMetricsModeChanged(bool enabled, bool managed) override;
185 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override;
186 void OnLocationServicesModeChanged(bool enabled, bool managed) override;
187
182 // Stops ARC without changing ArcEnabled preference. 188 // Stops ARC without changing ArcEnabled preference.
183 void StopArc(); 189 void StopArc();
184 190
185 // StopArc(), then EnableArc(). Between them data clear may happens. 191 // StopArc(), then EnableArc(). Between them data clear may happens.
186 // This is a special method to support enterprise device lost case. 192 // This is a special method to support enterprise device lost case.
187 // This can be called only when ARC is running. 193 // This can be called only when ARC is running.
188 void StopAndEnableArc(); 194 void StopAndEnableArc();
189 195
190 // Removes the data if ARC is stopped. Otherwise, queue to remove the data 196 // Removes the data if ARC is stopped. Otherwise, queue to remove the data
191 // on ARC is stopped. 197 // on ARC is stopped.
192 void RemoveArcData(); 198 void RemoveArcData();
193 199
194 // Returns current page that has to be shown in OptIn UI. 200 // Returns current page that has to be shown in OptIn UI.
195 UIPage ui_page() const { return ui_page_; } 201 ArcSupportHost::UIPage ui_page() const { return ui_page_; }
196 202
197 // Returns current page status, relevant to the specific page. 203 // Returns current page status, relevant to the specific page.
198 const base::string16& ui_page_status() const { return ui_page_status_; } 204 const base::string16& ui_page_status() const { return ui_page_status_; }
199 205
200 ArcSupportHost* support_host() { return support_host_.get(); } 206 ArcSupportHost* support_host() { return support_host_.get(); }
201 207
202 private: 208 private:
203 void StartArc(); 209 void StartArc();
204 // TODO: move UI methods/fields to ArcSupportHost. 210 // TODO: move UI methods/fields to ArcSupportHost.
205 void ShowUI(UIPage page, const base::string16& status); 211 void ShowUI(ArcSupportHost::UIPage page, const base::string16& status);
206 void CloseUI(); 212 void CloseUI();
207 void SetUIPage(UIPage page, const base::string16& status); 213 void SetUIPage(ArcSupportHost::UIPage page, const base::string16& status);
208 void SetState(State state); 214 void SetState(State state);
209 void ShutdownBridge(); 215 void ShutdownBridge();
210 void ShutdownBridgeAndCloseUI(); 216 void ShutdownBridgeAndCloseUI();
211 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); 217 void ShutdownBridgeAndShowUI(ArcSupportHost::UIPage page,
218 const base::string16& status);
212 void OnOptInPreferenceChanged(); 219 void OnOptInPreferenceChanged();
213 void StartUI(); 220 void StartUI();
214 void StartAndroidManagementClient(); 221 void StartAndroidManagementClient();
215 void OnAndroidManagementPassed(); 222 void OnAndroidManagementPassed();
216 void OnArcDataRemoved(bool success); 223 void OnArcDataRemoved(bool success);
217 void OnArcSignInTimeout(); 224 void OnArcSignInTimeout();
218 bool IsAuthCodeRequest() const; 225 bool IsAuthCodeRequest() const;
219 void FetchAuthCode(); 226 void FetchAuthCode();
220 void PrepareContextForAuthCodeRequest(); 227 void PrepareContextForAuthCodeRequest();
221 228
(...skipping 14 matching lines...) Expand all
236 PrefChangeRegistrar pref_change_registrar_; 243 PrefChangeRegistrar pref_change_registrar_;
237 244
238 mojo::Binding<AuthHost> binding_; 245 mojo::Binding<AuthHost> binding_;
239 State state_ = State::NOT_INITIALIZED; 246 State state_ = State::NOT_INITIALIZED;
240 base::ObserverList<Observer> observer_list_; 247 base::ObserverList<Observer> observer_list_;
241 std::unique_ptr<ArcAppLauncher> playstore_launcher_; 248 std::unique_ptr<ArcAppLauncher> playstore_launcher_;
242 std::string auth_code_; 249 std::string auth_code_;
243 GetAuthCodeCallback auth_callback_; 250 GetAuthCodeCallback auth_callback_;
244 GetAuthCodeAndAccountTypeCallback auth_account_callback_; 251 GetAuthCodeAndAccountTypeCallback auth_account_callback_;
245 bool initial_opt_in_ = false; 252 bool initial_opt_in_ = false;
246 UIPage ui_page_ = UIPage::NO_PAGE; 253 ArcSupportHost::UIPage ui_page_ = ArcSupportHost::UIPage::NO_PAGE;
247 base::string16 ui_page_status_; 254 base::string16 ui_page_status_;
248 bool clear_required_ = false; 255 bool clear_required_ = false;
249 bool reenable_arc_ = false; 256 bool reenable_arc_ = false;
250 base::OneShotTimer arc_sign_in_timer_; 257 base::OneShotTimer arc_sign_in_timer_;
251 258
252 // Temporarily keeps the ArcSupportHost instance. 259 // Temporarily keeps the ArcSupportHost instance.
253 // This should be moved to ArcSessionManager when the refactoring is 260 // This should be moved to ArcSessionManager when the refactoring is
254 // done. 261 // done.
255 std::unique_ptr<ArcSupportHost> support_host_; 262 std::unique_ptr<ArcSupportHost> support_host_;
263 // Handles preferences and metrics mode.
264 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_;
256 265
257 std::unique_ptr<ArcAuthContext> context_; 266 std::unique_ptr<ArcAuthContext> context_;
258 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; 267 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_;
259 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; 268 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_;
260 269
261 base::Time sign_in_time_; 270 base::Time sign_in_time_;
262 271
263 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; 272 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_;
264 273
265 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); 274 DISALLOW_COPY_AND_ASSIGN(ArcAuthService);
266 }; 275 };
267 276
268 // Outputs the stringified |state| to |os|. This is only for logging purposes. 277 // Outputs the stringified |state| to |os|. This is only for logging purposes.
269 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); 278 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state);
270 279
271 } // namespace arc 280 } // namespace arc
272 281
273 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 282 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/arc_auth_service.cc » ('j') | chrome/browser/chromeos/arc/arc_auth_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698