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

Unified Diff: components/arc/arc_session_runner.h

Issue 2586183002: Refactor ArcSessionRunner part 2. (Closed)
Patch Set: Rebase Created 4 years 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 | « components/arc/arc_service_manager.cc ('k') | components/arc/arc_session_runner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/arc/arc_session_runner.h
diff --git a/components/arc/arc_session_runner.h b/components/arc/arc_session_runner.h
index 9a459cdd8f3760bcd555cc4e03388e8af80c729a..8eeeabd14dc3f2d85d442feb662bdb9f92a9a5b1 100644
--- a/components/arc/arc_session_runner.h
+++ b/components/arc/arc_session_runner.h
@@ -14,13 +14,6 @@
#include "components/arc/arc_bridge_service.h"
#include "components/arc/arc_session_observer.h"
-template <typename T>
-class scoped_refptr;
-
-namespace base {
-class TaskRunner;
-} // namespace base
-
namespace arc {
class ArcSession;
@@ -28,23 +21,36 @@ class ArcSession;
// Accept requests to start/stop ARC instance. Also supports automatic
// restarting on unexpected ARC instance crash.
// TODO(hidehiko): Get rid of ArcBridgeService inheritance.
-class ArcSessionRunner : public ArcBridgeService, public ArcSessionObserver {
+class ArcSessionRunner : public ArcSessionObserver {
public:
// This is the factory interface to inject ArcSession instance
// for testing purpose.
using ArcSessionFactory = base::Callback<std::unique_ptr<ArcSession>()>;
- explicit ArcSessionRunner(scoped_refptr<base::TaskRunner> task_runner);
-
- // For testing.
- // TODO(hidehiko): Migrate this and above constructors.
explicit ArcSessionRunner(const ArcSessionFactory& factory);
~ArcSessionRunner() override;
- // ArcBridgeService overrides:
- void RequestStart() override;
- void RequestStop() override;
- void OnShutdown() override;
+ // Add/Remove an observer.
+ void AddObserver(ArcSessionObserver* observer);
+ void RemoveObserver(ArcSessionObserver* observer);
+
+ // Starts the ARC service, then it will connect the Mojo channel. When the
+ // bridge becomes ready, registered Observer's OnSessionReady() is called.
+ void RequestStart();
+
+ // Stops the ARC service.
+ void RequestStop();
+
+ // OnShutdown() should be called when the browser is shutting down. This can
+ // only be called on the thread that this class was created on. We assume that
+ // when this function is called, MessageLoop is no longer exists.
+ void OnShutdown();
+
+ // Returns whether currently ARC instance is running or stopped respectively.
+ // Note that, both can return false at same time when, e.g., starting
+ // or stopping ARC instance.
+ bool IsRunning() const;
+ bool IsStopped() const;
// Returns the current ArcSession instance for testing purpose.
ArcSession* GetArcSessionForTesting() { return arc_session_.get(); }
@@ -55,6 +61,39 @@ class ArcSessionRunner : public ArcBridgeService, public ArcSessionObserver {
void SetRestartDelayForTesting(const base::TimeDelta& restart_delay);
private:
+ // The possible states. In the normal flow, the state changes in the
+ // following sequence:
+ //
+ // STOPPED
+ // RequestStart() ->
+ // STARTING
+ // OnSessionReady() ->
+ // READY
+ //
+ // The ArcSession state machine can be thought of being substates of
+ // ArcBridgeService's STARTING state.
+ // ArcBridgeService's state machine can be stopped at any phase.
+ //
+ // *
+ // RequestStop() ->
+ // STOPPING
+ // OnSessionStopped() ->
+ // STOPPED
+ enum class State {
+ // ARC instance is not currently running.
+ STOPPED,
+
+ // Request to start ARC instance is received. Starting an ARC instance.
+ STARTING,
+
+ // ARC instance has finished initializing, and is now ready for interaction
+ // with other services.
+ RUNNING,
+
+ // Request to stop ARC instance is recieved. Stopping the ARC instance.
+ STOPPING,
+ };
+
// Starts to run an ARC instance.
void StartArcSession();
@@ -62,6 +101,11 @@ class ArcSessionRunner : public ArcBridgeService, public ArcSessionObserver {
void OnSessionReady() override;
void OnSessionStopped(StopReason reason) override;
+ base::ThreadChecker thread_checker_;
+
+ // Observers for the ARC instance state change events.
+ base::ObserverList<ArcSessionObserver> observer_list_;
+
// Whether a client requests to run session or not.
bool run_requested_ = false;
@@ -73,6 +117,9 @@ class ArcSessionRunner : public ArcBridgeService, public ArcSessionObserver {
// Factory to inject a fake ArcSession instance for testing.
ArcSessionFactory factory_;
+ // Current runner's state.
+ State state_ = State::STOPPED;
+
// ArcSession object for currently running ARC instance. This should be
// nullptr if the state is STOPPED, otherwise non-nullptr.
std::unique_ptr<ArcSession> arc_session_;
« no previous file with comments | « components/arc/arc_service_manager.cc ('k') | components/arc/arc_session_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698