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

Side by Side Diff: components/arc/arc_bridge_service.h

Issue 1412863004: arc-bridge: Add the ARC Bridge Service (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Addressed feedback Created 5 years, 1 month 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 unified diff | Download patch
OLDNEW
(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_threadsafe.h"
10 #include "base/sequenced_task_runner.h"
11 #include "chromeos/dbus/dbus_method_call_status.h"
12 #include "ipc/ipc_channel_proxy.h"
13 #include "ipc/ipc_listener.h"
14 #include "ipc/ipc_message.h"
15
16 class PrefRegistrySimple;
17 class PrefService;
18
19 namespace arc {
20
21 class ArcBridgeTest;
22
23 // The Chrome-side service that handles ARC instances and ARC bridge creation.
24 // This service handles the lifetime of ARC instances and sets up the
25 // communication channel (the ARC bridge) used to send and receive messages.
26 class ArcBridgeService : public IPC::Listener {
27 public:
28 // The possible states of the bridge. In the normal flow, the state changes
29 // in the following sequence:
30 //
31 // STOPPED
32 // SetEnabled(true) + HandleStartup() -> SocketConnect() ->
33 // CONNECTING
34 // Connect() ->
35 // CONNECTED
36 // SocketConnectAfterSetSocketPermissions() ->
37 // STARTING
38 // StartInstance() -> OnInstanceReady() ->
39 // READY
40 //
41 // When Shutdown() is called, the state changes depending on the state it was
42 // at:
43 //
44 // CONNECTED/CONNECTING -> STOPPED
45 // STARTING/READY -> STOPPING -> StopInstance() -> STOPPED
46 enum class State {
47 // ARC is not currently running.
48 STOPPED,
49
50 // The request to connect has been sent.
51 CONNECTING,
52
53 // The bridge has connected to the socket, but has not started the ARC
54 // instance.
55 CONNECTED,
56
57 // The ARC bridge has been set up and ARC is starting up.
58 STARTING,
59
60 // The ARC instance has been fully initialized and is now ready for user
61 // interaction.
62 READY,
63
64 // The ARC instance has started shutting down.
65 STOPPING,
66 };
67
68 class Observer {
69 public:
70 // Called whenever the state of the bridge has changed.
71 virtual void OnStateChanged(State state) {}
jochen (gone - plz use gerrit) 2015/11/06 06:02:17 why aren't those pure virtual?
Luis Héctor Chávez 2015/11/09 16:41:04 I saw examples of both pure virtual and this style
72
73 // Called whenever ARC's enabled status has changed for this session.
74 virtual void OnEnabledChanged(bool enabled) {}
75
76 protected:
77 virtual ~Observer() {}
78 };
79
80 explicit ArcBridgeService(
81 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
82 virtual ~ArcBridgeService();
83
84 // HandleStartup() should be called upon profile startup. This will only
85 // launch an instance if the instance service is available and it is enabled.
86 void HandleStartup();
87
88 // Shuts down the running instance, if any. This is safe to call even if
89 // there is no instance running.
90 void Shutdown();
91
92 // Adds or removes observers.
93 void AddObserver(Observer* observer);
94 void RemoveObserver(Observer* observer);
95
96 // Gets the current state of the bridge service.
97 State state() const { return state_; }
98
99 // Enables or disables the bridge for this session.
100 void SetEnabled(bool enabled);
101
102 // Gets if the bridge is enabled for this session.
103 bool enabled() const { return enabled_; }
104
105 // Requests registration of an input device on the ARC instance.
106 // TODO(denniskempin): Make this interface more typesafe.
107 // |name| should be the displayable name of the emulated device (e.g. "Chrome
108 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
109 // and |fd| a file descriptor that emulates the kernel events of the device.
110 bool RegisterInputDevice(const std::string& name,
111 const std::string& device_type,
112 base::ScopedFD fd);
113
114 private:
115 friend class arc::ArcBridgeTest;
jochen (gone - plz use gerrit) 2015/11/06 06:02:17 please use the FRIEND_TEST_ALL_PREFIXES macro
jochen (gone - plz use gerrit) 2015/11/06 06:02:17 please use the FRIEND_TEST_ALL_PREFIXES macro
Luis Héctor Chávez 2015/11/09 16:41:04 Done.
116
117 // Binds to the socket specified by |socket_path|.
118 void SocketConnect(const base::FilePath& socket_path);
119
120 // Binds to the socket specified by |socket_path| after creating its parent
121 // directory is present.
122 void SocketConnectAfterEnsureParentDirectory(
123 const base::FilePath& socket_path, bool directory_present);
124
125 // Internal connection method. Separated to make testing easier.
126 bool Connect(const IPC::ChannelHandle& handle, IPC::Channel::Mode mode);
127
128 // Finishes connecting after setting socket permissions.
129 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path,
130 bool socket_permissions_success);
131
132 // Called when the ARC instance has finished setting up and is ready for user
133 // interaction.
134 void OnInstanceReady();
135
136 // Changes the current state and notify all observers.
137 void SetState(State state);
138
139 // IPC::Listener:
140 bool OnMessageReceived(const IPC::Message& message) override;
141
142 // DBus callbacks.
143 void OnInstanceStarted(bool success);
144 void OnInstanceStopped(bool success);
145
146 // Thread in which IPC messaging is performed.
147 base::Thread ipc_thread_;
148
149 // Task runner on which incoming messages are handled.
150 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
151
152 // Task runner on which file operations are performed.
153 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
154
155 // The channel through which messages are sent.
156 scoped_ptr<IPC::ChannelProxy> ipc_channel_;
157
158 // List of observers to notify of state changes.
159 base::ObserverList<Observer> observer_list_;
160
161 // If the ARC instance service is available.
162 bool available_;
163
164 // If ARC has been enabled by policy and user choice.
165 bool enabled_;
166
167 // The current state of the bridge.
168 ArcBridgeService::State state_;
169
170 // WeakPtrFactory to use callbacks.
171 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
172
173 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
174 };
175
176 } // namespace arc
177
178 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698