Chromium Code Reviews| 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_session_observer.h" | 18 #include "components/arc/arc_session_runner.h" |
| 19 #include "components/arc/arc_stop_reason.h" | |
| 19 #include "components/prefs/pref_change_registrar.h" | 20 #include "components/prefs/pref_change_registrar.h" |
| 20 #include "components/sync_preferences/pref_service_syncable_observer.h" | 21 #include "components/sync_preferences/pref_service_syncable_observer.h" |
| 21 | 22 |
| 22 class ArcAppLauncher; | 23 class ArcAppLauncher; |
| 23 class Profile; | 24 class Profile; |
| 24 | 25 |
| 25 namespace user_prefs { | 26 namespace user_prefs { |
| 26 class PrefRegistrySyncable; | 27 class PrefRegistrySyncable; |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace arc { | 30 namespace arc { |
| 30 | 31 |
| 31 class ArcAndroidManagementChecker; | 32 class ArcAndroidManagementChecker; |
| 32 class ArcAuthInfoFetcher; | 33 class ArcAuthInfoFetcher; |
| 33 class ArcAuthContext; | 34 class ArcAuthContext; |
| 34 class ArcSessionRunner; | |
| 35 class ArcTermsOfServiceNegotiator; | 35 class ArcTermsOfServiceNegotiator; |
| 36 enum class ProvisioningResult : int; | 36 enum class ProvisioningResult : int; |
| 37 | 37 |
| 38 // This class proxies the request from the client to fetch an auth code from | 38 // This class proxies the request from the client to fetch an auth code from |
| 39 // LSO. It lives on the UI thread. | 39 // LSO. It lives on the UI thread. |
| 40 class ArcSessionManager : public ArcSessionObserver, | 40 class ArcSessionManager : public ArcSessionRunner::Observer, |
| 41 public ArcSupportHost::Observer, | 41 public ArcSupportHost::Observer, |
| 42 public sync_preferences::PrefServiceSyncableObserver { | 42 public sync_preferences::PrefServiceSyncableObserver { |
| 43 public: | 43 public: |
| 44 // Represents each State of ARC session. | 44 // Represents each State of ARC session. |
| 45 // NOT_INITIALIZED: represents the state that the Profile is not yet ready | 45 // NOT_INITIALIZED: represents the state that the Profile is not yet ready |
| 46 // so that this service is not yet initialized, or Chrome is being shut | 46 // so that this service is not yet initialized, or Chrome is being shut |
| 47 // down so that this is destroyed. | 47 // down so that this is destroyed. |
| 48 // STOPPED: ARC session is not running, or being terminated. | 48 // STOPPED: ARC session is not running, or being terminated. |
| 49 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support | 49 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support |
| 50 // Chrome app. | 50 // Chrome app. |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 78 // relationship with |enable_requested_|. | 78 // relationship with |enable_requested_|. |
| 79 enum class State { | 79 enum class State { |
| 80 NOT_INITIALIZED, | 80 NOT_INITIALIZED, |
| 81 STOPPED, | 81 STOPPED, |
| 82 SHOWING_TERMS_OF_SERVICE, | 82 SHOWING_TERMS_OF_SERVICE, |
| 83 CHECKING_ANDROID_MANAGEMENT, | 83 CHECKING_ANDROID_MANAGEMENT, |
| 84 REMOVING_DATA_DIR, | 84 REMOVING_DATA_DIR, |
| 85 ACTIVE, | 85 ACTIVE, |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // Observer for those services outside of ARC which want to know ARC events. | |
| 88 class Observer { | 89 class Observer { |
| 89 public: | 90 public: |
| 90 virtual ~Observer() = default; | |
| 91 | |
| 92 // Called to notify that whether Google Play Store is enabled or not, which | 91 // Called to notify that whether Google Play Store is enabled or not, which |
| 93 // is represented by "arc.enabled" preference, is updated. | 92 // is represented by "arc.enabled" preference, is updated. |
| 94 virtual void OnArcPlayStoreEnabledChanged(bool enabled) {} | 93 virtual void OnArcPlayStoreEnabledChanged(bool enabled) {} |
| 95 | 94 |
| 96 // Called to notify that ARC has been initialized successfully. | 95 // Called to notify that ARC has been initialized successfully. |
| 97 virtual void OnArcInitialStart() {} | 96 virtual void OnArcInitialStart() {} |
| 98 | 97 |
| 98 // Called when ARC session is stopped, and is not being restarted | |
| 99 // automatically. | |
| 100 virtual void OnArcSessionStopped(ArcStopReason stop_reason) {} | |
| 101 | |
| 99 // Called to notify that Android data has been removed. Used in | 102 // Called to notify that Android data has been removed. Used in |
| 100 // browser_tests | 103 // browser_tests |
| 101 virtual void OnArcDataRemoved() {} | 104 virtual void OnArcDataRemoved() {} |
| 105 | |
| 106 protected: | |
| 107 // Do not directly create/destroy the instance via the interface. | |
| 108 Observer() = default; | |
| 109 ~Observer() = default; | |
|
Yusuke Sato
2017/03/01 15:51:01
qq: Thanks. Read the discussion. Is there any prac
hidehiko
2017/03/01 17:28:02
As for your example, no, it won't. However, it is
Yusuke Sato
2017/03/01 17:40:24
Sorry if my comment above was not clear enough, bu
hidehiko
2017/03/01 17:49:41
Sure, done.
Note that, removed ctor, too, consider
Luis Héctor Chávez
2017/03/01 18:26:52
I'll add this for posterity in the ARC++ style gui
hidehiko
2017/03/01 18:43:02
SG. Thanks!
| |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 explicit ArcSessionManager( | 112 explicit ArcSessionManager( |
| 105 std::unique_ptr<ArcSessionRunner> arc_session_runner); | 113 std::unique_ptr<ArcSessionRunner> arc_session_runner); |
| 106 ~ArcSessionManager() override; | 114 ~ArcSessionManager() override; |
| 107 | 115 |
| 108 static ArcSessionManager* Get(); | 116 static ArcSessionManager* Get(); |
| 109 | 117 |
| 110 // Exposed here for unit_tests validation. | 118 // Exposed here for unit_tests validation. |
| 111 static bool IsOobeOptInActive(); | 119 static bool IsOobeOptInActive(); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 138 // In addition, this triggers to show ArcAuthNotification, if necessary. | 146 // In addition, this triggers to show ArcAuthNotification, if necessary. |
| 139 // Note that this must be called after SetProfile(). | 147 // Note that this must be called after SetProfile(). |
| 140 // TODO(hidehiko): Extract preference related code into a class to split the | 148 // TODO(hidehiko): Extract preference related code into a class to split the |
| 141 // dependencty. | 149 // dependencty. |
| 142 void StartPreferenceHandler(); | 150 void StartPreferenceHandler(); |
| 143 | 151 |
| 144 // Adds or removes observers. | 152 // Adds or removes observers. |
| 145 void AddObserver(Observer* observer); | 153 void AddObserver(Observer* observer); |
| 146 void RemoveObserver(Observer* observer); | 154 void RemoveObserver(Observer* observer); |
| 147 | 155 |
| 148 // Adds or removes ArcSessionObservers. | |
| 149 // TODO(hidehiko): The observer should be migrated into | |
| 150 // ArcSessionManager::Observer. | |
| 151 void AddSessionObserver(ArcSessionObserver* observer); | |
| 152 void RemoveSessionObserver(ArcSessionObserver* observer); | |
| 153 | |
| 154 // Returns true if ARC instance is running/stopped, respectively. | 156 // Returns true if ARC instance is running/stopped, respectively. |
| 155 // See ArcSessionRunner::IsRunning()/IsStopped() for details. | 157 // See ArcSessionRunner::IsRunning()/IsStopped() for details. |
| 156 bool IsSessionRunning() const; | 158 bool IsSessionRunning() const; |
| 157 bool IsSessionStopped() const; | 159 bool IsSessionStopped() const; |
| 158 | 160 |
| 159 // Called from ARC support platform app when user cancels signing. | 161 // Called from ARC support platform app when user cancels signing. |
| 160 void CancelAuthCode(); | 162 void CancelAuthCode(); |
| 161 | 163 |
| 162 // Requests to enable ARC session. This starts ARC instance, or maybe starts | 164 // Requests to enable ARC session. This starts ARC instance, or maybe starts |
| 163 // Terms Of Service negotiation if they haven't been accepted yet. | 165 // Terms Of Service negotiation if they haven't been accepted yet. |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 // Called when the Android management check is done in opt-in flow or | 256 // Called when the Android management check is done in opt-in flow or |
| 255 // re-auth flow. | 257 // re-auth flow. |
| 256 void OnAndroidManagementChecked( | 258 void OnAndroidManagementChecked( |
| 257 policy::AndroidManagementClient::Result result); | 259 policy::AndroidManagementClient::Result result); |
| 258 | 260 |
| 259 // Called when the background Android management check is done. It is | 261 // Called when the background Android management check is done. It is |
| 260 // triggered when the second or later ARC boot timing. | 262 // triggered when the second or later ARC boot timing. |
| 261 void OnBackgroundAndroidManagementChecked( | 263 void OnBackgroundAndroidManagementChecked( |
| 262 policy::AndroidManagementClient::Result result); | 264 policy::AndroidManagementClient::Result result); |
| 263 | 265 |
| 264 // ArcSessionObserver: | 266 // ArcSessionRunner::Observer: |
| 265 void OnSessionReady() override; | 267 void OnSessionStopped(ArcStopReason reason, bool restarting) override; |
| 266 void OnSessionStopped(StopReason reason) override; | |
| 267 | 268 |
| 268 std::unique_ptr<ArcSessionRunner> arc_session_runner_; | 269 std::unique_ptr<ArcSessionRunner> arc_session_runner_; |
| 269 | 270 |
| 270 // Unowned pointer. Keeps current profile. | 271 // Unowned pointer. Keeps current profile. |
| 271 Profile* profile_ = nullptr; | 272 Profile* profile_ = nullptr; |
| 272 | 273 |
| 273 // Registrar used to monitor ARC enabled state. | 274 // Registrar used to monitor ARC enabled state. |
| 274 PrefChangeRegistrar pref_change_registrar_; | 275 PrefChangeRegistrar pref_change_registrar_; |
| 275 | 276 |
| 276 // Whether ArcSessionManager is requested to enable (starting to run ARC | 277 // Whether ArcSessionManager is requested to enable (starting to run ARC |
| 277 // instance) or not. | 278 // instance) or not. |
| 278 bool enable_requested_ = false; | 279 bool enable_requested_ = false; |
| 279 | 280 |
| 280 // Internal state machine. See also State enum class. | 281 // Internal state machine. See also State enum class. |
| 281 State state_ = State::NOT_INITIALIZED; | 282 State state_ = State::NOT_INITIALIZED; |
| 282 base::ObserverList<Observer> observer_list_; | 283 base::ObserverList<Observer> observer_list_; |
| 283 base::ObserverList<ArcSessionObserver> arc_session_observer_list_; | |
| 284 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 284 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 285 bool reenable_arc_ = false; | 285 bool reenable_arc_ = false; |
| 286 bool provisioning_reported_ = false; | 286 bool provisioning_reported_ = false; |
| 287 base::OneShotTimer arc_sign_in_timer_; | 287 base::OneShotTimer arc_sign_in_timer_; |
| 288 | 288 |
| 289 std::unique_ptr<ArcSupportHost> support_host_; | 289 std::unique_ptr<ArcSupportHost> support_host_; |
| 290 | 290 |
| 291 std::unique_ptr<ArcTermsOfServiceNegotiator> terms_of_service_negotiator_; | 291 std::unique_ptr<ArcTermsOfServiceNegotiator> terms_of_service_negotiator_; |
| 292 | 292 |
| 293 std::unique_ptr<ArcAuthContext> context_; | 293 std::unique_ptr<ArcAuthContext> context_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 305 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); | 305 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); |
| 306 }; | 306 }; |
| 307 | 307 |
| 308 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 308 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 309 std::ostream& operator<<(std::ostream& os, | 309 std::ostream& operator<<(std::ostream& os, |
| 310 const ArcSessionManager::State& state); | 310 const ArcSessionManager::State& state); |
| 311 | 311 |
| 312 } // namespace arc | 312 } // namespace arc |
| 313 | 313 |
| 314 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ | 314 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ |
| OLD | NEW |