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 <memory> | |
9 #include <ostream> | 8 #include <ostream> |
10 #include <string> | |
11 | 9 |
12 #include "base/macros.h" | 10 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
15 #include "chrome/browser/chromeos/policy/android_management_client.h" | |
16 #include "components/arc/arc_bridge_service.h" | 12 #include "components/arc/arc_bridge_service.h" |
17 #include "components/arc/arc_service.h" | 13 #include "components/arc/arc_service.h" |
18 #include "components/arc/common/auth.mojom.h" | 14 #include "components/arc/common/auth.mojom.h" |
19 #include "components/prefs/pref_change_registrar.h" | 15 #include "components/prefs/pref_change_registrar.h" |
20 #include "components/syncable_prefs/pref_service_syncable_observer.h" | 16 #include "components/syncable_prefs/pref_service_syncable_observer.h" |
21 #include "components/syncable_prefs/synced_pref_observer.h" | 17 #include "components/syncable_prefs/synced_pref_observer.h" |
| 18 #include "google_apis/gaia/gaia_auth_consumer.h" |
22 #include "google_apis/gaia/ubertoken_fetcher.h" | 19 #include "google_apis/gaia/ubertoken_fetcher.h" |
23 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
24 | 21 |
25 class ArcAppLauncher; | 22 class ArcAppLauncher; |
26 class GaiaAuthFetcher; | 23 class GaiaAuthFetcher; |
27 class Profile; | 24 class Profile; |
28 class ProfileOAuth2TokenService; | |
29 | 25 |
30 namespace content { | 26 namespace content { |
31 class StoragePartition; | 27 class StoragePartition; |
32 } | 28 } |
33 | 29 |
34 namespace net { | 30 namespace net { |
35 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
36 } | 32 } |
37 | 33 |
38 namespace user_prefs { | 34 namespace user_prefs { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 virtual ~Observer() = default; | 67 virtual ~Observer() = default; |
72 | 68 |
73 // Called whenever Opt-In state of the ARC has been changed. | 69 // Called whenever Opt-In state of the ARC has been changed. |
74 virtual void OnOptInChanged(State state) {} | 70 virtual void OnOptInChanged(State state) {} |
75 | 71 |
76 // Called to notify that OptIn UI needs to be closed. | 72 // Called to notify that OptIn UI needs to be closed. |
77 virtual void OnOptInUIClose() {} | 73 virtual void OnOptInUIClose() {} |
78 | 74 |
79 // Called to notify that OptIn UI needs to show specific page. | 75 // Called to notify that OptIn UI needs to show specific page. |
80 virtual void OnOptInUIShowPage(UIPage page, const base::string16& status) {} | 76 virtual void OnOptInUIShowPage(UIPage page, const base::string16& status) {} |
81 | |
82 // Called to notify that ARC bridge is shut down. | |
83 virtual void OnShutdownBridge() {} | |
84 }; | 77 }; |
85 | 78 |
86 explicit ArcAuthService(ArcBridgeService* bridge_service); | 79 explicit ArcAuthService(ArcBridgeService* bridge_service); |
87 ~ArcAuthService() override; | 80 ~ArcAuthService() override; |
88 | 81 |
89 static ArcAuthService* Get(); | 82 static ArcAuthService* Get(); |
90 | 83 |
91 // It is called from chrome/browser/prefs/browser_prefs.cc. | 84 // It is called from chrome/browser/prefs/browser_prefs.cc. |
92 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); | 85 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); |
93 | 86 |
94 static void DisableUIForTesting(); | 87 static void DisableUIForTesting(); |
95 | 88 |
96 // Checks if OptIn verification was disabled by switch in command line. | 89 // Checks if OptIn verification was disabled by switch in command line. |
97 static bool IsOptInVerificationDisabled(); | 90 static bool IsOptInVerificationDisabled(); |
98 | 91 |
99 static void EnableCheckAndroidManagementForTesting(); | |
100 | |
101 void OnPrimaryUserProfilePrepared(Profile* profile); | 92 void OnPrimaryUserProfilePrepared(Profile* profile); |
102 void Shutdown(); | 93 void Shutdown(); |
103 | 94 |
104 State state() const { return state_; } | 95 State state() const { return state_; } |
105 | 96 |
106 std::string GetAndResetAuthCode(); | 97 std::string GetAndResetAuthCode(); |
107 | 98 |
108 // Adds or removes observers. | 99 // Adds or removes observers. |
109 void AddObserver(Observer* observer); | 100 void AddObserver(Observer* observer); |
110 void RemoveObserver(Observer* observer); | 101 void RemoveObserver(Observer* observer); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 void ShowUI(UIPage page, const base::string16& status); | 153 void ShowUI(UIPage page, const base::string16& status); |
163 void CloseUI(); | 154 void CloseUI(); |
164 void SetUIPage(UIPage page, const base::string16& status); | 155 void SetUIPage(UIPage page, const base::string16& status); |
165 void SetState(State state); | 156 void SetState(State state); |
166 void ShutdownBridge(); | 157 void ShutdownBridge(); |
167 void ShutdownBridgeAndCloseUI(); | 158 void ShutdownBridgeAndCloseUI(); |
168 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); | 159 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); |
169 void OnOptInPreferenceChanged(); | 160 void OnOptInPreferenceChanged(); |
170 void StartUI(); | 161 void StartUI(); |
171 void OnPrepareContextFailed(); | 162 void OnPrepareContextFailed(); |
172 void StartAndroidManagementClient(); | |
173 void CheckAndroidManagement(); | |
174 void OnAndroidManagementChecked( | |
175 policy::AndroidManagementClient::Result result); | |
176 void StartArcIfSignedIn(); | |
177 | 163 |
178 // Unowned pointer. Keeps current profile. | 164 // Unowned pointer. Keeps current profile. |
179 Profile* profile_ = nullptr; | 165 Profile* profile_ = nullptr; |
180 // Owned by content::BrowserContent. Used to isolate cookies for auth server | 166 // Owned by content::BrowserContent. Used to isolate cookies for auth server |
181 // communication and shared with Arc OptIn UI platform app. | 167 // communication and shared with Arc OptIn UI platform app. |
182 content::StoragePartition* storage_partition_ = nullptr; | 168 content::StoragePartition* storage_partition_ = nullptr; |
183 | 169 |
184 // Registrar used to monitor ARC enabled state. | 170 // Registrar used to monitor ARC enabled state. |
185 PrefChangeRegistrar pref_change_registrar_; | 171 PrefChangeRegistrar pref_change_registrar_; |
186 | 172 |
187 mojo::Binding<AuthHost> binding_; | 173 mojo::Binding<AuthHost> binding_; |
188 State state_ = State::STOPPED; | 174 State state_ = State::STOPPED; |
189 base::ObserverList<Observer> observer_list_; | 175 base::ObserverList<Observer> observer_list_; |
190 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; | 176 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_; |
191 std::unique_ptr<UbertokenFetcher> ubertoken_fethcher_; | 177 std::unique_ptr<UbertokenFetcher> ubertoken_fethcher_; |
192 std::unique_ptr<ArcAppLauncher> playstore_launcher_; | 178 std::unique_ptr<ArcAppLauncher> playstore_launcher_; |
193 std::string auth_code_; | 179 std::string auth_code_; |
194 GetAuthCodeCallback auth_callback_; | 180 GetAuthCodeCallback auth_callback_; |
195 bool initial_opt_in_ = false; | 181 bool initial_opt_in_ = false; |
196 bool context_prepared_ = false; | 182 bool context_prepared_ = false; |
197 UIPage ui_page_ = UIPage::NO_PAGE; | 183 UIPage ui_page_ = UIPage::NO_PAGE; |
198 base::string16 ui_page_status_; | 184 base::string16 ui_page_status_; |
199 | 185 |
200 ProfileOAuth2TokenService* token_service_; | |
201 std::string account_id_; | |
202 std::unique_ptr<policy::AndroidManagementClient> android_management_client_; | |
203 | |
204 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; | |
205 | |
206 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 186 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
207 }; | 187 }; |
208 | 188 |
209 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); | 189 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); |
210 | 190 |
211 } // namespace arc | 191 } // namespace arc |
212 | 192 |
213 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 193 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
OLD | NEW |