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

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

Issue 1681813003: arc: Use incognito profile for OptIn and cookie fetcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 4 years, 10 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 <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 "chrome/browser/chromeos/arc/arc_auth_ui.h"
14 #include "components/arc/arc_bridge_service.h" 13 #include "components/arc/arc_bridge_service.h"
15 #include "components/arc/arc_service.h" 14 #include "components/arc/arc_service.h"
16 #include "components/arc/auth/arc_auth_fetcher.h" 15 #include "components/arc/auth/arc_auth_fetcher.h"
17 #include "components/arc/common/auth.mojom.h" 16 #include "components/arc/common/auth.mojom.h"
18 #include "components/prefs/pref_change_registrar.h" 17 #include "components/prefs/pref_change_registrar.h"
18 #include "google_apis/gaia/gaia_auth_consumer.h"
19 #include "google_apis/gaia/ubertoken_fetcher.h"
19 #include "mojo/public/cpp/bindings/binding.h" 20 #include "mojo/public/cpp/bindings/binding.h"
20 21
22 class GaiaAuthFetcher;
21 class PrefService; 23 class PrefService;
xiyuan 2016/02/11 17:57:20 nit: not used?
khmel 2016/02/12 02:45:23 Done.
22 class Profile; 24 class Profile;
23 25
26 namespace content {
27 class StoragePartition;
28 }
29
30 namespace net {
31 class URLRequestContextGetter;
32 }
33
24 namespace user_prefs { 34 namespace user_prefs {
25 class PrefRegistrySyncable; 35 class PrefRegistrySyncable;
26 } 36 }
27 37
28 namespace arc { 38 namespace arc {
29 39
30 // 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
31 // LSO. 41 // LSO.
32 class ArcAuthService : public ArcService, 42 class ArcAuthService : public ArcService,
33 public AuthHost, 43 public AuthHost,
34 public ArcBridgeService::Observer, 44 public ArcBridgeService::Observer,
35 public ArcAuthFetcher::Delegate, 45 public ArcAuthFetcher::Delegate,
36 public ArcAuthUI::Delegate { 46 public UbertokenConsumer,
47 public GaiaAuthConsumer {
37 public: 48 public:
38 enum class State { 49 enum class State {
39 DISABLE, // ARC is not allowed to run (default). 50 DISABLE, // ARC is not allowed to run (default).
40 FETCHING_CODE, // ARC is allowed, receiving auth_2 code. 51 FETCHING_CODE, // ARC is allowed, receiving auth_2 code.
41 NO_CODE, // ARC is allowed, auth_2 code was not received. 52 NO_CODE, // ARC is allowed, auth_2 code was not received.
42 ENABLE, // ARC is allowed, auth_2 code was received. 53 ENABLE, // ARC is allowed, auth_2 code was received.
43 }; 54 };
44 55
45 class Observer { 56 class Observer {
46 public: 57 public:
47 virtual ~Observer() = default; 58 virtual ~Observer() = default;
48 59
49 // Called whenever Opt-In state of the ARC has been changed. 60 // Called whenever Opt-In state of the ARC has been changed.
50 virtual void OnOptInChanged(State state) = 0; 61 virtual void OnOptInChanged(State state) {}
62
63 // Called to notify that OptIn UI needs to be closed.
64 virtual void OnOptInUINeedToClose() {}
51 }; 65 };
52 66
53 explicit ArcAuthService(ArcBridgeService* bridge_service); 67 explicit ArcAuthService(ArcBridgeService* bridge_service);
54 ~ArcAuthService() override; 68 ~ArcAuthService() override;
55 69
56 static ArcAuthService* Get(); 70 static ArcAuthService* Get();
57 71
58 // It is called from chrome/browser/prefs/browser_prefs.cc. 72 // It is called from chrome/browser/prefs/browser_prefs.cc.
59 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 73 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
60 74
61 static void DisableUIForTesting(); 75 static void DisableUIForTesting();
62 76
63 // Checks if OptIn verification was disabled by switch in command line. 77 // Checks if OptIn verification was disabled by switch in command line.
64 static bool IsOptInVerificationDisabled(); 78 static bool IsOptInVerificationDisabled();
65 79
66 void OnPrimaryUserProfilePrepared(Profile* profile); 80 void OnPrimaryUserProfilePrepared(Profile* profile);
67 void Shutdown(); 81 void Shutdown();
68 82
69 State state() const { return state_; } 83 State state() const { return state_; }
70 84
71 // Sets the auth code. Can be set from internally or from external component
72 // that accepts user's credentials. This actually starts ARC bridge service.
73 void SetAuthCodeAndStartArc(const std::string& auth_code);
74
75 std::string GetAndResetAuthCode(); 85 std::string GetAndResetAuthCode();
76 86
77 // Adds or removes observers. 87 // Adds or removes observers.
78 void AddObserver(Observer* observer); 88 void AddObserver(Observer* observer);
79 void RemoveObserver(Observer* observer); 89 void RemoveObserver(Observer* observer);
80 90
81 // ArcBridgeService::Observer: 91 // ArcBridgeService::Observer:
82 void OnAuthInstanceReady() override; 92 void OnAuthInstanceReady() override;
83 93
84 // Overrides AuthHost. For security reason this code can be used only 94 // Overrides AuthHost. For security reason this code can be used only
85 // once and exists for specific period of time. 95 // once and exists for specific period of time.
86 void GetAuthCodeDeprecated( 96 void GetAuthCodeDeprecated(
87 const GetAuthCodeDeprecatedCallback& callback) override; 97 const GetAuthCodeDeprecatedCallback& callback) override;
88 void GetAuthCode(const GetAuthCodeCallback& callback) override; 98 void GetAuthCode(const GetAuthCodeCallback& callback) override;
89 99
100 // Called from Arc OptIn UI to check an auth code.
101 void CheckAuthCode();
102
90 // ArcAuthFetcher::Delegate: 103 // ArcAuthFetcher::Delegate:
91 void OnAuthCodeFetched(const std::string& auth_code) override; 104 void OnAuthCodeFetched(const std::string& auth_code) override;
92 void OnAuthCodeNeedUI() override; 105 void OnAuthCodeNeedUI() override;
93 void OnAuthCodeFailed() override; 106 void OnAuthCodeFailed() override;
94 107
95 // ArcAuthUI::Delegate: 108 // UbertokenConsumer:
96 void OnAuthUIClosed() override; 109 void OnUbertokenSuccess(const std::string& token) override;
110 void OnUbertokenFailure(const GoogleServiceAuthError& error) override;
111
112 // GaiaAuthConsumer:
113 void OnMergeSessionSuccess(const std::string& data) override;
114 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
97 115
98 private: 116 private:
117 void SetAuthCodeAndStartArc(const std::string& auth_code);
99 void FetchAuthCode(); 118 void FetchAuthCode();
119 void ShowUI();
100 void CloseUI(); 120 void CloseUI();
101 void SetState(State state); 121 void SetState(State state);
102 void ShutdownBridgeAndCloseUI(); 122 void ShutdownBridgeAndCloseUI();
103 void OnOptInPreferenceChanged(); 123 void OnOptInPreferenceChanged();
104 124
105 // Unowned pointer. Keeps current profile. 125 // Unowned pointer. Keeps current profile.
106 Profile* profile_ = nullptr; 126 Profile* profile_ = nullptr;
107 127 // Owned by content::BrowserContent. Used to isolate cookies for auth server
108 // Owned by view hierarchy. 128 // communication and shared with Arc OptIn UI platform app.
109 ArcAuthUI* auth_ui_ = nullptr; 129 content::StoragePartition* storage_partition_ = nullptr;
110 130
111 // Registrar used to monitor ARC opt-in state. 131 // Registrar used to monitor ARC opt-in state.
112 PrefChangeRegistrar pref_change_registrar_; 132 PrefChangeRegistrar pref_change_registrar_;
113 133
114 mojo::Binding<AuthHost> binding_; 134 mojo::Binding<AuthHost> binding_;
115 base::ThreadChecker thread_checker_; 135 base::ThreadChecker thread_checker_;
116 State state_ = State::DISABLE; 136 State state_ = State::DISABLE;
117 base::ObserverList<Observer> observer_list_; 137 base::ObserverList<Observer> observer_list_;
118 scoped_ptr<ArcAuthFetcher> auth_fetcher_; 138 scoped_ptr<ArcAuthFetcher> auth_fetcher_;
139 scoped_ptr<GaiaAuthFetcher> merger_fetcher_;
140 scoped_ptr<UbertokenFetcher> ubertoken_fethcher_;
119 std::string auth_code_; 141 std::string auth_code_;
120 142
121 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); 143 DISALLOW_COPY_AND_ASSIGN(ArcAuthService);
122 }; 144 };
123 145
124 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); 146 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state);
125 147
126 } // namespace arc 148 } // namespace arc
127 149
128 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 150 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698