Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.h

Issue 2102793002: arc: Implement silent OptIn mode for managed Arc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: refactored Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 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 "chrome/browser/chromeos/arc/arc_android_management_checker_delegate.h" 15 #include "chrome/browser/chromeos/arc/arc_android_management_checker_delegate.h"
16 #include "chrome/browser/chromeos/arc/arc_auth_context_delegate.h"
16 #include "components/arc/arc_bridge_service.h" 17 #include "components/arc/arc_bridge_service.h"
17 #include "components/arc/arc_service.h" 18 #include "components/arc/arc_service.h"
18 #include "components/arc/common/auth.mojom.h" 19 #include "components/arc/common/auth.mojom.h"
19 #include "components/prefs/pref_change_registrar.h" 20 #include "components/prefs/pref_change_registrar.h"
20 #include "components/syncable_prefs/pref_service_syncable_observer.h" 21 #include "components/syncable_prefs/pref_service_syncable_observer.h"
21 #include "components/syncable_prefs/synced_pref_observer.h" 22 #include "components/syncable_prefs/synced_pref_observer.h"
22 #include "google_apis/gaia/ubertoken_fetcher.h"
23 #include "mojo/public/cpp/bindings/binding.h" 23 #include "mojo/public/cpp/bindings/binding.h"
24 24
25 class ArcAndroidManagementChecker; 25 class ArcAndroidManagementChecker;
26 class ArcAppLauncher; 26 class ArcAppLauncher;
27 class GaiaAuthFetcher; 27 class ArcAuthContext;
28 class Profile; 28 class Profile;
29 class ProfileOAuth2TokenService;
30 29
31 namespace ash { 30 namespace ash {
32 class ShelfDelegate; 31 class ShelfDelegate;
33 } 32 }
34 33
35 namespace content {
36 class StoragePartition;
37 }
38
39 namespace net {
40 class URLRequestContextGetter;
41 }
42
43 namespace user_prefs { 34 namespace user_prefs {
44 class PrefRegistrySyncable; 35 class PrefRegistrySyncable;
45 } 36 }
46 37
47 namespace arc { 38 namespace arc {
48 39
49 // This class proxies the request from the client to fetch an auth code from 40 // This class proxies the request from the client to fetch an auth code from
50 // LSO. 41 // LSO.
51 class ArcAuthService : public ArcService, 42 class ArcAuthService : public ArcService,
52 public mojom::AuthHost, 43 public mojom::AuthHost,
53 public ArcBridgeService::Observer, 44 public ArcBridgeService::Observer,
54 public ArcAndroidManagementCheckerDelegate, 45 public ArcAndroidManagementCheckerDelegate,
55 public UbertokenConsumer, 46 public ArcAuthContextDelegate,
56 public GaiaAuthConsumer,
57 public syncable_prefs::PrefServiceSyncableObserver, 47 public syncable_prefs::PrefServiceSyncableObserver,
58 public syncable_prefs::SyncedPrefObserver { 48 public syncable_prefs::SyncedPrefObserver {
59 public: 49 public:
60 enum class State { 50 enum class State {
61 NOT_INITIALIZED, // Service is not initialized. 51 NOT_INITIALIZED, // Service is not initialized.
62 STOPPED, // ARC is not running. 52 STOPPED, // ARC is not running.
63 FETCHING_CODE, // ARC may be running or not. Auth code is fetching. 53 FETCHING_CODE, // ARC may be running or not. Auth code is fetching.
64 ACTIVE, // ARC is running. 54 ACTIVE, // ARC is running.
65 }; 55 };
66 56
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 void SetAuthCodeAndStartArc(const std::string& auth_code); 143 void SetAuthCodeAndStartArc(const std::string& auth_code);
154 144
155 // Called from Arc support platform app when user cancels signing. 145 // Called from Arc support platform app when user cancels signing.
156 void CancelAuthCode(); 146 void CancelAuthCode();
157 147
158 bool IsArcManaged() const; 148 bool IsArcManaged() const;
159 bool IsArcEnabled() const; 149 bool IsArcEnabled() const;
160 void EnableArc(); 150 void EnableArc();
161 void DisableArc(); 151 void DisableArc();
162 152
163 // UbertokenConsumer:
164 void OnUbertokenSuccess(const std::string& token) override;
165 void OnUbertokenFailure(const GoogleServiceAuthError& error) override;
166
167 // GaiaAuthConsumer:
168 void OnMergeSessionSuccess(const std::string& data) override;
169 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
170
171 // syncable_prefs::PrefServiceSyncableObserver 153 // syncable_prefs::PrefServiceSyncableObserver
172 void OnIsSyncingChanged() override; 154 void OnIsSyncingChanged() override;
173 155
174 // syncable_prefs::SyncedPrefObserver 156 // syncable_prefs::SyncedPrefObserver
175 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override; 157 void OnSyncedPrefChanged(const std::string& path, bool from_sync) override;
176 158
159 // ArcAuthContextDelegate:
160 void OnContextReady() override;
161 void OnPrepareContextFailed() override;
162
177 // ArcAndroidManagementCheckerDelegate: 163 // ArcAndroidManagementCheckerDelegate:
178 void OnAndroidManagementChecked( 164 void OnAndroidManagementChecked(
179 policy::AndroidManagementClient::Result result) override; 165 policy::AndroidManagementClient::Result result) override;
180 166
181 // Returns current page that has to be shown in OptIn UI. 167 // Returns current page that has to be shown in OptIn UI.
182 UIPage ui_page() const { return ui_page_; } 168 UIPage ui_page() const { return ui_page_; }
183 169
184 // Returns current page status, relevant to the specific page. 170 // Returns current page status, relevant to the specific page.
185 const base::string16& ui_page_status() { return ui_page_status_; } 171 const base::string16& ui_page_status() { return ui_page_status_; }
186 172
187 private: 173 private:
188 void StartArc(); 174 void StartArc();
189 void PrepareContext();
190 void ShowUI(UIPage page, const base::string16& status); 175 void ShowUI(UIPage page, const base::string16& status);
191 void CloseUI(); 176 void CloseUI();
192 void SetUIPage(UIPage page, const base::string16& status); 177 void SetUIPage(UIPage page, const base::string16& status);
193 void SetState(State state); 178 void SetState(State state);
194 void ShutdownBridge(); 179 void ShutdownBridge();
195 void ShutdownBridgeAndCloseUI(); 180 void ShutdownBridgeAndCloseUI();
196 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status); 181 void ShutdownBridgeAndShowUI(UIPage page, const base::string16& status);
197 void OnOptInPreferenceChanged(); 182 void OnOptInPreferenceChanged();
198 void StartUI(); 183 void StartUI();
199 void OnPrepareContextFailed();
200 void StartAndroidManagementClient(); 184 void StartAndroidManagementClient();
201 void CheckAndroidManagement(bool background_mode); 185 void CheckAndroidManagement(bool background_mode);
202 void StartArcIfSignedIn(); 186 void StartArcIfSignedIn();
203 187
204 // Unowned pointer. Keeps current profile. 188 // Unowned pointer. Keeps current profile.
205 Profile* profile_ = nullptr; 189 Profile* profile_ = nullptr;
206 // Owned by content::BrowserContent. Used to isolate cookies for auth server
207 // communication and shared with Arc OptIn UI platform app.
208 content::StoragePartition* storage_partition_ = nullptr;
209 190
210 // Registrar used to monitor ARC enabled state. 191 // Registrar used to monitor ARC enabled state.
211 PrefChangeRegistrar pref_change_registrar_; 192 PrefChangeRegistrar pref_change_registrar_;
212 193
213 mojo::Binding<AuthHost> binding_; 194 mojo::Binding<AuthHost> binding_;
214 State state_ = State::NOT_INITIALIZED; 195 State state_ = State::NOT_INITIALIZED;
215 base::ObserverList<Observer> observer_list_; 196 base::ObserverList<Observer> observer_list_;
216 std::unique_ptr<GaiaAuthFetcher> merger_fetcher_;
217 std::unique_ptr<UbertokenFetcher> ubertoken_fetcher_;
218 std::unique_ptr<ArcAppLauncher> playstore_launcher_; 197 std::unique_ptr<ArcAppLauncher> playstore_launcher_;
219 std::string auth_code_; 198 std::string auth_code_;
220 GetAuthCodeCallback auth_callback_; 199 GetAuthCodeCallback auth_callback_;
221 bool initial_opt_in_ = false; 200 bool initial_opt_in_ = false;
222 bool context_prepared_ = false;
223 bool disable_arc_from_ui_ = false; 201 bool disable_arc_from_ui_ = false;
224 UIPage ui_page_ = UIPage::NO_PAGE; 202 UIPage ui_page_ = UIPage::NO_PAGE;
225 base::string16 ui_page_status_; 203 base::string16 ui_page_status_;
226 bool clear_required_ = false; 204 bool clear_required_ = false;
227 205
228 ProfileOAuth2TokenService* token_service_; 206 std::unique_ptr<ArcAuthContext> context_;
229 std::string account_id_;
230 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_; 207 std::unique_ptr<ArcAndroidManagementChecker> android_management_checker_;
231 208
232 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_; 209 base::WeakPtrFactory<ArcAuthService> weak_ptr_factory_;
233 210
234 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); 211 DISALLOW_COPY_AND_ASSIGN(ArcAuthService);
235 }; 212 };
236 213
237 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); 214 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state);
238 215
239 } // namespace arc 216 } // namespace arc
240 217
241 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 218 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698