| 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 <ostream> | 8 #include <ostream> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
| 12 #include "base/threading/thread_checker.h" | 12 #include "base/threading/thread_checker.h" |
| 13 #include "components/arc/arc_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
| 14 #include "components/arc/arc_service.h" | 14 #include "components/arc/arc_service.h" |
| 15 #include "components/arc/auth/arc_auth_fetcher.h" | |
| 16 #include "components/arc/common/auth.mojom.h" | 15 #include "components/arc/common/auth.mojom.h" |
| 17 #include "components/syncable_prefs/pref_service_syncable_observer.h" | 16 #include "components/syncable_prefs/pref_service_syncable_observer.h" |
| 18 #include "components/syncable_prefs/synced_pref_observer.h" | 17 #include "components/syncable_prefs/synced_pref_observer.h" |
| 19 #include "google_apis/gaia/gaia_auth_consumer.h" | 18 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 20 #include "google_apis/gaia/ubertoken_fetcher.h" | 19 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 21 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
| 22 | 21 |
| 23 class GaiaAuthFetcher; | 22 class GaiaAuthFetcher; |
| 24 class Profile; | 23 class Profile; |
| 25 | 24 |
| 26 namespace content { | 25 namespace content { |
| 27 class StoragePartition; | 26 class StoragePartition; |
| 28 } | 27 } |
| 29 | 28 |
| 30 namespace net { | 29 namespace net { |
| 31 class URLRequestContextGetter; | 30 class URLRequestContextGetter; |
| 32 } | 31 } |
| 33 | 32 |
| 34 namespace user_prefs { | 33 namespace user_prefs { |
| 35 class PrefRegistrySyncable; | 34 class PrefRegistrySyncable; |
| 36 } | 35 } |
| 37 | 36 |
| 38 namespace arc { | 37 namespace arc { |
| 39 | 38 |
| 40 // This class proxies the request from the client to fetch an auth code from | 39 // This class proxies the request from the client to fetch an auth code from |
| 41 // LSO. | 40 // LSO. |
| 42 class ArcAuthService : public ArcService, | 41 class ArcAuthService : public ArcService, |
| 43 public AuthHost, | 42 public AuthHost, |
| 44 public ArcBridgeService::Observer, | 43 public ArcBridgeService::Observer, |
| 45 public ArcAuthFetcher::Delegate, | |
| 46 public UbertokenConsumer, | 44 public UbertokenConsumer, |
| 47 public GaiaAuthConsumer, | 45 public GaiaAuthConsumer, |
| 48 public syncable_prefs::PrefServiceSyncableObserver, | 46 public syncable_prefs::PrefServiceSyncableObserver, |
| 49 public syncable_prefs::SyncedPrefObserver { | 47 public syncable_prefs::SyncedPrefObserver { |
| 50 public: | 48 public: |
| 51 enum class State { | 49 enum class State { |
| 52 STOPPED, // ARC is not running. | 50 STOPPED, // ARC is not running. |
| 53 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. | 51 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. |
| 54 ACTIVE, // ARC is running. | 52 ACTIVE, // ARC is running. |
| 55 }; | 53 }; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 void GetAuthCodeDeprecated( | 108 void GetAuthCodeDeprecated( |
| 111 const GetAuthCodeDeprecatedCallback& callback) override; | 109 const GetAuthCodeDeprecatedCallback& callback) override; |
| 112 void GetAuthCode(const GetAuthCodeCallback& callback) override; | 110 void GetAuthCode(const GetAuthCodeCallback& callback) override; |
| 113 void OnSignInComplete() override; | 111 void OnSignInComplete() override; |
| 114 void OnSignInFailed(arc::ArcSignInFailureReason reason) override; | 112 void OnSignInFailed(arc::ArcSignInFailureReason reason) override; |
| 115 // Callback is called with a bool that indicates the management status of the | 113 // Callback is called with a bool that indicates the management status of the |
| 116 // user. | 114 // user. |
| 117 void GetIsAccountManaged( | 115 void GetIsAccountManaged( |
| 118 const GetIsAccountManagedCallback& callback) override; | 116 const GetIsAccountManagedCallback& callback) override; |
| 119 | 117 |
| 120 // Called from Arc support platform app to check auth code. | 118 // Called from Arc support platform app to start LSO. |
| 121 void CheckAuthCode(); | 119 void StartLSO(); |
| 120 |
| 121 // Called from Arc support platform app to set auth code and start arc. |
| 122 void SetAuthCodeAndStartArc(const std::string& auth_code); |
| 122 | 123 |
| 123 // Called from Arc support platform app when user cancels signing. | 124 // Called from Arc support platform app when user cancels signing. |
| 124 void CancelAuthCode(); | 125 void CancelAuthCode(); |
| 125 | 126 |
| 126 void EnableArc(); | 127 void EnableArc(); |
| 127 void DisableArc(); | 128 void DisableArc(); |
| 128 | 129 |
| 129 // ArcAuthFetcher::Delegate: | |
| 130 void OnAuthCodeFetched(const std::string& auth_code) override; | |
| 131 void OnAuthCodeNeedUI() override; | |
| 132 void OnAuthCodeFailed() override; | |
| 133 | |
| 134 // UbertokenConsumer: | 130 // UbertokenConsumer: |
| 135 void OnUbertokenSuccess(const std::string& token) override; | 131 void OnUbertokenSuccess(const std::string& token) override; |
| 136 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; | 132 void OnUbertokenFailure(const GoogleServiceAuthError& error) override; |
| 137 | 133 |
| 138 // GaiaAuthConsumer: | 134 // GaiaAuthConsumer: |
| 139 void OnMergeSessionSuccess(const std::string& data) override; | 135 void OnMergeSessionSuccess(const std::string& data) override; |
| 140 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; | 136 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
| 141 | 137 |
| 142 // syncable_prefs::PrefServiceSyncableObserver | 138 // syncable_prefs::PrefServiceSyncableObserver |
| 143 void OnIsSyncingChanged() override; | 139 void OnIsSyncingChanged() override; |
| 144 | 140 |
| 145 // syncable_prefs::SyncedPrefObserver | 141 // syncable_prefs::SyncedPrefObserver |
| 146 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; | 142 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; |
| 147 | 143 |
| 148 // Returns current page that has to be shown in OptIn UI. | 144 // Returns current page that has to be shown in OptIn UI. |
| 149 UIPage ui_page() const { return ui_page_; } | 145 UIPage ui_page() const { return ui_page_; } |
| 150 // Returns current page status, relevant to the specific page. | 146 // Returns current page status, relevant to the specific page. |
| 151 const base::string16& ui_page_status() { return ui_page_status_; } | 147 const base::string16& ui_page_status() { return ui_page_status_; } |
| 152 | 148 |
| 153 private: | 149 private: |
| 154 void StartArc(); | 150 void StartArc(); |
| 155 void SetAuthCodeAndStartArc(const std::string& auth_code); | |
| 156 void PrepareContext(); | 151 void PrepareContext(); |
| 157 void ShowUI(UIPage page, const base::string16& status); | 152 void ShowUI(UIPage page, const base::string16& status); |
| 158 void CloseUI(); | 153 void CloseUI(); |
| 159 void SetUIPage(UIPage page, const base::string16& status); | 154 void SetUIPage(UIPage page, const base::string16& status); |
| 160 void SetState(State state); | 155 void SetState(State state); |
| 161 void ShutdownBridge(); | 156 void ShutdownBridge(); |
| 162 void ShutdownBridgeAndCloseUI(); | 157 void ShutdownBridgeAndCloseUI(); |
| 163 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); | 158 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); |
| 164 void OnOptInPreferenceChanged(); | 159 void OnOptInPreferenceChanged(); |
| 165 void FetchAuthCode(); | 160 void StartUI(); |
| 161 void OnPrepareContextFailed(); |
| 166 | 162 |
| 167 // Unowned pointer. Keeps current profile. | 163 // Unowned pointer. Keeps current profile. |
| 168 Profile* profile_ = nullptr; | 164 Profile* profile_ = nullptr; |
| 169 // Owned by content::BrowserContent. Used to isolate cookies for auth server | 165 // Owned by content::BrowserContent. Used to isolate cookies for auth server |
| 170 // communication and shared with Arc OptIn UI platform app. | 166 // communication and shared with Arc OptIn UI platform app. |
| 171 content::StoragePartition* storage_partition_ = nullptr; | 167 content::StoragePartition* storage_partition_ = nullptr; |
| 172 | 168 |
| 173 mojo::Binding<AuthHost> binding_; | 169 mojo::Binding<AuthHost> binding_; |
| 174 base::ThreadChecker thread_checker_; | 170 base::ThreadChecker thread_checker_; |
| 175 State state_ = State::STOPPED; | 171 State state_ = State::STOPPED; |
| 176 base::ObserverList<Observer> observer_list_; | 172 base::ObserverList<Observer> observer_list_; |
| 177 scoped_ptr<ArcAuthFetcher> auth_fetcher_; | |
| 178 scoped_ptr<GaiaAuthFetcher> merger_fetcher_; | 173 scoped_ptr<GaiaAuthFetcher> merger_fetcher_; |
| 179 scoped_ptr<UbertokenFetcher> ubertoken_fethcher_; | 174 scoped_ptr<UbertokenFetcher> ubertoken_fethcher_; |
| 180 std::string auth_code_; | 175 std::string auth_code_; |
| 181 GetAuthCodeCallback auth_callback_; | 176 GetAuthCodeCallback auth_callback_; |
| 182 bool initial_opt_in_ = false; | 177 bool initial_opt_in_ = false; |
| 183 bool context_prepared_ = false; | 178 bool context_prepared_ = false; |
| 184 UIPage ui_page_ = UIPage::NO_PAGE; | 179 UIPage ui_page_ = UIPage::NO_PAGE; |
| 185 base::string16 ui_page_status_; | 180 base::string16 ui_page_status_; |
| 186 | 181 |
| 187 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 182 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 188 }; | 183 }; |
| 189 | 184 |
| 190 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); | 185 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); |
| 191 | 186 |
| 192 } // namespace arc | 187 } // namespace arc |
| 193 | 188 |
| 194 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 189 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |