| 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_runner.h" | 18 #include "components/arc/arc_session_runner.h" |
| 19 #include "components/arc/arc_stop_reason.h" | 19 #include "components/arc/arc_stop_reason.h" |
| 20 #include "components/prefs/pref_change_registrar.h" | |
| 21 #include "components/sync_preferences/pref_service_syncable_observer.h" | |
| 22 | 20 |
| 23 class ArcAppLauncher; | 21 class ArcAppLauncher; |
| 24 class Profile; | 22 class Profile; |
| 25 | 23 |
| 26 namespace user_prefs { | 24 namespace user_prefs { |
| 27 class PrefRegistrySyncable; | 25 class PrefRegistrySyncable; |
| 28 } | 26 } |
| 29 | 27 |
| 30 namespace arc { | 28 namespace arc { |
| 31 | 29 |
| 32 class ArcAndroidManagementChecker; | 30 class ArcAndroidManagementChecker; |
| 33 class ArcAuthInfoFetcher; | |
| 34 class ArcAuthContext; | 31 class ArcAuthContext; |
| 35 class ArcTermsOfServiceNegotiator; | 32 class ArcTermsOfServiceNegotiator; |
| 36 enum class ProvisioningResult : int; | 33 enum class ProvisioningResult : int; |
| 37 | 34 |
| 38 // This class proxies the request from the client to fetch an auth code from | 35 // This class proxies the request from the client to fetch an auth code from |
| 39 // LSO. It lives on the UI thread. | 36 // LSO. It lives on the UI thread. |
| 40 class ArcSessionManager : public ArcSessionRunner::Observer, | 37 class ArcSessionManager : public ArcSessionRunner::Observer, |
| 41 public ArcSupportHost::Observer, | 38 public ArcSupportHost::Observer { |
| 42 public sync_preferences::PrefServiceSyncableObserver { | |
| 43 public: | 39 public: |
| 44 // Represents each State of ARC session. | 40 // Represents each State of ARC session. |
| 45 // NOT_INITIALIZED: represents the state that the Profile is not yet ready | 41 // 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 | 42 // so that this service is not yet initialized, or Chrome is being shut |
| 47 // down so that this is destroyed. | 43 // down so that this is destroyed. |
| 48 // STOPPED: ARC session is not running, or being terminated. | 44 // STOPPED: ARC session is not running, or being terminated. |
| 49 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support | 45 // SHOWING_TERMS_OF_SERVICE: "Terms Of Service" page is shown on ARC support |
| 50 // Chrome app. | 46 // Chrome app. |
| 51 // CHECKING_ANDROID_MANAGEMENT: Checking Android management status. Note that | 47 // CHECKING_ANDROID_MANAGEMENT: Checking Android management status. Note that |
| 52 // the status is checked for each ARC session starting, but this is the | 48 // the status is checked for each ARC session starting, but this is the |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 127 |
| 132 // Sets the |profile|, and sets up Profile related fields in this instance. | 128 // Sets the |profile|, and sets up Profile related fields in this instance. |
| 133 // IsArcAllowedForProfile() must return true for the given |profile|. | 129 // IsArcAllowedForProfile() must return true for the given |profile|. |
| 134 void SetProfile(Profile* profile); | 130 void SetProfile(Profile* profile); |
| 135 | 131 |
| 136 Profile* profile() { return profile_; } | 132 Profile* profile() { return profile_; } |
| 137 const Profile* profile() const { return profile_; } | 133 const Profile* profile() const { return profile_; } |
| 138 | 134 |
| 139 State state() const { return state_; } | 135 State state() const { return state_; } |
| 140 | 136 |
| 141 // Starts observing Google Play Store enabled preference change. | |
| 142 // Also, based on its initial value, this may start ArcSession, or may start | |
| 143 // removing the data, as initial state. | |
| 144 // In addition, this triggers to show ArcAuthNotification, if necessary. | |
| 145 // Note that this must be called after SetProfile(). | |
| 146 // TODO(hidehiko): Extract preference related code into a class to split the | |
| 147 // dependencty. | |
| 148 void StartPreferenceHandler(); | |
| 149 | |
| 150 // Adds or removes observers. | 137 // Adds or removes observers. |
| 151 void AddObserver(Observer* observer); | 138 void AddObserver(Observer* observer); |
| 152 void RemoveObserver(Observer* observer); | 139 void RemoveObserver(Observer* observer); |
| 153 | 140 |
| 141 // Notifies observers that Google Play Store enabled preference is changed. |
| 142 // Note: ArcPlayStoreEnabledPreferenceHandler has the main responsibility to |
| 143 // notify the event. However, due to life time, it is difficult for non-ARC |
| 144 // services to subscribe the handler instance directly. Instead, they can |
| 145 // subscribe to ArcSessionManager, and ArcSessionManager proxies the event. |
| 146 void NotifyArcPlayStoreEnabledChanged(bool enabled); |
| 147 |
| 154 // Returns true if ARC instance is running/stopped, respectively. | 148 // Returns true if ARC instance is running/stopped, respectively. |
| 155 // See ArcSessionRunner::IsRunning()/IsStopped() for details. | 149 // See ArcSessionRunner::IsRunning()/IsStopped() for details. |
| 156 bool IsSessionRunning() const; | 150 bool IsSessionRunning() const; |
| 157 bool IsSessionStopped() const; | 151 bool IsSessionStopped() const; |
| 158 | 152 |
| 159 // Called from ARC support platform app when user cancels signing. | 153 // Called from ARC support platform app when user cancels signing. |
| 160 void CancelAuthCode(); | 154 void CancelAuthCode(); |
| 161 | 155 |
| 162 // Requests to enable ARC session. This starts ARC instance, or maybe starts | 156 // Requests to enable ARC session. This starts ARC instance, or maybe starts |
| 163 // Terms Of Service negotiation if they haven't been accepted yet. | 157 // Terms Of Service negotiation if they haven't been accepted yet. |
| 164 // If it is already requested to enable, no-op. | 158 // If it is already requested to enable, no-op. |
| 165 // Currently, enabled/disabled is tied to whether Google Play Store is | 159 // Currently, enabled/disabled is tied to whether Google Play Store is |
| 166 // enabled or disabled. Please see also TODO of | 160 // enabled or disabled. Please see also TODO of |
| 167 // SetArcPlayStoreEnabledForProfile(). | 161 // SetArcPlayStoreEnabledForProfile(). |
| 168 void RequestEnable(); | 162 void RequestEnable(); |
| 169 | 163 |
| 170 // Requests to disable ARC session. This stops ARC instance, or quits Terms | 164 // Requests to disable ARC session. This stops ARC instance, or quits Terms |
| 171 // Of Service negotiation if it is the middle of the process (e.g. closing | 165 // Of Service negotiation if it is the middle of the process (e.g. closing |
| 172 // UI for manual negotiation if it is shown). | 166 // UI for manual negotiation if it is shown). |
| 173 // If it is already requested to disable, no-op. | 167 // If it is already requested to disable, no-op. |
| 174 void RequestDisable(); | 168 void RequestDisable(); |
| 175 | 169 |
| 176 // Called from the Chrome OS metrics provider to record Arc.State | 170 // Called from the Chrome OS metrics provider to record Arc.State |
| 177 // periodically. | 171 // periodically. |
| 178 void RecordArcState(); | 172 void RecordArcState(); |
| 179 | 173 |
| 180 // sync_preferences::PrefServiceSyncableObserver | |
| 181 void OnIsSyncingChanged() override; | |
| 182 | |
| 183 // ArcSupportHost::Observer: | 174 // ArcSupportHost::Observer: |
| 184 void OnWindowClosed() override; | 175 void OnWindowClosed() override; |
| 185 void OnTermsAgreed(bool is_metrics_enabled, | 176 void OnTermsAgreed(bool is_metrics_enabled, |
| 186 bool is_backup_and_restore_enabled, | 177 bool is_backup_and_restore_enabled, |
| 187 bool is_location_service_enabled) override; | 178 bool is_location_service_enabled) override; |
| 188 void OnRetryClicked() override; | 179 void OnRetryClicked() override; |
| 189 void OnSendFeedbackClicked() override; | 180 void OnSendFeedbackClicked() override; |
| 190 | 181 |
| 191 // StopArc(), then restart. Between them data clear may happens. | 182 // StopArc(), then restart. Between them data clear may happens. |
| 192 // This is a special method to support enterprise device lost case. | 183 // This is a special method to support enterprise device lost case. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 // Negotiates the terms of service to user. | 229 // Negotiates the terms of service to user. |
| 239 void StartTermsOfServiceNegotiation(); | 230 void StartTermsOfServiceNegotiation(); |
| 240 void OnTermsOfServiceNegotiated(bool accepted); | 231 void OnTermsOfServiceNegotiated(bool accepted); |
| 241 | 232 |
| 242 // Returns whether ARC is managed and all ARC related OptIn preferences are | 233 // Returns whether ARC is managed and all ARC related OptIn preferences are |
| 243 // managed too. | 234 // managed too. |
| 244 bool AreArcAllOptInPreferencesManaged() const; | 235 bool AreArcAllOptInPreferencesManaged() const; |
| 245 | 236 |
| 246 void SetState(State state); | 237 void SetState(State state); |
| 247 void ShutdownSession(); | 238 void ShutdownSession(); |
| 248 void OnOptInPreferenceChanged(); | |
| 249 void OnAndroidManagementPassed(); | 239 void OnAndroidManagementPassed(); |
| 250 void OnArcDataRemoved(bool success); | 240 void OnArcDataRemoved(bool success); |
| 251 void OnArcSignInTimeout(); | 241 void OnArcSignInTimeout(); |
| 252 | 242 |
| 253 void StartArcAndroidManagementCheck(); | 243 void StartArcAndroidManagementCheck(); |
| 254 void MaybeReenableArc(); | 244 void MaybeReenableArc(); |
| 255 | 245 |
| 256 // Called when the Android management check is done in opt-in flow or | 246 // Called when the Android management check is done in opt-in flow or |
| 257 // re-auth flow. | 247 // re-auth flow. |
| 258 void OnAndroidManagementChecked( | 248 void OnAndroidManagementChecked( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 275 void StopArc(); | 265 void StopArc(); |
| 276 | 266 |
| 277 // ArcSessionRunner::Observer: | 267 // ArcSessionRunner::Observer: |
| 278 void OnSessionStopped(ArcStopReason reason, bool restarting) override; | 268 void OnSessionStopped(ArcStopReason reason, bool restarting) override; |
| 279 | 269 |
| 280 std::unique_ptr<ArcSessionRunner> arc_session_runner_; | 270 std::unique_ptr<ArcSessionRunner> arc_session_runner_; |
| 281 | 271 |
| 282 // Unowned pointer. Keeps current profile. | 272 // Unowned pointer. Keeps current profile. |
| 283 Profile* profile_ = nullptr; | 273 Profile* profile_ = nullptr; |
| 284 | 274 |
| 285 // Registrar used to monitor ARC enabled state. | |
| 286 PrefChangeRegistrar pref_change_registrar_; | |
| 287 | |
| 288 // Whether ArcSessionManager is requested to enable (starting to run ARC | 275 // Whether ArcSessionManager is requested to enable (starting to run ARC |
| 289 // instance) or not. | 276 // instance) or not. |
| 290 bool enable_requested_ = false; | 277 bool enable_requested_ = false; |
| 291 | 278 |
| 292 // Internal state machine. See also State enum class. | 279 // Internal state machine. See also State enum class. |
| 293 State state_ = State::NOT_INITIALIZED; | 280 State state_ = State::NOT_INITIALIZED; |
| 294 base::ObserverList<Observer> observer_list_; | 281 base::ObserverList<Observer> observer_list_; |
| 295 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 282 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 296 bool reenable_arc_ = false; | 283 bool reenable_arc_ = false; |
| 297 bool provisioning_reported_ = false; | 284 bool provisioning_reported_ = false; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 316 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); | 303 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); |
| 317 }; | 304 }; |
| 318 | 305 |
| 319 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 306 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 320 std::ostream& operator<<(std::ostream& os, | 307 std::ostream& operator<<(std::ostream& os, |
| 321 const ArcSessionManager::State& state); | 308 const ArcSessionManager::State& state); |
| 322 | 309 |
| 323 } // namespace arc | 310 } // namespace arc |
| 324 | 311 |
| 325 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ | 312 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ |
| OLD | NEW |