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

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: rebased, added reseting windowClosedInternally before window creation 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
21 class PrefService; 22 class GaiaAuthFetcher;
22 class Profile; 23 class Profile;
23 24
25 namespace content {
26 class StoragePartition;
27 }
28
29 namespace net {
30 class URLRequestContextGetter;
31 }
32
24 namespace user_prefs { 33 namespace user_prefs {
25 class PrefRegistrySyncable; 34 class PrefRegistrySyncable;
26 } 35 }
27 36
28 namespace arc { 37 namespace arc {
29 38
30 // 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
31 // LSO. 40 // LSO.
32 class ArcAuthService : public ArcService, 41 class ArcAuthService : public ArcService,
33 public AuthHost, 42 public AuthHost,
34 public ArcBridgeService::Observer, 43 public ArcBridgeService::Observer,
35 public ArcAuthFetcher::Delegate, 44 public ArcAuthFetcher::Delegate,
36 public ArcAuthUI::Delegate { 45 public UbertokenConsumer,
46 public GaiaAuthConsumer {
37 public: 47 public:
38 enum class State { 48 enum class State {
39 DISABLE, // ARC is not allowed to run (default). 49 DISABLE, // ARC is not allowed to run (default).
40 FETCHING_CODE, // ARC is allowed, receiving auth_2 code. 50 FETCHING_CODE, // ARC is allowed, receiving auth_2 code.
41 NO_CODE, // ARC is allowed, auth_2 code was not received. 51 NO_CODE, // ARC is allowed, auth_2 code was not received.
42 ENABLE, // ARC is allowed, auth_2 code was received. 52 ENABLE, // ARC is allowed, auth_2 code was received.
43 }; 53 };
44 54
45 class Observer { 55 class Observer {
46 public: 56 public:
47 virtual ~Observer() = default; 57 virtual ~Observer() = default;
48 58
49 // Called whenever Opt-In state of the ARC has been changed. 59 // Called whenever Opt-In state of the ARC has been changed.
50 virtual void OnOptInChanged(State state) = 0; 60 virtual void OnOptInChanged(State state) {}
61
62 // Called to notify that OptIn UI needs to be closed.
63 virtual void OnOptInUINeedToClose() {}
51 }; 64 };
52 65
53 explicit ArcAuthService(ArcBridgeService* bridge_service); 66 explicit ArcAuthService(ArcBridgeService* bridge_service);
54 ~ArcAuthService() override; 67 ~ArcAuthService() override;
55 68
56 static ArcAuthService* Get(); 69 static ArcAuthService* Get();
57 70
58 // It is called from chrome/browser/prefs/browser_prefs.cc. 71 // It is called from chrome/browser/prefs/browser_prefs.cc.
59 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 72 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
60 73
61 static void DisableUIForTesting(); 74 static void DisableUIForTesting();
62 75
63 // Checks if OptIn verification was disabled by switch in command line. 76 // Checks if OptIn verification was disabled by switch in command line.
64 static bool IsOptInVerificationDisabled(); 77 static bool IsOptInVerificationDisabled();
65 78
66 void OnPrimaryUserProfilePrepared(Profile* profile); 79 void OnPrimaryUserProfilePrepared(Profile* profile);
67 void Shutdown(); 80 void Shutdown();
68 81
69 State state() const { return state_; } 82 State state() const { return state_; }
70 83
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(); 84 std::string GetAndResetAuthCode();
76 85
77 // Adds or removes observers. 86 // Adds or removes observers.
78 void AddObserver(Observer* observer); 87 void AddObserver(Observer* observer);
79 void RemoveObserver(Observer* observer); 88 void RemoveObserver(Observer* observer);
80 89
81 // ArcBridgeService::Observer: 90 // ArcBridgeService::Observer:
82 void OnAuthInstanceReady() override; 91 void OnAuthInstanceReady() override;
83 92
84 // Overrides AuthHost. For security reason this code can be used only 93 // Overrides AuthHost. For security reason this code can be used only
85 // once and exists for specific period of time. 94 // once and exists for specific period of time.
86 void GetAuthCodeDeprecated( 95 void GetAuthCodeDeprecated(
87 const GetAuthCodeDeprecatedCallback& callback) override; 96 const GetAuthCodeDeprecatedCallback& callback) override;
88 void GetAuthCode(const GetAuthCodeCallback& callback) override; 97 void GetAuthCode(const GetAuthCodeCallback& callback) override;
89 98
99 // May be called internally as response to on Arc OptIn preference change
100 // or externally from Arc support platform app.
101 void FetchAuthCode();
102
103 // Called from Arc support platform app when user cancels signing.
104 void CancelAuthCode();
105
90 // ArcAuthFetcher::Delegate: 106 // ArcAuthFetcher::Delegate:
91 void OnAuthCodeFetched(const std::string& auth_code) override; 107 void OnAuthCodeFetched(const std::string& auth_code) override;
92 void OnAuthCodeNeedUI() override; 108 void OnAuthCodeNeedUI() override;
93 void OnAuthCodeFailed() override; 109 void OnAuthCodeFailed() override;
94 110
95 // ArcAuthUI::Delegate: 111 // UbertokenConsumer:
96 void OnAuthUIClosed() override; 112 void OnUbertokenSuccess(const std::string& token) override;
113 void OnUbertokenFailure(const GoogleServiceAuthError& error) override;
114
115 // GaiaAuthConsumer:
116 void OnMergeSessionSuccess(const std::string& data) override;
117 void OnMergeSessionFailure(const GoogleServiceAuthError& error) override;
97 118
98 private: 119 private:
99 void FetchAuthCode(); 120 void SetAuthCodeAndStartArc(const std::string& auth_code);
121 void ShowUI();
100 void CloseUI(); 122 void CloseUI();
101 void SetState(State state); 123 void SetState(State state);
102 void ShutdownBridgeAndCloseUI(); 124 void ShutdownBridgeAndCloseUI();
103 void OnOptInPreferenceChanged(); 125 void OnOptInPreferenceChanged();
104 126
105 // Unowned pointer. Keeps current profile. 127 // Unowned pointer. Keeps current profile.
106 Profile* profile_ = nullptr; 128 Profile* profile_ = nullptr;
107 129 // Owned by content::BrowserContent. Used to isolate cookies for auth server
108 // Owned by view hierarchy. 130 // communication and shared with Arc OptIn UI platform app.
109 ArcAuthUI* auth_ui_ = nullptr; 131 content::StoragePartition* storage_partition_ = nullptr;
110 132
111 // Registrar used to monitor ARC opt-in state. 133 // Registrar used to monitor ARC opt-in state.
112 PrefChangeRegistrar pref_change_registrar_; 134 PrefChangeRegistrar pref_change_registrar_;
113 135
114 mojo::Binding<AuthHost> binding_; 136 mojo::Binding<AuthHost> binding_;
115 base::ThreadChecker thread_checker_; 137 base::ThreadChecker thread_checker_;
116 State state_ = State::DISABLE; 138 State state_ = State::DISABLE;
117 base::ObserverList<Observer> observer_list_; 139 base::ObserverList<Observer> observer_list_;
118 scoped_ptr<ArcAuthFetcher> auth_fetcher_; 140 scoped_ptr<ArcAuthFetcher> auth_fetcher_;
141 scoped_ptr<GaiaAuthFetcher> merger_fetcher_;
142 scoped_ptr<UbertokenFetcher> ubertoken_fethcher_;
Luis Héctor Chávez 2016/04/06 20:23:06 |ubertoken_fetcher_|.
119 std::string auth_code_; 143 std::string auth_code_;
120 144
121 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); 145 DISALLOW_COPY_AND_ASSIGN(ArcAuthService);
122 }; 146 };
123 147
124 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state); 148 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state);
125 149
126 } // namespace arc 150 } // namespace arc
127 151
128 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ 152 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698