Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | |
| 6 #define COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/observer_list.h" | |
| 10 #include "base/sequenced_task_runner.h" | |
| 11 #include "chromeos/dbus/dbus_method_call_status.h" | |
| 12 #include "components/keyed_service/core/keyed_service.h" | |
| 13 #include "ipc/ipc_channel_proxy.h" | |
| 14 #include "ipc/ipc_listener.h" | |
| 15 #include "ipc/ipc_message.h" | |
| 16 | |
| 17 class PrefRegistrySimple; | |
| 18 class PrefService; | |
| 19 | |
| 20 namespace arc { | |
| 21 | |
| 22 class ArcBridgeTest; | |
| 23 | |
| 24 // The Chrome-side service that handles ARC instances and ARC bridge creation. | |
| 25 // This service handles the lifetime of ARC instances and sets up the | |
| 26 // communication channel (the ARC bridge) used to send and receive messages. | |
| 27 class ArcBridgeService : public KeyedService, | |
| 28 public IPC::Listener { | |
|
hidehiko
2015/10/28 17:48:45
nit: can be fit in a line?
Luis Héctor Chávez
2015/10/28 21:06:32
It can, but having it separate seems to be the pre
| |
| 29 public: | |
| 30 enum State { | |
|
hidehiko
2015/10/28 17:48:45
As this is statemachine, it'd be good to note the
Luis Héctor Chávez
2015/10/29 23:43:52
Done.
| |
| 31 // An attempt to start the ARC instance was done, but it resulted in an | |
| 32 // error. | |
| 33 ERROR, | |
| 34 | |
| 35 // ARC was not enabled in this machine. | |
| 36 DISABLED, | |
| 37 | |
| 38 // ARC is enabled in this machine, but has not started. | |
| 39 STOPPED, | |
| 40 | |
| 41 // The bridge has connected to the socket, but has not started the ARC | |
| 42 // instance. | |
| 43 CONNECTED, | |
| 44 | |
| 45 // The ARC bridge has been set up and ARC is starting up. | |
| 46 STARTING, | |
| 47 | |
| 48 // The ARC instance has been fully initialized and is now ready for user | |
| 49 // interaction. | |
| 50 READY | |
| 51 }; | |
| 52 | |
| 53 class Observer { | |
| 54 public: | |
| 55 // Called whenever the state of the bridge has changed. | |
| 56 virtual void OnStateChanged(State state) {} | |
| 57 | |
| 58 protected: | |
| 59 virtual ~Observer() {} | |
| 60 }; | |
| 61 | |
| 62 ArcBridgeService( | |
|
satorux1
2015/10/28 05:45:23
Explicit is missing?
Luis Héctor Chávez
2015/10/28 17:19:14
Done.
| |
| 63 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); | |
| 64 virtual ~ArcBridgeService(); | |
| 65 | |
| 66 // Registers ARC preferences. | |
| 67 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 68 | |
| 69 // Reads from the preference store if ARC has been enabled. | |
| 70 static bool GetEnabledPref(PrefService* pref_service); | |
| 71 | |
| 72 // HandleStartup() should be called upon profile startup. This will only | |
| 73 // launch an instance if the instance service is available and it is enabled. | |
| 74 void HandleStartup(); | |
| 75 | |
| 76 // Shuts down the running instance, if any. This is safe to call even if | |
| 77 // there is no instance running. | |
| 78 void Shutdown(); | |
| 79 | |
| 80 // Add or remove observers. | |
|
satorux1
2015/10/28 05:45:23
nit: Adds or removes
Luis Héctor Chávez
2015/10/28 17:19:14
Done.
| |
| 81 void AddObserver(Observer* observer); | |
| 82 void RemoveObserver(Observer* observer); | |
| 83 | |
| 84 // Gets the current state of the bridge service. | |
| 85 State GetState() const { return state_; } | |
| 86 | |
| 87 // Enables or disables the bridge for this session. | |
| 88 void SetEnabled(bool enabled); | |
| 89 | |
| 90 // Request for registering an input device on the ARC instance. | |
|
satorux1
2015/10/28 05:45:23
nit: Requests
Luis Héctor Chávez
2015/10/28 17:19:14
Done.
| |
| 91 // TODO(denniskempin): Make this interface more typesafe. | |
| 92 // |name| should be the displayable name of the emulated device (e.g. "Chrome | |
| 93 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | |
| 94 // and |fd| a file descriptor that emulates the kernel events of the device. | |
| 95 bool RegisterInputDevice(const std::string& name, | |
| 96 const std::string& device_type, | |
| 97 base::ScopedFD fd); | |
| 98 | |
| 99 private: | |
| 100 friend class arc::ArcBridgeTest; | |
| 101 | |
| 102 // Binds to the socket specified by |socket_path|. | |
| 103 void SocketConnect(const std::string& socket_path, | |
| 104 bool directory_creation_success); | |
| 105 | |
| 106 // Internal connection method. Exposed for testing. | |
|
hidehiko
2015/10/28 17:48:45
For testing, I'd recommend you to pass that socket
hidehiko
2015/10/29 16:29:46
ping?
Luis Héctor Chávez
2015/10/29 23:43:52
Sorry I missed this. We can't do that since this i
| |
| 107 bool Connect(const IPC::ChannelHandle& handle, IPC::Channel::Mode mode); | |
|
satorux1
2015/10/28 05:45:23
If this function is named like ConnectForTesting()
Luis Héctor Chávez
2015/10/28 17:19:14
The function is used outside of tests in arc_bridg
| |
| 108 | |
| 109 // Finish connecting after setting socket permissions. | |
|
satorux1
2015/10/28 05:45:23
nit: Finishes
Luis Héctor Chávez
2015/10/28 17:19:14
Done.
| |
| 110 void FinishConnectAfterSocketPermissions(const std::string& socket_path, | |
| 111 bool socket_permissions_success); | |
| 112 | |
| 113 // Called when the ARC instance has finished setting up and is ready for user | |
| 114 // interaction. | |
| 115 void OnInstanceReady(); | |
| 116 | |
| 117 // Change the current state and notify all observers. | |
|
satorux1
2015/10/28 05:45:23
nit: Changes
Luis Héctor Chávez
2015/10/28 17:19:14
Done.
| |
| 118 void NotifyStateChanged(State state); | |
|
hidehiko
2015/10/28 17:48:45
nit: How about ChangeState(), if this actually cha
Luis Héctor Chávez
2015/10/29 23:43:52
Missed this as well. Was changed to SetState.
| |
| 119 | |
| 120 // Finishes shutdown after deleting the socket file. | |
| 121 void FinishShutdownAfterSocketDeleted(bool socket_deleted); | |
| 122 | |
| 123 // IPC::Listener: | |
| 124 bool OnMessageReceived(const IPC::Message& message) override; | |
| 125 | |
| 126 // DBus callbacks. | |
| 127 void OnInstanceStarted(chromeos::DBusMethodCallStatus status); | |
| 128 void OnInstanceStopped(chromeos::DBusMethodCallStatus status); | |
| 129 | |
| 130 // Thread in which IPC messaging is performed. | |
| 131 base::Thread ipc_thread_; | |
| 132 | |
| 133 // Task runner on which incoming messages are handled. | |
| 134 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; | |
| 135 | |
| 136 // Task runner on which file operations are performed. | |
| 137 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | |
| 138 | |
| 139 // The channel through which messages are sent. | |
| 140 scoped_ptr<IPC::ChannelProxy> ipc_channel_; | |
| 141 | |
| 142 // List of observers to notify of state changes. | |
| 143 // Makes sure list is empty on destruction. | |
| 144 base::ObserverList<Observer, true> observer_list_; | |
| 145 | |
| 146 // The current state of the bridge. | |
| 147 ArcBridgeService::State state_; | |
| 148 | |
| 149 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | |
| 150 }; | |
| 151 | |
| 152 } // namespace arc | |
| 153 | |
| 154 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | |
| OLD | NEW |