Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Unified Diff: chrome/browser/chromeos/arc/arc_auth_service.h

Issue 1618193003: arc: Pass auth token from Chrome to ARC instance. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update BUILD.gn Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/arc_auth_service.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..6ed0d23a8705d0c834323cce691e873bacd9e260 100644
--- a/chrome/browser/chromeos/arc/arc_auth_service.h
+++ b/chrome/browser/chromeos/arc/arc_auth_service.h
@@ -5,35 +5,105 @@
#ifndef CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
#define CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
+#include <ostream>
+
#include "base/macros.h"
+#include "base/observer_list.h"
+#include "base/threading/thread_checker.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/auth/arc_auth_fetcher.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() = default;
+
+ // 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:
- // Overrides ArcBridgeService::Observer.
+ 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);
+
+ std::string GetAndResetAutoCode();
+
+ // Adds or removes observers.
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ // 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;
+ // ArcAuthFetcher::Delegate:
+ void OnAuthCodeFetched(const std::string& auth_code) override;
+ void OnAuthCodeNeedUI() override;
+ void OnAuthCodeFailed() override;
+
+ // 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);
};
+std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state);
+
} // namespace arc
#endif // CHROME_BROWSER_CHROMEOS_ARC_ARC_AUTH_SERVICE_H_
« no previous file with comments | « no previous file | chrome/browser/chromeos/arc/arc_auth_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698