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. | |
xiyuan
2016/01/27 23:56:05
nit: strip one space between "receiving" and "auth
khmel
2016/01/28 05:22:08
Done.
| |
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 // Called whenever Opt-In state of the ARC has been changed. | |
40 virtual void OnOptInChanged(State state) = 0; | |
41 }; | |
xiyuan
2016/01/27 23:56:05
nit: add a virtual ~Observer() {}
khmel
2016/01/28 05:22:08
Done.
| |
42 | |
22 explicit ArcAuthService(ArcBridgeService* bridge_service); | 43 explicit ArcAuthService(ArcBridgeService* bridge_service); |
23 ~ArcAuthService() override; | 44 ~ArcAuthService() override; |
24 | 45 |
25 private: | 46 static ArcAuthService* Get(); |
47 | |
48 static void DisableUIForTesting(); | |
49 | |
50 void OnPrimaryUserProfilePrepared(Profile* profile); | |
51 void Shutdown(); | |
52 | |
53 State state() const { return state_; } | |
54 | |
55 // Sets the auth code. Can be set from internally or from external component | |
56 // that accepts user's credentials. This actually starts ARC bridge service. | |
57 void SetAuthCodeAndStartArc(const std::string auth_code); | |
58 | |
59 std::string GetAuthCode(); | |
60 | |
61 // Adds or removes observers. | |
62 void AddObserver(Observer* observer); | |
63 void RemoveObserver(Observer* observer); | |
64 | |
26 // Overrides ArcBridgeService::Observer. | 65 // Overrides ArcBridgeService::Observer. |
27 void OnAuthInstanceReady() override; | 66 void OnAuthInstanceReady() override; |
28 | 67 |
29 // Overrides AuthHost. | 68 // Overrides AuthHost. For security reason this code can be used only |
69 // once and exists for specific period of time. | |
30 void GetAuthCode(const GetAuthCodeCallback& callback) override; | 70 void GetAuthCode(const GetAuthCodeCallback& callback) override; |
31 | 71 |
72 // Overrides ArcAuthFetcher::Delegate. | |
73 void OnAuthCodeFetched(const std::string& auth_code) override; | |
74 void OnAuthCodeNeedUI() override; | |
75 void OnAuthCodeFailed() override; | |
76 | |
77 // Overrides ArcAuthUI::Delegate. | |
78 void OnAuthUIClosed() override; | |
79 | |
80 private: | |
81 void FetchAuthCode(); | |
82 void CloseUI(); | |
83 | |
84 // Unowned pointer. Keeps current profile. | |
85 Profile* profile_ = nullptr; | |
86 | |
87 // Owned by view hierarchy. | |
88 ArcAuthUI* auth_ui_ = nullptr; | |
89 | |
32 mojo::Binding<AuthHost> binding_; | 90 mojo::Binding<AuthHost> binding_; |
91 base::ThreadChecker thread_checker_; | |
92 State state_ = State::DISABLE; | |
93 base::ObserverList<Observer> observer_list_; | |
94 scoped_ptr<ArcAuthFetcher> auth_fetcher_; | |
95 std::string auth_code_; | |
33 | 96 |
34 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 97 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
35 }; | 98 }; |
36 | 99 |
37 } // namespace arc | 100 } // namespace arc |
38 | 101 |
39 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 102 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
OLD | NEW |