| 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 #include <string> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" |
| 11 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "chrome/browser/chromeos/policy/android_management_client.h" |
| 12 #include "components/arc/arc_bridge_service.h" | 15 #include "components/arc/arc_bridge_service.h" |
| 13 #include "components/arc/arc_service.h" | 16 #include "components/arc/arc_service.h" |
| 14 #include "components/arc/common/auth.mojom.h" | 17 #include "components/arc/common/auth.mojom.h" |
| 15 #include "components/prefs/pref_change_registrar.h" | 18 #include "components/prefs/pref_change_registrar.h" |
| 16 #include "components/syncable_prefs/pref_service_syncable_observer.h" | 19 #include "components/syncable_prefs/pref_service_syncable_observer.h" |
| 17 #include "components/syncable_prefs/synced_pref_observer.h" | 20 #include "components/syncable_prefs/synced_pref_observer.h" |
| 18 #include "google_apis/gaia/gaia_auth_consumer.h" | 21 #include "google_apis/gaia/gaia_auth_consumer.h" |
| 22 #include "google_apis/gaia/oauth2_token_service.h" |
| 19 #include "google_apis/gaia/ubertoken_fetcher.h" | 23 #include "google_apis/gaia/ubertoken_fetcher.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" | 24 #include "mojo/public/cpp/bindings/binding.h" |
| 21 | 25 |
| 22 class ArcAppLauncher; | 26 class ArcAppLauncher; |
| 23 class GaiaAuthFetcher; | 27 class GaiaAuthFetcher; |
| 28 class GoogleServiceAuthError; |
| 24 class Profile; | 29 class Profile; |
| 30 class ProfileOAuth2TokenService; |
| 25 | 31 |
| 26 namespace content { | 32 namespace content { |
| 27 class StoragePartition; | 33 class StoragePartition; |
| 28 } | 34 } |
| 29 | 35 |
| 30 namespace net { | 36 namespace net { |
| 31 class URLRequestContextGetter; | 37 class URLRequestContextGetter; |
| 32 } | 38 } |
| 33 | 39 |
| 34 namespace user_prefs { | 40 namespace user_prefs { |
| 35 class PrefRegistrySyncable; | 41 class PrefRegistrySyncable; |
| 36 } | 42 } |
| 37 | 43 |
| 38 namespace arc { | 44 namespace arc { |
| 39 | 45 |
| 40 // This class proxies the request from the client to fetch an auth code from | 46 // This class proxies the request from the client to fetch an auth code from |
| 41 // LSO. | 47 // LSO. |
| 42 class ArcAuthService : public ArcService, | 48 class ArcAuthService : public ArcService, |
| 43 public mojom::AuthHost, | 49 public mojom::AuthHost, |
| 44 public ArcBridgeService::Observer, | 50 public ArcBridgeService::Observer, |
| 45 public UbertokenConsumer, | 51 public UbertokenConsumer, |
| 46 public GaiaAuthConsumer, | 52 public GaiaAuthConsumer, |
| 53 public OAuth2TokenService::Consumer, |
| 47 public syncable_prefs::PrefServiceSyncableObserver, | 54 public syncable_prefs::PrefServiceSyncableObserver, |
| 48 public syncable_prefs::SyncedPrefObserver { | 55 public syncable_prefs::SyncedPrefObserver { |
| 49 public: | 56 public: |
| 50 enum class State { | 57 enum class State { |
| 51 STOPPED, // ARC is not running. | 58 STOPPED, // ARC is not running. |
| 52 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. | 59 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. |
| 53 ACTIVE, // ARC is running. | 60 ACTIVE, // ARC is running. |
| 54 }; | 61 }; |
| 55 | 62 |
| 56 enum class UIPage { | 63 enum class UIPage { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 82 static ArcAuthService* Get(); | 89 static ArcAuthService* Get(); |
| 83 | 90 |
| 84 // It is called from chrome/browser/prefs/browser_prefs.cc. | 91 // It is called from chrome/browser/prefs/browser_prefs.cc. |
| 85 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 92 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
| 86 | 93 |
| 87 static void DisableUIForTesting(); | 94 static void DisableUIForTesting(); |
| 88 | 95 |
| 89 // Checks if OptIn verification was disabled by switch in command line. | 96 // Checks if OptIn verification was disabled by switch in command line. |
| 90 static bool IsOptInVerificationDisabled(); | 97 static bool IsOptInVerificationDisabled(); |
| 91 | 98 |
| 99 static void EnableCheckAndroidManagementForTesting(const char* access_token); |
| 100 |
| 92 void OnPrimaryUserProfilePrepared(Profile* profile); | 101 void OnPrimaryUserProfilePrepared(Profile* profile); |
| 93 void Shutdown(); | 102 void Shutdown(); |
| 94 | 103 |
| 95 State state() const { return state_; } | 104 State state() const { return state_; } |
| 96 | 105 |
| 97 std::string GetAndResetAuthCode(); | 106 std::string GetAndResetAuthCode(); |
| 98 | 107 |
| 99 // Adds or removes observers. | 108 // Adds or removes observers. |
| 100 void AddObserver(Observer* observer); | 109 void AddObserver(Observer* observer); |
| 101 void RemoveObserver(Observer* observer); | 110 void RemoveObserver(Observer* observer); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 // GaiaAuthConsumer: | 144 // GaiaAuthConsumer: |
| 136 void OnMergeSessionSuccess(const std::string& data) override; | 145 void OnMergeSessionSuccess(const std::string& data) override; |
| 137 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; | 146 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override; |
| 138 | 147 |
| 139 // syncable_prefs::PrefServiceSyncableObserver | 148 // syncable_prefs::PrefServiceSyncableObserver |
| 140 void OnIsSyncingChanged() override; | 149 void OnIsSyncingChanged() override; |
| 141 | 150 |
| 142 // syncable_prefs::SyncedPrefObserver | 151 // syncable_prefs::SyncedPrefObserver |
| 143 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; | 152 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; |
| 144 | 153 |
| 154 // OAuth2TokenService::Consumer implementation: |
| 155 void OnGetTokenSuccess(const OAuth2TokenService::Request* request, |
| 156 const std::string& access_token, |
| 157 const base::Time& expiration_time) override; |
| 158 void OnGetTokenFailure(const OAuth2TokenService::Request* request, |
| 159 const GoogleServiceAuthError& error) override; |
| 160 |
| 145 // Returns current page that has to be shown in OptIn UI. | 161 // Returns current page that has to be shown in OptIn UI. |
| 146 UIPage ui_page() const { return ui_page_; } | 162 UIPage ui_page() const { return ui_page_; } |
| 147 // Returns current page status, relevant to the specific page. | 163 // Returns current page status, relevant to the specific page. |
| 148 const base::string16& ui_page_status() { return ui_page_status_; } | 164 const base::string16& ui_page_status() { return ui_page_status_; } |
| 149 | |
| 150 private: | 165 private: |
| 151 void StartArc(); | 166 void StartArc(); |
| 152 void PrepareContext(); | 167 void PrepareContext(); |
| 153 void ShowUI(UIPage page, const base::string16& status); | 168 void ShowUI(UIPage page, const base::string16& status); |
| 154 void CloseUI(); | 169 void CloseUI(); |
| 155 void SetUIPage(UIPage page, const base::string16& status); | 170 void SetUIPage(UIPage page, const base::string16& status); |
| 156 void SetState(State state); | 171 void SetState(State state); |
| 157 void ShutdownBridge(); | 172 void ShutdownBridge(); |
| 158 void ShutdownBridgeAndCloseUI(); | 173 void ShutdownBridgeAndCloseUI(); |
| 159 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); | 174 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); |
| 160 void OnOptInPreferenceChanged(); | 175 void OnOptInPreferenceChanged(); |
| 161 void StartUI(); | 176 void StartUI(); |
| 162 void OnPrepareContextFailed(); | 177 void OnPrepareContextFailed(); |
| 178 void StartAndroidManagementClient(); |
| 179 void CheckAndroidManagement(); |
| 180 void OnAndroidManagementChecked( |
| 181 policy::AndroidManagementClient::Result result); |
| 163 | 182 |
| 164 // Unowned pointer. Keeps current profile. | 183 // Unowned pointer. Keeps current profile. |
| 165 Profile* profile_ = nullptr; | 184 Profile* profile_ = nullptr; |
| 166 // Owned by content::BrowserContent. Used to isolate cookies for auth server | 185 // Owned by content::BrowserContent. Used to isolate cookies for auth server |
| 167 // communication and shared with Arc OptIn UI platform app. | 186 // communication and shared with Arc OptIn UI platform app. |
| 168 content::StoragePartition* storage_partition_ = nullptr; | 187 content::StoragePartition* storage_partition_ = nullptr; |
| 169 | 188 |
| 170 // Registrar used to monitor ARC enabled state. | 189 // Registrar used to monitor ARC enabled state. |
| 171 PrefChangeRegistrar pref_change_registrar_; | 190 PrefChangeRegistrar pref_change_registrar_; |
| 172 | 191 |
| 173 mojo::Binding<AuthHost> binding_; | 192 mojo::Binding<AuthHost> binding_; |
| 174 State state_ = State::STOPPED; | 193 State state_ = State::STOPPED; |
| 175 base::ObserverList<Observer> observer_list_; | 194 base::ObserverList<Observer> observer_list_; |
| 176 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; | 195 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; |
| 177 std::unique_ptr<UbertokenFetcher> ubertoken_fethcher_; | 196 std::unique_ptr<UbertokenFetcher> ubertoken_fethcher_; |
| 178 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 197 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
| 179 std::string auth_code_; | 198 std::string auth_code_; |
| 180 GetAuthCodeCallback auth_callback_; | 199 GetAuthCodeCallback auth_callback_; |
| 181 bool initial_opt_in_ = false; | 200 bool initial_opt_in_ = false; |
| 182 bool context_prepared_ = false; | 201 bool context_prepared_ = false; |
| 183 UIPage ui_page_ = UIPage::NO_PAGE; | 202 UIPage ui_page_ = UIPage::NO_PAGE; |
| 184 base::string16 ui_page_status_; | 203 base::string16 ui_page_status_; |
| 185 | 204 |
| 205 ProfileOAuth2TokenService* token_service_; |
| 206 std::string account_id_; |
| 207 |
| 208 std::unique_ptr<policy::AndroidManagementClient> android_management_client_; |
| 209 std::unique_ptr<OAuth2TokenService::Request> token_request_; |
| 210 |
| 211 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; |
| 212 |
| 186 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 213 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 187 }; | 214 }; |
| 188 | 215 |
| 189 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); | 216 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); |
| 190 | 217 |
| 191 } // namespace arc | 218 } // namespace arc |
| 192 | 219 |
| 193 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 220 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |