| 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_SESSION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_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/policy/android_management_client.h" | 17 #include "chrome/browser/chromeos/policy/android_management_client.h" |
| 18 #include "components/arc/arc_service.h" | |
| 19 #include "components/arc/arc_session_observer.h" | 18 #include "components/arc/arc_session_observer.h" |
| 20 #include "components/prefs/pref_change_registrar.h" | 19 #include "components/prefs/pref_change_registrar.h" |
| 21 #include "components/sync_preferences/pref_service_syncable_observer.h" | 20 #include "components/sync_preferences/pref_service_syncable_observer.h" |
| 22 #include "components/sync_preferences/synced_pref_observer.h" | 21 #include "components/sync_preferences/synced_pref_observer.h" |
| 23 #include "mojo/public/cpp/bindings/binding.h" | |
| 24 | 22 |
| 25 class ArcAppLauncher; | 23 class ArcAppLauncher; |
| 26 class Profile; | 24 class Profile; |
| 27 | 25 |
| 28 namespace ash { | 26 namespace ash { |
| 29 class ShelfDelegate; | 27 class ShelfDelegate; |
| 30 } | 28 } |
| 31 | 29 |
| 32 namespace user_prefs { | 30 namespace user_prefs { |
| 33 class PrefRegistrySyncable; | 31 class PrefRegistrySyncable; |
| 34 } | 32 } |
| 35 | 33 |
| 36 namespace arc { | 34 namespace arc { |
| 37 | 35 |
| 38 class ArcAndroidManagementChecker; | 36 class ArcAndroidManagementChecker; |
| 39 class ArcAuthCodeFetcher; | 37 class ArcAuthCodeFetcher; |
| 40 class ArcAuthContext; | 38 class ArcAuthContext; |
| 41 class ArcBridgeService; | 39 class ArcSessionRunner; |
| 42 class ArcTermsOfServiceNegotiator; | 40 class ArcTermsOfServiceNegotiator; |
| 43 enum class ProvisioningResult : int; | 41 enum class ProvisioningResult : int; |
| 44 | 42 |
| 45 // This class proxies the request from the client to fetch an auth code from | 43 // This class proxies the request from the client to fetch an auth code from |
| 46 // LSO. It lives on the UI thread. | 44 // LSO. It lives on the UI thread. |
| 47 class ArcSessionManager : public ArcService, | 45 class ArcSessionManager : public ArcSessionObserver, |
| 48 public ArcSessionObserver, | |
| 49 public ArcSupportHost::Observer, | 46 public ArcSupportHost::Observer, |
| 50 public sync_preferences::PrefServiceSyncableObserver, | 47 public sync_preferences::PrefServiceSyncableObserver, |
| 51 public sync_preferences::SyncedPrefObserver { | 48 public sync_preferences::SyncedPrefObserver { |
| 52 public: | 49 public: |
| 53 // Represents each State of ARC session. | 50 // Represents each State of ARC session. |
| 54 // NOT_INITIALIZED: represents the state that the Profile is not yet ready | 51 // NOT_INITIALIZED: represents the state that the Profile is not yet ready |
| 55 // so that this service is not yet initialized, or Chrome is being shut | 52 // so that this service is not yet initialized, or Chrome is being shut |
| 56 // down so that this is destroyed. | 53 // down so that this is destroyed. |
| 57 // STOPPED: ARC session is not running, or being terminated. | 54 // STOPPED: ARC session is not running, or being terminated. |
| 58 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support | 55 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 SHOWING_TERMS_OF_SERVICE, | 93 SHOWING_TERMS_OF_SERVICE, |
| 97 CHECKING_ANDROID_MANAGEMENT, | 94 CHECKING_ANDROID_MANAGEMENT, |
| 98 REMOVING_DATA_DIR, | 95 REMOVING_DATA_DIR, |
| 99 ACTIVE, | 96 ACTIVE, |
| 100 }; | 97 }; |
| 101 | 98 |
| 102 class Observer { | 99 class Observer { |
| 103 public: | 100 public: |
| 104 virtual ~Observer() = default; | 101 virtual ~Observer() = default; |
| 105 | 102 |
| 106 // Called to notify that ARC bridge is shut down. | 103 // Called to notify that ARC session is shut down. |
| 104 // TODO(hidehiko): Rename the observer callback to OnArcSessionShutdown(). |
| 107 virtual void OnArcBridgeShutdown() {} | 105 virtual void OnArcBridgeShutdown() {} |
| 108 | 106 |
| 109 // Called to notify that ARC enabled state has been updated. | 107 // Called to notify that ARC enabled state has been updated. |
| 110 virtual void OnArcOptInChanged(bool enabled) {} | 108 virtual void OnArcOptInChanged(bool enabled) {} |
| 111 | 109 |
| 112 // Called to notify that ARC has been initialized successfully. | 110 // Called to notify that ARC has been initialized successfully. |
| 113 virtual void OnArcInitialStart() {} | 111 virtual void OnArcInitialStart() {} |
| 114 | 112 |
| 115 // Called to notify that Android data has been removed. Used in | 113 // Called to notify that Android data has been removed. Used in |
| 116 // browser_tests | 114 // browser_tests |
| 117 virtual void OnArcDataRemoved() {} | 115 virtual void OnArcDataRemoved() {} |
| 118 }; | 116 }; |
| 119 | 117 |
| 120 explicit ArcSessionManager(ArcBridgeService* bridge_service); | 118 explicit ArcSessionManager( |
| 119 std::unique_ptr<ArcSessionRunner> arc_session_runner); |
| 121 ~ArcSessionManager() override; | 120 ~ArcSessionManager() override; |
| 122 | 121 |
| 123 static ArcSessionManager* Get(); | 122 static ArcSessionManager* Get(); |
| 124 | 123 |
| 125 // It is called from chrome/browser/prefs/browser_prefs.cc. | 124 // It is called from chrome/browser/prefs/browser_prefs.cc. |
| 126 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 125 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 127 | 126 |
| 128 static void DisableUIForTesting(); | 127 static void DisableUIForTesting(); |
| 129 static void SetShelfDelegateForTesting(ash::ShelfDelegate* shelf_delegate); | 128 static void SetShelfDelegateForTesting(ash::ShelfDelegate* shelf_delegate); |
| 130 | 129 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 147 | 146 |
| 148 Profile* profile() { return profile_; } | 147 Profile* profile() { return profile_; } |
| 149 const Profile* profile() const { return profile_; } | 148 const Profile* profile() const { return profile_; } |
| 150 | 149 |
| 151 State state() const { return state_; } | 150 State state() const { return state_; } |
| 152 | 151 |
| 153 // Adds or removes observers. | 152 // Adds or removes observers. |
| 154 void AddObserver(Observer* observer); | 153 void AddObserver(Observer* observer); |
| 155 void RemoveObserver(Observer* observer); | 154 void RemoveObserver(Observer* observer); |
| 156 | 155 |
| 157 // ArcSessionObserver: | 156 // Adds or removes ArcSessionObservers. |
| 158 void OnSessionStopped(StopReason reason) override; | 157 // TODO(hidehiko): The observer should be migrated into |
| 158 // ArcSessionManager::Observer. |
| 159 void AddSessionObserver(ArcSessionObserver* observer); |
| 160 void RemoveSessionObserver(ArcSessionObserver* observer); |
| 161 |
| 162 // Returns true if ARC instance is running/stopped, respectively. |
| 163 // See ArcSessionRunner::IsRunning()/IsStopped() for details. |
| 164 bool IsSessionRunning() const; |
| 165 bool IsSessionStopped() const; |
| 159 | 166 |
| 160 // Called from Arc support platform app when user cancels signing. | 167 // Called from Arc support platform app when user cancels signing. |
| 161 void CancelAuthCode(); | 168 void CancelAuthCode(); |
| 162 | 169 |
| 163 bool IsArcManaged() const; | 170 bool IsArcManaged() const; |
| 164 bool IsArcEnabled() const; | 171 bool IsArcEnabled() const; |
| 165 | 172 |
| 166 // This requires Arc to be allowed (|IsAllowed|)for current profile. | 173 // This requires Arc to be allowed (|IsAllowed|)for current profile. |
| 167 void EnableArc(); | 174 void EnableArc(); |
| 168 void DisableArc(); | 175 void DisableArc(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 ArcSupportHost* support_host() { return support_host_.get(); } | 207 ArcSupportHost* support_host() { return support_host_.get(); } |
| 201 | 208 |
| 202 // TODO(hidehiko): Get rid of the getter by migration between ArcAuthContext | 209 // TODO(hidehiko): Get rid of the getter by migration between ArcAuthContext |
| 203 // and ArcAuthCodeFetcher. | 210 // and ArcAuthCodeFetcher. |
| 204 ArcAuthContext* auth_context() { return context_.get(); } | 211 ArcAuthContext* auth_context() { return context_.get(); } |
| 205 | 212 |
| 206 void StartArc(); | 213 void StartArc(); |
| 207 | 214 |
| 208 void OnProvisioningFinished(ProvisioningResult result); | 215 void OnProvisioningFinished(ProvisioningResult result); |
| 209 | 216 |
| 217 // Injectors for testing. |
| 218 void SetArcSessionRunnerForTesting( |
| 219 std::unique_ptr<ArcSessionRunner> arc_session_runner); |
| 210 void SetAttemptUserExitCallbackForTesting(const base::Closure& callback); | 220 void SetAttemptUserExitCallbackForTesting(const base::Closure& callback); |
| 211 | 221 |
| 212 private: | 222 private: |
| 213 // Negotiates the terms of service to user. | 223 // Negotiates the terms of service to user. |
| 214 void StartTermsOfServiceNegotiation(); | 224 void StartTermsOfServiceNegotiation(); |
| 215 void OnTermsOfServiceNegotiated(bool accepted); | 225 void OnTermsOfServiceNegotiated(bool accepted); |
| 216 | 226 |
| 217 void SetState(State state); | 227 void SetState(State state); |
| 218 void ShutdownBridge(); | 228 void ShutdownSession(); |
| 219 void OnOptInPreferenceChanged(); | 229 void OnOptInPreferenceChanged(); |
| 220 void OnAndroidManagementPassed(); | 230 void OnAndroidManagementPassed(); |
| 221 void OnArcDataRemoved(bool success); | 231 void OnArcDataRemoved(bool success); |
| 222 void OnArcSignInTimeout(); | 232 void OnArcSignInTimeout(); |
| 223 void FetchAuthCode(); | 233 void FetchAuthCode(); |
| 224 void PrepareContextForAuthCodeRequest(); | 234 void PrepareContextForAuthCodeRequest(); |
| 225 | 235 |
| 226 void StartArcAndroidManagementCheck(); | 236 void StartArcAndroidManagementCheck(); |
| 227 void MaybeReenableArc(); | 237 void MaybeReenableArc(); |
| 228 | 238 |
| 229 // Called when the Android management check is done in opt-in flow or | 239 // Called when the Android management check is done in opt-in flow or |
| 230 // re-auth flow. | 240 // re-auth flow. |
| 231 void OnAndroidManagementChecked( | 241 void OnAndroidManagementChecked( |
| 232 policy::AndroidManagementClient::Result result); | 242 policy::AndroidManagementClient::Result result); |
| 233 | 243 |
| 234 // Called when the background Android management check is done. It is | 244 // Called when the background Android management check is done. It is |
| 235 // triggered when the second or later ARC boot timing. | 245 // triggered when the second or later ARC boot timing. |
| 236 void OnBackgroundAndroidManagementChecked( | 246 void OnBackgroundAndroidManagementChecked( |
| 237 policy::AndroidManagementClient::Result result); | 247 policy::AndroidManagementClient::Result result); |
| 238 | 248 |
| 249 // ArcSessionObserver: |
| 250 void OnSessionReady() override; |
| 251 void OnSessionStopped(StopReason reason) override; |
| 252 |
| 253 std::unique_ptr<ArcSessionRunner> arc_session_runner_; |
| 254 |
| 239 // Unowned pointer. Keeps current profile. | 255 // Unowned pointer. Keeps current profile. |
| 240 Profile* profile_ = nullptr; | 256 Profile* profile_ = nullptr; |
| 241 | 257 |
| 242 // Registrar used to monitor ARC enabled state. | 258 // Registrar used to monitor ARC enabled state. |
| 243 PrefChangeRegistrar pref_change_registrar_; | 259 PrefChangeRegistrar pref_change_registrar_; |
| 244 | 260 |
| 245 State state_ = State::NOT_INITIALIZED; | 261 State state_ = State::NOT_INITIALIZED; |
| 246 base::ObserverList<Observer> observer_list_; | 262 base::ObserverList<Observer> observer_list_; |
| 263 base::ObserverList<ArcSessionObserver> arc_session_observer_list_; |
| 247 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 264 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 248 bool reenable_arc_ = false; | 265 bool reenable_arc_ = false; |
| 249 bool provisioning_reported_ = false; | 266 bool provisioning_reported_ = false; |
| 250 base::OneShotTimer arc_sign_in_timer_; | 267 base::OneShotTimer arc_sign_in_timer_; |
| 251 | 268 |
| 252 std::unique_ptr<ArcSupportHost> support_host_; | 269 std::unique_ptr<ArcSupportHost> support_host_; |
| 253 | 270 |
| 254 std::unique_ptr<ArcTermsOfServiceNegotiator> terms_of_service_negotiator_; | 271 std::unique_ptr<ArcTermsOfServiceNegotiator> terms_of_service_negotiator_; |
| 255 | 272 |
| 256 std::unique_ptr<ArcAuthContext> context_; | 273 std::unique_ptr<ArcAuthContext> context_; |
| 257 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; | 274 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; |
| 258 | 275 |
| 259 base::Time sign_in_time_; | 276 base::Time sign_in_time_; |
| 260 base::Closure attempt_user_exit_callback_; | 277 base::Closure attempt_user_exit_callback_; |
| 261 | 278 |
| 262 base::WeakPtrFactory<ArcSessionManager> weak_ptr_factory_; | 279 base::WeakPtrFactory<ArcSessionManager> weak_ptr_factory_; |
| 263 | 280 |
| 264 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); | 281 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); |
| 265 }; | 282 }; |
| 266 | 283 |
| 267 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 284 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 268 std::ostream& operator<<(std::ostream& os, | 285 std::ostream& operator<<(std::ostream& os, |
| 269 const ArcSessionManager::State& state); | 286 const ArcSessionManager::State& state); |
| 270 | 287 |
| 271 } // namespace arc | 288 } // namespace arc |
| 272 | 289 |
| 273 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ | 290 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ |
| OLD | NEW |