Chromium Code Reviews| Index: components/arc/arc_bridge_service.h |
| diff --git a/components/arc/arc_bridge_service.h b/components/arc/arc_bridge_service.h |
| index e3417bc985756c0db52044b339df84c9da3d350b..494a4402844a86ca02184abd8bd5e443babd1a64 100644 |
| --- a/components/arc/arc_bridge_service.h |
| +++ b/components/arc/arc_bridge_service.h |
| @@ -17,7 +17,7 @@ namespace arc { |
| // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| // This service handles the lifetime of ARC instances and sets up the |
| // communication channel (the ARC bridge) used to send and receive messages. |
| -class ArcBridgeService : public IPC::Listener { |
| +class ArcBridgeService { |
| public: |
| // The possible states of the bridge. In the normal flow, the state changes |
| // in the following sequence: |
| @@ -67,33 +67,28 @@ class ArcBridgeService : public IPC::Listener { |
| // Called whenever ARC's availability has changed for this system. |
| virtual void OnAvailableChanged(bool available) {} |
| + // Called whenever ARC sends information about available apps. |
| + virtual void OnAppsRefreshed(const std::vector<std::string>& name, |
| + const std::vector<std::string>& packages, |
| + const std::vector<std::string>& activities) {} |
| + |
| + // Called whenever ARC sends app icon data for specific scale factor. |
| + virtual void OnAppIcon(const std::string& package, |
| + const std::string& activity, |
| + int scale_factor, |
| + const std::vector<uint8_t>& icon_png_data) {} |
| + |
| protected: |
| virtual ~Observer() {} |
| }; |
| - ArcBridgeService( |
| - const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| - const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
| - ~ArcBridgeService() override; |
| + ArcBridgeService(); |
| + virtual ~ArcBridgeService(); |
| // Gets the global instance of the ARC Bridge Service. This can only be |
| // called on the thread that this class was created on. |
| static ArcBridgeService* Get(); |
| - // DetectAvailability() should be called once D-Bus is available. It will |
| - // call CheckArcAvailability() on the session_manager. This can only be |
| - // called on the thread that this class was created on. |
| - void DetectAvailability(); |
| - |
| - // HandleStartup() should be called upon profile startup. This will only |
| - // launch an instance if the instance service is available and it is enabled. |
| - // This can only be called on the thread that this class was created on. |
| - void HandleStartup(); |
| - |
| - // Shutdown() should be called when the browser is shutting down. This can |
| - // only be called on the thread that this class was created on. |
| - void Shutdown(); |
| - |
| // Adds or removes observers. This can only be called on the thread that this |
| // class was created on. |
| void AddObserver(Observer* observer); |
| @@ -105,15 +100,89 @@ class ArcBridgeService : public IPC::Listener { |
| // Gets if ARC is available in this system. |
| bool available() const { return available_; } |
| + // HandleStartup() should be called upon profile startup. This will only |
| + // launch an instance if the instance service is available and it is enabled. |
| + // This can only be called on the thread that this class was created on. |
| + virtual void HandleStartup() = 0; |
| + |
| + // Shutdown() should be called when the browser is shutting down. This can |
| + // only be called on the thread that this class was created on. |
| + virtual void Shutdown() = 0; |
| + |
| + |
| // Requests registration of an input device on the ARC instance. |
| // TODO(denniskempin): Make this interface more typesafe. |
| // |name| should be the displayable name of the emulated device (e.g. "Chrome |
| // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") |
| // and |fd| a file descriptor that emulates the kernel events of the device. |
| // This can only be called on the thread that this class was created on. |
| + virtual bool RegisterInputDevice(const std::string& name, |
| + const std::string& device_type, |
| + base::ScopedFD fd) = 0; |
| + |
| + // Requests to refresh an app list. |
| + virtual bool RefreshApps() = 0; |
| + |
| + // Requests to launch an app. |
| + virtual bool LaunchApp(const std::string& package, |
| + const std::string& activity) = 0; |
| + |
| + // Request to load icon of specific scale_factor. |
| + virtual bool RequestIcon(const std::string& package, |
| + const std::string& activity, |
| + int scale_factor) = 0; |
| + |
| + protected: |
| + // Changes the current state and notifies all observers. |
| + void SetState(State state); |
| + |
| + // Changes the current availability and notifies all observers. |
| + void SetAvailable(bool availability); |
| + |
| + scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
| + |
| + base::ObserverList<Observer> observer_list_; |
| + |
| + // If the ARC instance service is available. |
| + bool available_; |
| + |
| + // The current state of the bridge. |
| + ArcBridgeService::State state_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| +}; |
| + |
| +class ArcBridgeServiceImpl : public ArcBridgeService, public IPC::Listener { |
|
xiyuan
2015/11/18 03:42:16
Move this into its own file, arc_bridge_service_im
khmel1
2015/11/18 06:10:05
Done.
|
| + public: |
| + |
| + ArcBridgeServiceImpl( |
| + const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| + const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
| + ~ArcBridgeServiceImpl() override; |
| + |
| + // DetectAvailability() should be called once D-Bus is available. It will |
| + // call CheckArcAvailability() on the session_manager. This can only be |
| + // called on the thread that this class was created on. |
| + void DetectAvailability(); |
| + |
| + void HandleStartup() override; |
| + |
| + void Shutdown() override; |
| + |
| bool RegisterInputDevice(const std::string& name, |
| const std::string& device_type, |
| - base::ScopedFD fd); |
| + base::ScopedFD fd) override; |
| + // Requests to refresh an app list. |
| + bool RefreshApps() override; |
| + |
| + // Requests to launch an app. |
| + bool LaunchApp(const std::string& package, |
| + const std::string& activity) override; |
| + |
| + // Request to load icon of specific scale_factor. |
| + bool RequestIcon(const std::string& package, |
| + const std::string& activity, |
| + int scale_factor) override; |
| private: |
| friend class ArcBridgeTest; |
| @@ -148,8 +217,16 @@ class ArcBridgeService : public IPC::Listener { |
| // interaction. |
| void OnInstanceReady(); |
| - // Changes the current state and notifies all observers. |
| - void SetState(State state); |
| + // Called whenever ARC sends information about available apps. |
| + void OnAppsRefreshed(const std::vector<std::string>& name, |
| + const std::vector<std::string>& packages, |
| + const std::vector<std::string>& activities); |
| + |
| + // Called whenever ARC sends app icon data for specific scale factor. |
| + void OnAppIcon(const std::string& package, |
| + const std::string& activity, |
| + int scale_factor, |
| + const std::vector<uint8_t>& icon_png_data); |
| // IPC::Listener: |
| bool OnMessageReceived(const IPC::Message& message) override; |
| @@ -159,27 +236,18 @@ class ArcBridgeService : public IPC::Listener { |
| void OnInstanceStarted(bool success); |
| void OnInstanceStopped(bool success); |
| - scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
| scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
| scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| scoped_ptr<IPC::ChannelProxy> ipc_channel_; |
| - base::ObserverList<Observer> observer_list_; |
| - |
| // If the user's session has started. |
| bool session_started_; |
| - // If the ARC instance service is available. |
| - bool available_; |
| - |
| - // The current state of the bridge. |
| - ArcBridgeService::State state_; |
| - |
| // WeakPtrFactory to use callbacks. |
| - base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
| + base::WeakPtrFactory<ArcBridgeServiceImpl> weak_factory_; |
| - DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| + DISALLOW_COPY_AND_ASSIGN(ArcBridgeServiceImpl); |
| }; |
| } // namespace arc |