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