| OLD | NEW |
| 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_support_host.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher_delegate.h" | 17 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher_delegate.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h" | 18 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.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 ArcOptInPreferenceHandler; |
| 43 class ArcAndroidManagementChecker; | 44 class ArcAndroidManagementChecker; |
| 44 class ArcAuthCodeFetcher; | 45 class ArcAuthCodeFetcher; |
| 45 class ArcAuthContext; | 46 class ArcAuthContext; |
| 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 Loading... |
| 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 // ArcOptInPreferenceHandlerObserver: |
| 176 void OnMetricsModeChanged(bool enabled, bool managed) override; |
| 177 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; |
| 178 void OnLocationServicesModeChanged(bool enabled, bool managed) override; |
| 179 |
| 180 // ArcSupportHost::Observer: |
| 181 void OnWindowClosed() override; |
| 182 void OnTermsAgreed(bool is_metrics_enabled, |
| 183 bool is_backup_and_restore_enabled, |
| 184 bool is_location_service_enabled) override; |
| 185 void OnAuthSucceeded(const std::string& auth_code) override; |
| 186 void OnSendFeedbackClicked() 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. | |
| 195 UIPage ui_page() const { return ui_page_; } | |
| 196 | |
| 197 // Returns current page status, relevant to the specific page. | |
| 198 const base::string16& ui_page_status() const { return ui_page_status_; } | |
| 199 | |
| 200 ArcSupportHost* support_host() { return support_host_.get(); } | 200 ArcSupportHost* support_host() { return support_host_.get(); } |
| 201 | 201 |
| 202 private: | 202 private: |
| 203 void StartArc(); | 203 void StartArc(); |
| 204 // TODO: move UI methods/fields to ArcSupportHost. | 204 // TODO: move UI methods/fields to ArcSupportHost. |
| 205 void ShowUI(UIPage page, const base::string16& status); | |
| 206 void CloseUI(); | 205 void CloseUI(); |
| 207 void SetUIPage(UIPage page, const base::string16& status); | |
| 208 void SetState(State state); | 206 void SetState(State state); |
| 209 void ShutdownBridge(); | 207 void ShutdownBridge(); |
| 210 void ShutdownBridgeAndCloseUI(); | |
| 211 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); | |
| 212 void OnOptInPreferenceChanged(); | 208 void OnOptInPreferenceChanged(); |
| 213 void StartUI(); | 209 void StartUI(); |
| 214 void StartAndroidManagementClient(); | 210 void StartAndroidManagementClient(); |
| 215 void OnAndroidManagementPassed(); | 211 void OnAndroidManagementPassed(); |
| 216 void OnArcDataRemoved(bool success); | 212 void OnArcDataRemoved(bool success); |
| 217 void OnArcSignInTimeout(); | 213 void OnArcSignInTimeout(); |
| 218 bool IsAuthCodeRequest() const; | 214 bool IsAuthCodeRequest() const; |
| 219 void FetchAuthCode(); | 215 void FetchAuthCode(); |
| 220 void PrepareContextForAuthCodeRequest(); | 216 void PrepareContextForAuthCodeRequest(); |
| 221 | 217 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 236 PrefChangeRegistrar pref_change_registrar_; | 232 PrefChangeRegistrar pref_change_registrar_; |
| 237 | 233 |
| 238 mojo::Binding<AuthHost> binding_; | 234 mojo::Binding<AuthHost> binding_; |
| 239 State state_ = State::NOT_INITIALIZED; | 235 State state_ = State::NOT_INITIALIZED; |
| 240 base::ObserverList<Observer> observer_list_; | 236 base::ObserverList<Observer> observer_list_; |
| 241 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 237 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 242 std::string auth_code_; | 238 std::string auth_code_; |
| 243 GetAuthCodeCallback auth_callback_; | 239 GetAuthCodeCallback auth_callback_; |
| 244 GetAuthCodeAndAccountTypeCallback auth_account_callback_; | 240 GetAuthCodeAndAccountTypeCallback auth_account_callback_; |
| 245 bool initial_opt_in_ = false; | 241 bool initial_opt_in_ = false; |
| 246 UIPage ui_page_ = UIPage::NO_PAGE; | |
| 247 base::string16 ui_page_status_; | |
| 248 bool clear_required_ = false; | 242 bool clear_required_ = false; |
| 249 bool reenable_arc_ = false; | 243 bool reenable_arc_ = false; |
| 250 base::OneShotTimer arc_sign_in_timer_; | 244 base::OneShotTimer arc_sign_in_timer_; |
| 251 | 245 |
| 252 // Temporarily keeps the ArcSupportHost instance. | 246 // Temporarily keeps the ArcSupportHost instance. |
| 253 // This should be moved to ArcSessionManager when the refactoring is | 247 // This should be moved to ArcSessionManager when the refactoring is |
| 254 // done. | 248 // done. |
| 255 std::unique_ptr<ArcSupportHost> support_host_; | 249 std::unique_ptr<ArcSupportHost> support_host_; |
| 256 | 250 |
| 251 // Handles preferences and metrics mode. |
| 252 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_; |
| 253 |
| 257 std::unique_ptr<ArcAuthContext> context_; | 254 std::unique_ptr<ArcAuthContext> context_; |
| 258 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; | 255 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; |
| 259 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; | 256 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; |
| 260 | 257 |
| 261 base::Time sign_in_time_; | 258 base::Time sign_in_time_; |
| 262 | 259 |
| 263 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; | 260 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; |
| 264 | 261 |
| 265 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 262 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 266 }; | 263 }; |
| 267 | 264 |
| 268 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 265 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 269 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); | 266 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); |
| 270 | 267 |
| 271 } // namespace arc | 268 } // namespace arc |
| 272 | 269 |
| 273 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 270 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |