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_observer.h" |
| 19 #include "components/prefs/pref_change_registrar.h" | |
| 20 #include "components/sync_preferences/pref_service_syncable_observer.h" | |
| 21 | 19 |
| 22 class ArcAppLauncher; | 20 class ArcAppLauncher; |
| 23 class Profile; | 21 class Profile; |
| 24 | 22 |
| 25 namespace user_prefs { | 23 namespace user_prefs { |
| 26 class PrefRegistrySyncable; | 24 class PrefRegistrySyncable; |
| 27 } | 25 } |
| 28 | 26 |
| 29 namespace arc { | 27 namespace arc { |
| 30 | 28 |
| 31 class ArcAndroidManagementChecker; | 29 class ArcAndroidManagementChecker; |
| 32 class ArcAuthInfoFetcher; | |
| 33 class ArcAuthContext; | 30 class ArcAuthContext; |
| 34 class ArcSessionRunner; | 31 class ArcSessionRunner; |
| 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 ArcSessionObserver, | 37 class ArcSessionManager : public ArcSessionObserver, |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 121 |
| 126 // Sets the |profile|, and sets up Profile related fields in this instance. | 122 // Sets the |profile|, and sets up Profile related fields in this instance. |
| 127 // IsArcAllowedForProfile() must return true for the given |profile|. | 123 // IsArcAllowedForProfile() must return true for the given |profile|. |
| 128 void SetProfile(Profile* profile); | 124 void SetProfile(Profile* profile); |
| 129 | 125 |
| 130 Profile* profile() { return profile_; } | 126 Profile* profile() { return profile_; } |
| 131 const Profile* profile() const { return profile_; } | 127 const Profile* profile() const { return profile_; } |
| 132 | 128 |
| 133 State state() const { return state_; } | 129 State state() const { return state_; } |
| 134 | 130 |
| 135 // Starts observing Google Play Store enabled preference change. | |
| 136 // Also, based on its initial value, this may start ArcSession, or may start | |
| 137 // removing the data, as initial state. | |
| 138 // In addition, this triggers to show ArcAuthNotification, if necessary. | |
| 139 // Note that this must be called after SetProfile(). | |
| 140 // TODO(hidehiko): Extract preference related code into a class to split the | |
| 141 // dependencty. | |
| 142 void StartPreferenceHandler(); | |
| 143 | |
| 144 // Adds or removes observers. | 131 // Adds or removes observers. |
| 145 void AddObserver(Observer* observer); | 132 void AddObserver(Observer* observer); |
| 146 void RemoveObserver(Observer* observer); | 133 void RemoveObserver(Observer* observer); |
| 147 | 134 |
| 135 // Notifies observers that Google Play Store enabled preference is changed. | |
| 136 // Note: ArcPlayStoreEnabledPreferenceHandler has the main responsibility to | |
| 137 // notify the event. However, due to life time, it is difficult for non-ARC | |
| 138 // services to subscribe the handler instance directly. Instead, they can to | |
|
Luis Héctor Chávez
2017/03/02 00:09:17
nit: Instead, they can subscribe to
hidehiko
2017/03/02 02:21:57
Done.
| |
| 139 // ArcSessionManager, and ArcSessionManager proxies the event. | |
| 140 void NotifyArcPlayStoreEnabledChanged(bool enabled); | |
| 141 | |
| 148 // Adds or removes ArcSessionObservers. | 142 // Adds or removes ArcSessionObservers. |
| 149 // TODO(hidehiko): The observer should be migrated into | 143 // TODO(hidehiko): The observer should be migrated into |
| 150 // ArcSessionManager::Observer. | 144 // ArcSessionManager::Observer. |
| 151 void AddSessionObserver(ArcSessionObserver* observer); | 145 void AddSessionObserver(ArcSessionObserver* observer); |
| 152 void RemoveSessionObserver(ArcSessionObserver* observer); | 146 void RemoveSessionObserver(ArcSessionObserver* observer); |
| 153 | 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; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 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 // Stops ARC without changing ArcEnabled preference. | 182 // Stops ARC without changing ArcEnabled preference. |
| 192 void StopArc(); | 183 void StopArc(); |
| 193 | 184 |
| 194 // StopArc(), then restart. Between them data clear may happens. | 185 // StopArc(), then restart. Between them data clear may happens. |
| 195 // This is a special method to support enterprise device lost case. | 186 // This is a special method to support enterprise device lost case. |
| 196 // This can be called only when ARC is running. | 187 // This can be called only when ARC is running. |
| 197 void StopAndEnableArc(); | 188 void StopAndEnableArc(); |
| 198 | 189 |
| 199 // Removes the data if ARC is stopped. Otherwise, queue to remove the data | 190 // Removes the data if ARC is stopped. Otherwise, queue to remove the data |
| 200 // on ARC is stopped. A log statement with the removal reason must be added | 191 // on ARC is stopped. A log statement with the removal reason must be added |
| 201 // prior to calling RemoveArcData(). | 192 // prior to calling RemoveArcData(). |
| 202 void RemoveArcData(); | 193 void RemoveArcData(); |
| 203 | 194 |
| 204 ArcSupportHost* support_host() { return support_host_.get(); } | 195 ArcSupportHost* support_host() { return support_host_.get(); } |
| 205 | 196 |
| 206 // TODO(hidehiko): Get rid of the getter by migration between ArcAuthContext | 197 // TODO(hidehiko): Get rid of the getter by migration between ArcAuthContext |
| 207 // and ArcAuthInfoFetcher. | 198 // and ArcAuthInfoFetcher. |
| 208 ArcAuthContext* auth_context() { return context_.get(); } | 199 ArcAuthContext* auth_context() { return context_.get(); } |
| 209 | 200 |
| 210 void StartArc(); | 201 void StartArc(); |
|
Yusuke Sato
2017/03/01 18:09:27
While you're at it, can you give a function commen
hidehiko
2017/03/01 19:21:31
Done in another CL.
| |
| 211 | 202 |
| 212 void OnProvisioningFinished(ProvisioningResult result); | 203 void OnProvisioningFinished(ProvisioningResult result); |
|
Yusuke Sato
2017/03/01 18:09:27
same
hidehiko
2017/03/01 19:21:31
Ditto.
| |
| 213 | 204 |
| 214 // Returns the time when the sign in process started, or a null time if | 205 // Returns the time when the sign in process started, or a null time if |
| 215 // signing in didn't happen during this session. | 206 // signing in didn't happen during this session. |
| 216 base::Time sign_in_start_time() const { return sign_in_start_time_; } | 207 base::Time sign_in_start_time() const { return sign_in_start_time_; } |
| 217 | 208 |
| 218 // Returns the time when ARC was about to start, or a null time if ARC has not | 209 // Returns the time when ARC was about to start, or a null time if ARC has not |
| 219 // been started yet. | 210 // been started yet. |
| 220 base::Time arc_start_time() const { return arc_start_time_; } | 211 base::Time arc_start_time() const { return arc_start_time_; } |
| 221 | 212 |
| 222 // Injectors for testing. | 213 // Injectors for testing. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 236 // Negotiates the terms of service to user. | 227 // Negotiates the terms of service to user. |
| 237 void StartTermsOfServiceNegotiation(); | 228 void StartTermsOfServiceNegotiation(); |
| 238 void OnTermsOfServiceNegotiated(bool accepted); | 229 void OnTermsOfServiceNegotiated(bool accepted); |
| 239 | 230 |
| 240 // Returns whether ARC is managed and all ARC related OptIn preferences are | 231 // Returns whether ARC is managed and all ARC related OptIn preferences are |
| 241 // managed too. | 232 // managed too. |
| 242 bool AreArcAllOptInPreferencesManaged() const; | 233 bool AreArcAllOptInPreferencesManaged() const; |
| 243 | 234 |
| 244 void SetState(State state); | 235 void SetState(State state); |
| 245 void ShutdownSession(); | 236 void ShutdownSession(); |
| 246 void OnOptInPreferenceChanged(); | |
| 247 void OnAndroidManagementPassed(); | 237 void OnAndroidManagementPassed(); |
| 248 void OnArcDataRemoved(bool success); | 238 void OnArcDataRemoved(bool success); |
| 249 void OnArcSignInTimeout(); | 239 void OnArcSignInTimeout(); |
| 250 | 240 |
| 251 void StartArcAndroidManagementCheck(); | 241 void StartArcAndroidManagementCheck(); |
| 252 void MaybeReenableArc(); | 242 void MaybeReenableArc(); |
| 253 | 243 |
| 254 // Called when the Android management check is done in opt-in flow or | 244 // Called when the Android management check is done in opt-in flow or |
| 255 // re-auth flow. | 245 // re-auth flow. |
| 256 void OnAndroidManagementChecked( | 246 void OnAndroidManagementChecked( |
| 257 policy::AndroidManagementClient::Result result); | 247 policy::AndroidManagementClient::Result result); |
| 258 | 248 |
| 259 // Called when the background Android management check is done. It is | 249 // Called when the background Android management check is done. It is |
| 260 // triggered when the second or later ARC boot timing. | 250 // triggered when the second or later ARC boot timing. |
| 261 void OnBackgroundAndroidManagementChecked( | 251 void OnBackgroundAndroidManagementChecked( |
| 262 policy::AndroidManagementClient::Result result); | 252 policy::AndroidManagementClient::Result result); |
| 263 | 253 |
| 264 // ArcSessionObserver: | 254 // ArcSessionObserver: |
| 265 void OnSessionReady() override; | 255 void OnSessionReady() override; |
| 266 void OnSessionStopped(StopReason reason) override; | 256 void OnSessionStopped(StopReason reason) override; |
| 267 | 257 |
| 268 std::unique_ptr<ArcSessionRunner> arc_session_runner_; | 258 std::unique_ptr<ArcSessionRunner> arc_session_runner_; |
| 269 | 259 |
| 270 // Unowned pointer. Keeps current profile. | 260 // Unowned pointer. Keeps current profile. |
| 271 Profile* profile_ = nullptr; | 261 Profile* profile_ = nullptr; |
| 272 | 262 |
| 273 // Registrar used to monitor ARC enabled state. | |
| 274 PrefChangeRegistrar pref_change_registrar_; | |
| 275 | |
| 276 // Whether ArcSessionManager is requested to enable (starting to run ARC | 263 // Whether ArcSessionManager is requested to enable (starting to run ARC |
| 277 // instance) or not. | 264 // instance) or not. |
| 278 bool enable_requested_ = false; | 265 bool enable_requested_ = false; |
| 279 | 266 |
| 280 // Internal state machine. See also State enum class. | 267 // Internal state machine. See also State enum class. |
| 281 State state_ = State::NOT_INITIALIZED; | 268 State state_ = State::NOT_INITIALIZED; |
| 282 base::ObserverList<Observer> observer_list_; | 269 base::ObserverList<Observer> observer_list_; |
| 283 base::ObserverList<ArcSessionObserver> arc_session_observer_list_; | 270 base::ObserverList<ArcSessionObserver> arc_session_observer_list_; |
| 284 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 271 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 285 bool reenable_arc_ = false; | 272 bool reenable_arc_ = false; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 305 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); | 292 DISALLOW_COPY_AND_ASSIGN(ArcSessionManager); |
| 306 }; | 293 }; |
| 307 | 294 |
| 308 // Outputs the stringified |state| to |os|. This is only for logging purposes. | 295 // Outputs the stringified |state| to |os|. This is only for logging purposes. |
| 309 std::ostream& operator<<(std::ostream& os, | 296 std::ostream& operator<<(std::ostream& os, |
| 310 const ArcSessionManager::State& state); | 297 const ArcSessionManager::State& state); |
| 311 | 298 |
| 312 } // namespace arc | 299 } // namespace arc |
| 313 | 300 |
| 314 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ | 301 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_SESSION_MANAGER_H_ |
| OLD | NEW |