Chromium Code Reviews| 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" | |
| 9 #include "components/arc/arc_bridge_service.h" | 11 #include "components/arc/arc_bridge_service.h" |
| 10 #include "components/arc/arc_service.h" | 12 #include "components/arc/arc_service.h" |
| 11 #include "components/arc/common/auth.mojom.h" | 13 #include "components/arc/common/auth.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 14 #include "mojo/public/cpp/bindings/binding.h" |
| 15 #include "net/url_request/url_fetcher_delegate.h" | |
| 16 | |
| 17 class GURL; | |
| 18 class Profile; | |
| 19 | |
| 20 namespace net { | |
| 21 class URLFetcher; | |
| 22 } // namespace net | |
| 13 | 23 |
| 14 namespace arc { | 24 namespace arc { |
| 15 | 25 |
| 16 // This class proxies the request from the client to fetch an auth code from | 26 // This class proxies the request from the client to fetch an auth code from |
| 17 // LSO. | 27 // LSO. |
| 18 class ArcAuthService : public ArcService, | 28 class ArcAuthService : public ArcService, |
| 19 public AuthHost, | 29 public AuthHost, |
| 20 public ArcBridgeService::Observer { | 30 public ArcBridgeService::Observer, |
| 31 public net::URLFetcherDelegate { | |
| 21 public: | 32 public: |
| 33 enum class State { | |
| 34 DISABLE, // ARC is not allowed to run (default). | |
| 35 FETCHING_TOKEN, // ARC is allowed, receiving auth_2 token. | |
| 36 NO_TOKEN, // ARC is allowed, auth_2 token was not received. | |
| 37 ENABLE, // ARC is allowed, auth_2 token was received. | |
| 38 }; | |
| 39 | |
| 40 class Observer { | |
| 41 public: | |
| 42 // Called whenever Opt-In state of the ARC has been changed. | |
| 43 virtual void OnOptInChanged(State state) = 0; | |
| 44 }; | |
| 45 | |
| 22 explicit ArcAuthService(ArcBridgeService* bridge_service); | 46 explicit ArcAuthService(ArcBridgeService* bridge_service); |
| 23 ~ArcAuthService() override; | 47 ~ArcAuthService() override; |
| 24 | 48 |
| 25 private: | 49 static ArcAuthService* Get(); |
| 50 | |
| 51 void SetProfile(Profile* profile); | |
| 52 State state() const { return state_; } | |
| 53 | |
| 54 // Sets the auth token. Can be set from internally or from external component | |
| 55 // that accepts user's credentials. This actually starts ARC bridge service. | |
| 56 void SetAuthTokenAndStartArc(const std::string auth_token); | |
| 57 | |
| 58 std::string GetAuthToken(); | |
| 59 | |
| 60 // Adds or removes observers. | |
| 61 void AddObserver(Observer* observer); | |
| 62 void RemoveObserver(Observer* observer); | |
| 63 | |
| 64 // net::URLFetcherDelegate overrides. | |
| 65 void OnURLFetchComplete(const net::URLFetcher* source) override; | |
| 66 | |
| 67 // Helper function to compose target URL, also is used in test. | |
| 68 static GURL CreateURL(Profile* profile); | |
| 69 | |
| 26 // Overrides ArcBridgeService::Observer. | 70 // Overrides ArcBridgeService::Observer. |
| 27 void OnAuthInstanceReady() override; | 71 void OnAuthInstanceReady() override; |
| 28 | 72 |
| 29 // Overrides AuthHost. | 73 // Overrides AuthHost. For security reason this token can be used only |
|
elijahtaylor1
2016/01/26 01:02:14
I'm confused by the token/code terminology. IIUC
| |
| 74 // once and exists for specific period of time. | |
| 30 void GetAuthCode(const GetAuthCodeCallback& callback) override; | 75 void GetAuthCode(const GetAuthCodeCallback& callback) override; |
| 31 | 76 |
| 77 private: | |
| 78 void FetchToken(); | |
| 79 // Finds auth token in cookies. | |
| 80 static bool ParseAuthToken(const net::URLFetcher* source, std::string* token); | |
| 81 | |
| 82 // Unowned pointer. Keeps current profile. | |
| 83 Profile* profile_ = nullptr; | |
| 84 | |
| 32 mojo::Binding<AuthHost> binding_; | 85 mojo::Binding<AuthHost> binding_; |
| 86 base::ThreadChecker thread_checker_; | |
| 87 State state_ = State::DISABLE; | |
| 88 base::ObserverList<Observer> observer_list_; | |
| 89 scoped_ptr<net::URLFetcher> auth_fetcher_; | |
| 90 std::string auth_token_; | |
| 33 | 91 |
| 34 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); | 92 DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
| 35 }; | 93 }; |
| 36 | 94 |
| 37 } // namespace arc | 95 } // namespace arc |
| 38 | 96 |
| 39 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ | 97 #endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
| OLD | NEW |