Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| 7 | 7 |
| 8 #include "base/files/scoped_file.h" | |
| 8 #include "base/macros.h" | 9 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 10 #include "base/sequenced_task_runner.h" | |
| 11 #include "components/arc/common/arc_message_types.h" | 11 #include "components/arc/common/arc_message_types.h" |
| 12 #include "ipc/ipc_channel_proxy.h" | 12 |
| 13 #include "ipc/ipc_listener.h" | 13 namespace base { |
| 14 #include "ipc/ipc_message.h" | 14 class SequencedTaskRunner; |
| 15 class SingleThreadTaskRunner; | |
| 16 } | |
| 15 | 17 |
| 16 namespace arc { | 18 namespace arc { |
| 17 | 19 |
| 18 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 20 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| 19 // This service handles the lifetime of ARC instances and sets up the | 21 // This service handles the lifetime of ARC instances and sets up the |
| 20 // communication channel (the ARC bridge) used to send and receive messages. | 22 // communication channel (the ARC bridge) used to send and receive messages. |
| 21 class ArcBridgeService : public IPC::Listener { | 23 class ArcBridgeService { |
| 22 public: | 24 public: |
| 23 // The possible states of the bridge. In the normal flow, the state changes | 25 // The possible states of the bridge. In the normal flow, the state changes |
| 24 // in the following sequence: | 26 // in the following sequence: |
| 25 // | 27 // |
| 26 // STOPPED | 28 // STOPPED |
| 27 // SetAvailable(true) + HandleStartup() -> SocketConnect() -> | 29 // SetAvailable(true) + HandleStartup() -> SocketConnect() -> |
| 28 // CONNECTING | 30 // CONNECTING |
| 29 // Connect() -> | 31 // Connect() -> |
| 30 // CONNECTED | 32 // CONNECTED |
| 31 // SocketConnectAfterSetSocketPermissions() -> | 33 // SocketConnectAfterSetSocketPermissions() -> |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 public: | 66 public: |
| 65 // Called whenever the state of the bridge has changed. | 67 // Called whenever the state of the bridge has changed. |
| 66 virtual void OnStateChanged(State state) {} | 68 virtual void OnStateChanged(State state) {} |
| 67 | 69 |
| 68 // Called when the instance has reached a boot phase | 70 // Called when the instance has reached a boot phase |
| 69 virtual void OnInstanceBootPhase(InstanceBootPhase phase) {} | 71 virtual void OnInstanceBootPhase(InstanceBootPhase phase) {} |
| 70 | 72 |
| 71 // Called whenever ARC's availability has changed for this system. | 73 // Called whenever ARC's availability has changed for this system. |
| 72 virtual void OnAvailableChanged(bool available) {} | 74 virtual void OnAvailableChanged(bool available) {} |
| 73 | 75 |
| 76 // Called whenever ARC sends information about available apps. | |
| 77 virtual void OnAppsRefreshed(const std::vector<std::string>& name, | |
| 78 const std::vector<std::string>& packages, | |
| 79 const std::vector<std::string>& activities) {} | |
| 80 | |
| 81 // Called whenever ARC sends app icon data for specific scale factor. | |
| 82 virtual void OnAppIcon(const std::string& package, | |
| 83 const std::string& activity, | |
| 84 int scale_factor, | |
| 85 const std::vector<uint8_t>& icon_png_data) {} | |
|
dcheng
2015/11/25 06:34:07
Where does icon_png_data originate from? Is this s
khmel1
2015/11/25 06:51:08
This png is encoded in Android: https://googleplex
dcheng
2015/11/25 19:34:55
Would it be feasible to decode here and just pass
khmel1
2015/11/27 05:24:01
I already responded early, just for consistency:
W
dcheng
2015/11/27 05:39:56
That doesn't seem like it'd require multiple obser
khmel1
2015/11/27 05:53:16
Sorry, I don't clear understand your thoughts. Wha
| |
| 86 | |
| 74 protected: | 87 protected: |
| 75 virtual ~Observer() {} | 88 virtual ~Observer() {} |
| 76 }; | 89 }; |
| 77 | 90 |
| 78 ArcBridgeService( | 91 ArcBridgeService(); |
|
hidehiko
2015/11/25 07:47:37
Please move them to protected section.
khmel1
2015/11/25 15:28:31
scoped_ptr<ArcBridgeService> requires public acces
hidehiko
2015/11/26 03:47:22
For dtor, yes. But it should not requires ctors, I
khmel1
2015/11/27 05:24:01
Done, Was addressed in previous CL
| |
| 92 virtual ~ArcBridgeService(); | |
| 93 | |
| 94 // Create instance of |ArcBridgeService| for normal use. | |
| 95 static ArcBridgeService* Create( | |
| 79 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, | 96 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
| 80 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); | 97 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
| 81 ~ArcBridgeService() override; | |
| 82 | 98 |
| 83 // Gets the global instance of the ARC Bridge Service. This can only be | 99 // Gets the global instance of the ARC Bridge Service. This can only be |
| 84 // called on the thread that this class was created on. | 100 // called on the thread that this class was created on. |
| 85 static ArcBridgeService* Get(); | 101 static ArcBridgeService* Get(); |
| 86 | 102 |
| 87 // DetectAvailability() should be called once D-Bus is available. It will | 103 // DetectAvailability() should be called once D-Bus is available. It will |
| 88 // call CheckArcAvailability() on the session_manager. This can only be | 104 // call CheckArcAvailability() on the session_manager. This can only be |
| 89 // called on the thread that this class was created on. | 105 // called on the thread that this class was created on. |
| 90 void DetectAvailability(); | 106 virtual void DetectAvailability() = 0; |
| 91 | 107 |
| 92 // HandleStartup() should be called upon profile startup. This will only | 108 // HandleStartup() should be called upon profile startup. This will only |
| 93 // launch an instance if the instance service is available and it is enabled. | 109 // launch an instance if the instance service is available and it is enabled. |
| 94 // This can only be called on the thread that this class was created on. | 110 // This can only be called on the thread that this class was created on. |
| 95 void HandleStartup(); | 111 virtual void HandleStartup() = 0; |
| 96 | 112 |
| 97 // Shutdown() should be called when the browser is shutting down. This can | 113 // Shutdown() should be called when the browser is shutting down. This can |
| 98 // only be called on the thread that this class was created on. | 114 // only be called on the thread that this class was created on. |
| 99 void Shutdown(); | 115 virtual void Shutdown() = 0; |
| 100 | 116 |
| 101 // Adds or removes observers. This can only be called on the thread that this | 117 // Adds or removes observers. This can only be called on the thread that this |
| 102 // class was created on. | 118 // class was created on. |
| 103 void AddObserver(Observer* observer); | 119 void AddObserver(Observer* observer); |
| 104 void RemoveObserver(Observer* observer); | 120 void RemoveObserver(Observer* observer); |
| 105 | 121 |
| 106 // Gets the current state of the bridge service. | 122 // Gets the current state of the bridge service. |
| 107 State state() const { return state_; } | 123 State state() const { return state_; } |
| 108 | 124 |
| 109 // Gets if ARC is available in this system. | 125 // Gets if ARC is available in this system. |
| 110 bool available() const { return available_; } | 126 bool available() const { return available_; } |
| 111 | 127 |
| 112 // Requests registration of an input device on the ARC instance. | 128 // Requests registration of an input device on the ARC instance. |
| 113 // TODO(denniskempin): Make this interface more typesafe. | 129 // TODO(denniskempin): Make this interface more typesafe. |
| 114 // |name| should be the displayable name of the emulated device (e.g. "Chrome | 130 // |name| should be the displayable name of the emulated device (e.g. "Chrome |
| 115 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | 131 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") |
| 116 // and |fd| a file descriptor that emulates the kernel events of the device. | 132 // and |fd| a file descriptor that emulates the kernel events of the device. |
| 117 // This can only be called on the thread that this class was created on. | 133 // This can only be called on the thread that this class was created on. |
| 118 bool RegisterInputDevice(const std::string& name, | 134 virtual bool RegisterInputDevice(const std::string& name, |
| 119 const std::string& device_type, | 135 const std::string& device_type, |
| 120 base::ScopedFD fd); | 136 base::ScopedFD fd) = 0; |
| 121 | 137 |
| 122 private: | 138 // Requests to refresh an app list. |
| 123 friend class ArcBridgeTest; | 139 virtual bool RefreshApps() = 0; |
| 124 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | |
| 125 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | |
| 126 | 140 |
| 127 // If all pre-requisites are true (ARC is available, it has been enabled, and | 141 // Requests to launch an app. |
| 128 // the session has started), and ARC is stopped, start ARC. If ARC is running | 142 virtual bool LaunchApp(const std::string& package, |
| 129 // and the pre-requisites stop being true, stop ARC. | 143 const std::string& activity) = 0; |
| 130 void PrerequisitesChanged(); | |
| 131 | 144 |
| 132 // Binds to the socket specified by |socket_path|. | 145 // Request to load icon of specific scale_factor. |
| 133 void SocketConnect(const base::FilePath& socket_path); | 146 virtual bool RequestIcon(const std::string& package, |
| 147 const std::string& activity, | |
| 148 int scale_factor) = 0; | |
| 134 | 149 |
| 135 // Binds to the socket specified by |socket_path| after creating its parent | 150 protected: |
| 136 // directory is present. | |
| 137 void SocketConnectAfterEnsureParentDirectory( | |
| 138 const base::FilePath& socket_path, | |
| 139 bool directory_present); | |
| 140 | |
| 141 // Internal connection method. Separated to make testing easier. | |
| 142 bool Connect(const IPC::ChannelHandle& handle, IPC::Channel::Mode mode); | |
| 143 | |
| 144 // Finishes connecting after setting socket permissions. | |
| 145 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path, | |
| 146 bool socket_permissions_success); | |
| 147 | |
| 148 // Stops the running instance. | |
| 149 void StopInstance(); | |
| 150 | |
| 151 // Called when the instance has reached a boot phase | |
| 152 void OnInstanceBootPhase(InstanceBootPhase phase); | |
| 153 | |
| 154 // Changes the current state and notifies all observers. | 151 // Changes the current state and notifies all observers. |
| 155 void SetState(State state); | 152 void SetState(State state); |
| 156 | 153 |
| 157 // IPC::Listener: | 154 // Changes the current availability and notifies all observers. |
| 158 bool OnMessageReceived(const IPC::Message& message) override; | 155 void SetAvailable(bool availability); |
| 159 | |
| 160 // DBus callbacks. | |
| 161 void OnArcAvailable(bool available); | |
| 162 void OnInstanceStarted(bool success); | |
| 163 void OnInstanceStopped(bool success); | |
| 164 | 156 |
| 165 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | 157 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
| 166 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | |
| 167 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | |
| 168 | |
| 169 scoped_ptr<IPC::ChannelProxy> ipc_channel_; | |
| 170 | 158 |
| 171 base::ObserverList<Observer> observer_list_; | 159 base::ObserverList<Observer> observer_list_; |
| 172 | 160 |
| 173 // If the user's session has started. | |
| 174 bool session_started_; | |
| 175 | |
| 176 // If the ARC instance service is available. | 161 // If the ARC instance service is available. |
| 177 bool available_; | 162 bool available_; |
| 178 | 163 |
| 179 // The current state of the bridge. | 164 // The current state of the bridge. |
| 180 ArcBridgeService::State state_; | 165 ArcBridgeService::State state_; |
| 181 | 166 |
| 182 // WeakPtrFactory to use callbacks. | |
| 183 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | |
| 184 | |
| 185 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 167 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 186 }; | 168 }; |
| 187 | 169 |
| 188 } // namespace arc | 170 } // namespace arc |
| 189 | 171 |
| 190 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 172 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |