| 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_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 to notify that ARC bridge is shut down. | 73 // Called to notify that ARC bridge is shut down. |
| 81 virtual void OnShutdownBridge() {} | 74 virtual void OnShutdownBridge() {} |
| 82 | 75 |
| 83 // Called to notify that ARC enabled state has been updated. | 76 // Called to notify that ARC enabled state has been updated. |
| 84 virtual void OnOptInEnabled(bool enabled) {} | 77 virtual void OnOptInEnabled(bool enabled) {} |
| 85 | 78 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; | 170 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; |
| 178 | 171 |
| 179 // ArcAuthContextDelegate: | 172 // ArcAuthContextDelegate: |
| 180 void OnContextReady() override; | 173 void OnContextReady() override; |
| 181 void OnPrepareContextFailed() override; | 174 void OnPrepareContextFailed() override; |
| 182 | 175 |
| 183 // ArcAuthCodeFetcherDelegate: | 176 // ArcAuthCodeFetcherDelegate: |
| 184 void OnAuthCodeSuccess(const std::string& auth_code) override; | 177 void OnAuthCodeSuccess(const std::string& auth_code) override; |
| 185 void OnAuthCodeFailed() override; | 178 void OnAuthCodeFailed() override; |
| 186 | 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 |
| 188 // arc::ArcOptInPreferenceHandlerObserver: |
| 189 void OnMetricsModeChanged(bool enabled, bool managed) override; |
| 190 void OnBackupAndRestoreModeChanged(bool enabled, bool managed) override; |
| 191 void OnLocationServicesModeChanged(bool enabled, bool managed) override; |
| 192 |
| 187 // Stops ARC without changing ArcEnabled preference. | 193 // Stops ARC without changing ArcEnabled preference. |
| 188 void StopArc(); | 194 void StopArc(); |
| 189 | 195 |
| 190 // StopArc(), then EnableArc(). Between them data clear may happens. | 196 // StopArc(), then EnableArc(). Between them data clear may happens. |
| 191 // This is a special method to support enterprise device lost case. | 197 // This is a special method to support enterprise device lost case. |
| 192 // This can be called only when ARC is running. | 198 // This can be called only when ARC is running. |
| 193 void StopAndEnableArc(); | 199 void StopAndEnableArc(); |
| 194 | 200 |
| 195 // Removes the data if ARC is stopped. Otherwise, queue to remove the data | 201 // Removes the data if ARC is stopped. Otherwise, queue to remove the data |
| 196 // on ARC is stopped. | 202 // on ARC is stopped. |
| 197 void RemoveArcData(); | 203 void RemoveArcData(); |
| 198 | 204 |
| 199 // Returns current page that has to be shown in OptIn UI. | 205 // Returns current page that has to be shown in OptIn UI. |
| 200 UIPage ui_page() const { return ui_page_; } | 206 ArcSupportHost::UIPage ui_page() const { return ui_page_; } |
| 201 | 207 |
| 202 // Returns current page status, relevant to the specific page. | 208 // Returns current page status, relevant to the specific page. |
| 203 const base::string16& ui_page_status() const { return ui_page_status_; } | 209 const base::string16& ui_page_status() const { return ui_page_status_; } |
| 204 | 210 |
| 205 ArcSupportHost* support_host() { return support_host_.get(); } | 211 ArcSupportHost* support_host() { return support_host_.get(); } |
| 206 | 212 |
| 207 private: | 213 private: |
| 208 using AccountInfoCallback = base::Callback<void(mojom::AccountInfoPtr)>; | 214 using AccountInfoCallback = base::Callback<void(mojom::AccountInfoPtr)>; |
| 209 class AccountInfoNotifier; | 215 class AccountInfoNotifier; |
| 210 | 216 |
| 211 void StartArc(); | 217 void StartArc(); |
| 212 // TODO(hidehiko): move UI methods/fields to ArcSupportHost. | 218 // TODO(hidehiko): move UI methods/fields to ArcSupportHost. |
| 213 void ShowUI(UIPage page, const base::string16& status); | 219 void ShowUI(ArcSupportHost::UIPage page, const base::string16& status); |
| 214 void CloseUI(); | 220 void CloseUI(); |
| 215 void SetUIPage(UIPage page, const base::string16& status); | 221 void SetUIPage(ArcSupportHost::UIPage page, const base::string16& status); |
| 216 void SetState(State state); | 222 void SetState(State state); |
| 217 void ShutdownBridge(); | 223 void ShutdownBridge(); |
| 218 void ShutdownBridgeAndCloseUI(); | 224 void ShutdownBridgeAndCloseUI(); |
| 219 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); | 225 void ShutdownBridgeAndShowUI(ArcSupportHost::UIPage page, |
| 226 const base::string16& status); |
| 220 void OnOptInPreferenceChanged(); | 227 void OnOptInPreferenceChanged(); |
| 221 void StartUI(); | 228 void StartUI(); |
| 222 void StartAndroidManagementClient(); | 229 void StartAndroidManagementClient(); |
| 223 void OnAndroidManagementPassed(); | 230 void OnAndroidManagementPassed(); |
| 224 void OnArcDataRemoved(bool success); | 231 void OnArcDataRemoved(bool success); |
| 225 void OnArcSignInTimeout(); | 232 void OnArcSignInTimeout(); |
| 226 bool IsAuthCodeRequest() const; | 233 bool IsAuthCodeRequest() const; |
| 227 void FetchAuthCode(); | 234 void FetchAuthCode(); |
| 228 void PrepareContextForAuthCodeRequest(); | 235 void PrepareContextForAuthCodeRequest(); |
| 229 void RequestAccountInfoInternal( | 236 void RequestAccountInfoInternal( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 Profile* profile_ = nullptr; | 251 Profile* profile_ = nullptr; |
| 245 | 252 |
| 246 // Registrar used to monitor ARC enabled state. | 253 // Registrar used to monitor ARC enabled state. |
| 247 PrefChangeRegistrar pref_change_registrar_; | 254 PrefChangeRegistrar pref_change_registrar_; |
| 248 | 255 |
| 249 mojo::Binding<AuthHost> binding_; | 256 mojo::Binding<AuthHost> binding_; |
| 250 State state_ = State::NOT_INITIALIZED; | 257 State state_ = State::NOT_INITIALIZED; |
| 251 base::ObserverList<Observer> observer_list_; | 258 base::ObserverList<Observer> observer_list_; |
| 252 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 259 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 253 std::string auth_code_; | 260 std::string auth_code_; |
| 254 UIPage ui_page_ = UIPage::NO_PAGE; | 261 ArcSupportHost::UIPage ui_page_ = ArcSupportHost::UIPage::NO_PAGE; |
| 255 base::string16 ui_page_status_; | 262 base::string16 ui_page_status_; |
| 256 bool clear_required_ = false; | 263 bool clear_required_ = false; |
| 257 bool reenable_arc_ = false; | 264 bool reenable_arc_ = false; |
| 258 base::OneShotTimer arc_sign_in_timer_; | 265 base::OneShotTimer arc_sign_in_timer_; |
| 259 | 266 |
| 260 // Notifies the correct callback whenever the auth_code is ready. | 267 // Notifies the correct callback whenever the auth_code is ready. |
| 261 std::unique_ptr<AccountInfoNotifier> account_info_notifier_; | 268 std::unique_ptr<AccountInfoNotifier> account_info_notifier_; |
| 262 | 269 |
| 263 // Temporarily keeps the ArcSupportHost instance. | 270 // Temporarily keeps the ArcSupportHost instance. |
| 264 // This should be moved to ArcSessionManager when the refactoring is | 271 // This should be moved to ArcSessionManager when the refactoring is |
| 265 // done. | 272 // done. |
| 266 std::unique_ptr<ArcSupportHost> support_host_; | 273 std::unique_ptr<ArcSupportHost> support_host_; |
| 274 // Handles preferences and metrics mode. |
| 275 std::unique_ptr<arc::ArcOptInPreferenceHandler> preference_handler_; |
| 267 | 276 |
| 268 std::unique_ptr<ArcAuthContext> context_; | 277 std::unique_ptr<ArcAuthContext> context_; |
| 269 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; | 278 std::unique_ptr<ArcAuthCodeFetcher> auth_code_fetcher_; |
| 270 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; | 279 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; |
| 271 | 280 |
| 272 base::Time sign_in_time_; | 281 base::Time sign_in_time_; |
| 273 | 282 |
| 274 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; | 283 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; |
| 275 | 284 |
| 276 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 285 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 277 }; | 286 }; |
| 278 | 287 |
| 279 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 288 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 280 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); | 289 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); |
| 281 | 290 |
| 282 } // namespace arc | 291 } // namespace arc |
| 283 | 292 |
| 284 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 293 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |