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/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| 11 #include "components/arc/arc_bridge_input_devices.h" | |
| 11 #include "ipc/ipc_channel_proxy.h" | 12 #include "ipc/ipc_channel_proxy.h" |
| 12 #include "ipc/ipc_listener.h" | 13 #include "ipc/ipc_listener.h" |
| 13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 15 #include "ui/events/event.h" | |
| 14 | 16 |
| 15 namespace base { | 17 namespace base { |
| 16 class CommandLine; | 18 class CommandLine; |
| 17 } | 19 } |
| 18 | 20 |
| 19 namespace arc { | 21 namespace arc { |
| 20 | 22 |
| 21 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 23 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
| 22 // This service handles the lifetime of ARC instances and sets up the | 24 // This service handles the lifetime of ARC instances and sets up the |
| 23 // communication channel (the ARC bridge) used to send and receive messages. | 25 // communication channel (the ARC bridge) used to send and receive messages. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 // class was created on. | 108 // class was created on. |
| 107 void AddObserver(Observer* observer); | 109 void AddObserver(Observer* observer); |
| 108 void RemoveObserver(Observer* observer); | 110 void RemoveObserver(Observer* observer); |
| 109 | 111 |
| 110 // Gets the current state of the bridge service. | 112 // Gets the current state of the bridge service. |
| 111 State state() const { return state_; } | 113 State state() const { return state_; } |
| 112 | 114 |
| 113 // Gets if ARC is available in this system. | 115 // Gets if ARC is available in this system. |
| 114 bool available() const { return available_; } | 116 bool available() const { return available_; } |
| 115 | 117 |
| 116 // Requests registration of an input device on the ARC instance. | 118 // Translates and sends input event to the ARC instance. |
| 117 // TODO(denniskempin): Make this interface more typesafe. | 119 void SendInputEvent(ui::Event* event); |
| 118 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
| 119 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
| 120 // and |fd| a file descriptor that emulates the kernel events of the device. | |
| 121 // This can only be called on the thread that this class was created on. | |
| 122 bool RegisterInputDevice(const std::string& name, | |
| 123 const std::string& device_type, | |
| 124 base::ScopedFD fd); | |
| 125 | 120 |
| 126 private: | 121 private: |
| 127 friend class ArcBridgeTest; | 122 friend class ArcBridgeTest; |
| 128 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 123 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
| 129 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 124 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
| 130 | 125 |
| 131 // If all pre-requisites are true (ARC is available, it has been enabled, and | 126 // If all pre-requisites are true (ARC is available, it has been enabled, and |
| 132 // the session has started), and ARC is stopped, start ARC. If ARC is running | 127 // the session has started), and ARC is stopped, start ARC. If ARC is running |
| 133 // and the pre-requisites stop being true, stop ARC. | 128 // and the pre-requisites stop being true, stop ARC. |
| 134 void PrerequisitesChanged(); | 129 void PrerequisitesChanged(); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 160 void SetState(State state); | 155 void SetState(State state); |
| 161 | 156 |
| 162 // IPC::Listener: | 157 // IPC::Listener: |
| 163 bool OnMessageReceived(const IPC::Message& message) override; | 158 bool OnMessageReceived(const IPC::Message& message) override; |
| 164 | 159 |
| 165 // DBus callbacks. | 160 // DBus callbacks. |
| 166 void OnArcAvailable(bool available); | 161 void OnArcAvailable(bool available); |
| 167 void OnInstanceStarted(bool success); | 162 void OnInstanceStarted(bool success); |
| 168 void OnInstanceStopped(bool success); | 163 void OnInstanceStopped(bool success); |
| 169 | 164 |
| 165 // Creates and registers an input device on the ARC instance. | |
| 166 // TODO(denniskempin): Make this interface more typesafe. | |
| 167 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
| 168 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
| 169 // Returns a file descriptor that receives the kernel events of the device. | |
| 170 base::ScopedFD CreateBridgeInputDevice(const std::string& name, | |
|
Luis Héctor Chávez
2015/11/17 17:51:54
I would prefer if the ArcBridgeService did not hav
denniskempin
2015/11/19 19:22:09
done
| |
| 171 const std::string& device_type); | |
| 172 | |
| 173 // Register all bridge input devices with the ARC instance. Called | |
| 174 // once the instance is ready. | |
| 175 void SetupBridgeInputDevices(); | |
| 176 | |
| 177 // List of bridge input devices registered with the ARC instance. | |
| 178 ScopedVector<BridgeInputDevice> bridge_devices_; | |
| 179 | |
| 180 // Task runner on which incoming messages are handled. | |
| 170 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | 181 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; |
| 171 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; | 182 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_; |
| 172 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 183 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
| 173 | 184 |
| 174 scoped_ptr<IPC::ChannelProxy> ipc_channel_; | 185 scoped_ptr<IPC::ChannelProxy> ipc_channel_; |
| 175 | 186 |
| 176 base::ObserverList<Observer> observer_list_; | 187 base::ObserverList<Observer> observer_list_; |
| 177 | 188 |
| 178 // If the user's session has started. | 189 // If the user's session has started. |
| 179 bool session_started_; | 190 bool session_started_; |
| 180 | 191 |
| 181 // If the ARC instance service is available. | 192 // If the ARC instance service is available. |
| 182 bool available_; | 193 bool available_; |
| 183 | 194 |
| 184 // The current state of the bridge. | 195 // The current state of the bridge. |
| 185 ArcBridgeService::State state_; | 196 ArcBridgeService::State state_; |
| 186 | 197 |
| 187 // WeakPtrFactory to use callbacks. | 198 // WeakPtrFactory to use callbacks. |
| 188 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 199 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
| 189 | 200 |
| 190 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 201 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
| 191 }; | 202 }; |
| 192 | 203 |
| 193 } // namespace arc | 204 } // namespace arc |
| 194 | 205 |
| 195 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 206 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
| OLD | NEW |