Index: chrome/browser/chromeos/arc/arc_auth_service.h |
diff --git a/chrome/browser/chromeos/arc/arc_auth_service.h b/chrome/browser/chromeos/arc/arc_auth_service.h |
index d14d2b1a60d867ff858923466c29a0c62fad1b2a..c89625472c3cd30c4fab6101af3da03396bd03fd 100644 |
--- a/chrome/browser/chromeos/arc/arc_auth_service.h |
+++ b/chrome/browser/chromeos/arc/arc_auth_service.h |
@@ -6,30 +6,96 @@ |
#define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_ |
#include "base/macros.h" |
+#include "base/observer_list.h" |
+#include "base/threading/thread_checker.h" |
+#include "chrome/browser/chromeos/arc/arc_auth_fetcher.h" |
+#include "chrome/browser/chromeos/arc/arc_auth_ui.h" |
#include "components/arc/arc_bridge_service.h" |
#include "components/arc/arc_service.h" |
#include "components/arc/common/auth.mojom.h" |
#include "mojo/public/cpp/bindings/binding.h" |
+class Profile; |
+ |
namespace arc { |
// This class proxies the request from the client to fetch an auth code from |
// LSO. |
class ArcAuthService : public ArcService, |
public AuthHost, |
- public ArcBridgeService::Observer { |
+ public ArcBridgeService::Observer, |
+ public ArcAuthFetcher::Delegate, |
+ public ArcAuthUI::Delegate { |
public: |
+ enum class State { |
+ DISABLE, // ARC is not allowed to run (default). |
+ FETCHING_CODE, // ARC is allowed, receiving auth_2 code. |
+ NO_CODE, // ARC is allowed, auth_2 code was not received. |
+ ENABLE, // ARC is allowed, auth_2 code was received. |
+ }; |
+ |
+ class Observer { |
+ public: |
+ virtual ~Observer() {} |
+ |
+ // Called whenever Opt-In state of the ARC has been changed. |
+ virtual void OnOptInChanged(State state) = 0; |
+ }; |
+ |
explicit ArcAuthService(ArcBridgeService* bridge_service); |
~ArcAuthService() override; |
- private: |
+ static ArcAuthService* Get(); |
+ |
+ static void DisableUIForTesting(); |
+ |
+ void OnPrimaryUserProfilePrepared(Profile* profile); |
+ void Shutdown(); |
+ |
+ State state() const { return state_; } |
+ |
+ // Sets the auth code. Can be set from internally or from external component |
+ // that accepts user's credentials. This actually starts ARC bridge service. |
+ void SetAuthCodeAndStartArc(const std::string auth_code); |
oshima
2016/01/28 17:46:41
std::string&
khmel
2016/01/28 19:24:02
Done.
|
+ |
+ std::string GetAuthCode(); |
+ |
+ // Adds or removes observers. |
+ void AddObserver(Observer* observer); |
+ void RemoveObserver(Observer* observer); |
+ |
// Overrides ArcBridgeService::Observer. |
void OnAuthInstanceReady() override; |
- // Overrides AuthHost. |
+ // Overrides AuthHost. For security reason this code can be used only |
+ // once and exists for specific period of time. |
void GetAuthCode(const GetAuthCodeCallback& callback) override; |
+ // Overrides ArcAuthFetcher::Delegate. |
+ void OnAuthCodeFetched(const std::string& auth_code) override; |
+ void OnAuthCodeNeedUI() override; |
+ void OnAuthCodeFailed() override; |
+ |
+ // Overrides ArcAuthUI::Delegate. |
+ void OnAuthUIClosed() override; |
+ |
+ private: |
+ void FetchAuthCode(); |
+ void CloseUI(); |
+ void SetState(State state); |
+ |
+ // Unowned pointer. Keeps current profile. |
+ Profile* profile_ = nullptr; |
+ |
+ // Owned by view hierarchy. |
+ ArcAuthUI* auth_ui_ = nullptr; |
+ |
mojo::Binding<AuthHost> binding_; |
+ base::ThreadChecker thread_checker_; |
+ State state_ = State::DISABLE; |
+ base::ObserverList<Observer> observer_list_; |
+ scoped_ptr<ArcAuthFetcher> auth_fetcher_; |
+ std::string auth_code_; |
DISALLOW_COPY_AND_ASSIGN(ArcAuthService); |
}; |