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 "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/observer_list.h" | |
10 #include "base/threading/thread_checker.h" | |
11 #include "chrome/browser/chromeos/arc/arc_auth_fetcher.h" | |
12 #include "chrome/browser/chromeos/arc/arc_auth_ui.h" | |
9 #include "components/arc/arc_bridge_service.h" | 13 #include "components/arc/arc_bridge_service.h" |
10 #include "components/arc/arc_service.h" | 14 #include "components/arc/arc_service.h" |
11 #include "components/arc/common/auth.mojom.h" | 15 #include "components/arc/common/auth.mojom.h" |
12 #include "mojo/public/cpp/bindings/binding.h" | 16 #include "mojo/public/cpp/bindings/binding.h" |
13 | 17 |
18 class Profile; | |
19 | |
14 namespace arc { | 20 namespace arc { |
15 | 21 |
16 // This class proxies the request from the client to fetch an auth code from | 22 // This class proxies the request from the client to fetch an auth code from |
17 // LSO. | 23 // LSO. |
18 class ArcAuthService : public ArcService, | 24 class ArcAuthService : public ArcService, |
19 public AuthHost, | 25 public AuthHost, |
20 public ArcBridgeService::Observer { | 26 public ArcBridgeService::Observer, |
27 public ArcAuthFetcher::Delegate, | |
28 public ArcAuthUI::Delegate { | |
21 public: | 29 public: |
30 enum class State { | |
31 DISABLE, // ARC is not allowed to run (default). | |
32 FETCHING_CODE, // ARC is allowed, receiving auth_2 code. | |
33 NO_CODE, // ARC is allowed, auth_2 code was not received. | |
34 ENABLE, // ARC is allowed, auth_2 code was received. | |
35 }; | |
36 | |
37 class Observer { | |
38 public: | |
39 virtual ~Observer() {} | |
40 | |
41 // Called whenever Opt-In state of the ARC has been changed. | |
42 virtual void OnOptInChanged(State state) = 0; | |
43 }; | |
44 | |
22 explicit ArcAuthService(ArcBridgeService* bridge_service); | 45 explicit ArcAuthService(ArcBridgeService* bridge_service); |
23 ~ArcAuthService() override; | 46 ~ArcAuthService() override; |
24 | 47 |
25 private: | 48 static ArcAuthService* Get(); |
49 | |
50 static void DisableUIForTesting(); | |
51 | |
52 void OnPrimaryUserProfilePrepared(Profile* profile); | |
53 void Shutdown(); | |
54 | |
55 State state() const { return state_; } | |
56 | |
57 // Sets the auth code. Can be set from internally or from external component | |
58 // that accepts user's credentials. This actually starts ARC bridge service. | |
59 void SetAuthCodeAndStartArc(const std::string auth_code); | |
oshima
2016/01/28 17:46:41
std::string&
khmel
2016/01/28 19:24:02
Done.
| |
60 | |
61 std::string GetAuthCode(); | |
62 | |
63 // Adds or removes observers. | |
64 void AddObserver(Observer* observer); | |
65 void RemoveObserver(Observer* observer); | |
66 | |
26 // Overrides ArcBridgeService::Observer. | 67 // Overrides ArcBridgeService::Observer. |
27 void OnAuthInstanceReady() override; | 68 void OnAuthInstanceReady() override; |
28 | 69 |
29 // Overrides AuthHost. | 70 // Overrides AuthHost. For security reason this code can be used only |
71 // once and exists for specific period of time. | |
30 void GetAuthCode(const GetAuthCodeCallback& callback) override; | 72 void GetAuthCode(const GetAuthCodeCallback& callback) override; |
31 | 73 |
74 // Overrides ArcAuthFetcher::Delegate. | |
75 void OnAuthCodeFetched(const std::string& auth_code) override; | |
76 void OnAuthCodeNeedUI() override; | |
77 void OnAuthCodeFailed() override; | |
78 | |
79 // Overrides ArcAuthUI::Delegate. | |
80 void OnAuthUIClosed() override; | |
81 | |
82 private: | |
83 void FetchAuthCode(); | |
84 void CloseUI(); | |
85 void SetState(State state); | |
86 | |
87 // Unowned pointer. Keeps current profile. | |
88 Profile* profile_ = nullptr; | |
89 | |
90 // Owned by view hierarchy. | |
91 ArcAuthUI* auth_ui_ = nullptr; | |
92 | |
32 mojo::Binding<AuthHost> binding_; | 93 mojo::Binding<AuthHost> binding_; |
94 base::ThreadChecker thread_checker_; | |
95 State state_ = State::DISABLE; | |
96 base::ObserverList<Observer> observer_list_; | |
97 scoped_ptr<ArcAuthFetcher> auth_fetcher_; | |
98 std::string auth_code_; | |
33 | 99 |
34 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 100 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
35 }; | 101 }; |
36 | 102 |
37 } // namespace arc | 103 } // namespace arc |
38 | 104 |
39 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 105 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
OLD | NEW |