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

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

Issue 1481523002: arc-bridge: Split ArcBridgeService to common part and IPC based impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase issue Created 5 years 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
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"
10 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h" 11 #include "base/observer_list.h"
10 #include "base/sequenced_task_runner.h"
11 #include "components/arc/common/arc_message_types.h" 12 #include "components/arc/common/arc_message_types.h"
12 #include "ipc/ipc_channel_proxy.h" 13
13 #include "ipc/ipc_listener.h" 14 namespace base {
hidehiko 2015/11/26 02:21:51 nit: please merge namespace to just below one.
khmel1 2015/11/26 05:46:43 Done.
14 #include "ipc/ipc_message.h" 15 class SequencedTaskRunner;
16 class SingleThreadTaskRunner;
17 }
15 18
16 namespace base { 19 namespace base {
17 class CommandLine; 20 class CommandLine;
18 } 21 }
19 22
20 namespace arc { 23 namespace arc {
21 24
22 // The Chrome-side service that handles ARC instances and ARC bridge creation. 25 // The Chrome-side service that handles ARC instances and ARC bridge creation.
23 // This service handles the lifetime of ARC instances and sets up the 26 // This service handles the lifetime of ARC instances and sets up the
24 // communication channel (the ARC bridge) used to send and receive messages. 27 // communication channel (the ARC bridge) used to send and receive messages.
25 class ArcBridgeService : public IPC::Listener { 28 class ArcBridgeService {
26 public: 29 public:
27 // The possible states of the bridge. In the normal flow, the state changes 30 // The possible states of the bridge. In the normal flow, the state changes
28 // in the following sequence: 31 // in the following sequence:
29 // 32 //
30 // STOPPED 33 // STOPPED
31 // SetAvailable(true) + HandleStartup() -> SocketConnect() -> 34 // SetAvailable(true) + HandleStartup() -> SocketConnect() ->
32 // CONNECTING 35 // CONNECTING
33 // Connect() -> 36 // Connect() ->
34 // CONNECTED 37 // CONNECTED
35 // SocketConnectAfterSetSocketPermissions() -> 38 // SocketConnectAfterSetSocketPermissions() ->
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Called when the instance has reached a boot phase 75 // Called when the instance has reached a boot phase
73 virtual void OnInstanceBootPhase(InstanceBootPhase phase) {} 76 virtual void OnInstanceBootPhase(InstanceBootPhase phase) {}
74 77
75 // Called whenever ARC's availability has changed for this system. 78 // Called whenever ARC's availability has changed for this system.
76 virtual void OnAvailableChanged(bool available) {} 79 virtual void OnAvailableChanged(bool available) {}
77 80
78 protected: 81 protected:
79 virtual ~Observer() {} 82 virtual ~Observer() {}
80 }; 83 };
81 84
82 ArcBridgeService( 85 ArcBridgeService();
hidehiko 2015/11/26 02:21:51 Please move this to protected.
khmel1 2015/11/26 05:46:43 Done.
86 virtual ~ArcBridgeService();
87
88 // Create instance of |ArcBridgeService| for normal use.
hidehiko 2015/11/26 02:21:51 nit: Create*s*. (For function or class comment, th
khmel1 2015/11/26 05:46:43 Sorry, copied from legacy code as template and did
89 static scoped_ptr<ArcBridgeService> Create(
83 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, 90 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner,
84 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); 91 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner);
85 ~ArcBridgeService() override;
86 92
87 // Gets the global instance of the ARC Bridge Service. This can only be 93 // Gets the global instance of the ARC Bridge Service. This can only be
88 // called on the thread that this class was created on. 94 // called on the thread that this class was created on.
89 static ArcBridgeService* Get(); 95 static ArcBridgeService* Get();
90 96
91 // Return true if ARC has been enabled through a commandline 97 // Return true if ARC has been enabled through a commandline
92 // switch. 98 // switch.
93 static bool GetEnabled(const base::CommandLine* command_line); 99 static bool GetEnabled(const base::CommandLine* command_line);
94 100
95 // DetectAvailability() should be called once D-Bus is available. It will 101 // DetectAvailability() should be called once D-Bus is available. It will
96 // call CheckArcAvailability() on the session_manager. This can only be 102 // call CheckArcAvailability() on the session_manager. This can only be
97 // called on the thread that this class was created on. 103 // called on the thread that this class was created on.
98 void DetectAvailability(); 104 virtual void DetectAvailability() = 0;
99 105
100 // HandleStartup() should be called upon profile startup. This will only 106 // HandleStartup() should be called upon profile startup. This will only
101 // launch an instance if the instance service is available and it is enabled. 107 // launch an instance if the instance service is available and it is enabled.
102 // This can only be called on the thread that this class was created on. 108 // This can only be called on the thread that this class was created on.
103 void HandleStartup(); 109 virtual void HandleStartup() = 0;
104 110
105 // Shutdown() should be called when the browser is shutting down. This can 111 // Shutdown() should be called when the browser is shutting down. This can
106 // only be called on the thread that this class was created on. 112 // only be called on the thread that this class was created on.
107 void Shutdown(); 113 virtual void Shutdown() = 0;
108 114
109 // Adds or removes observers. This can only be called on the thread that this 115 // Adds or removes observers. This can only be called on the thread that this
110 // class was created on. 116 // class was created on.
111 void AddObserver(Observer* observer); 117 void AddObserver(Observer* observer);
112 void RemoveObserver(Observer* observer); 118 void RemoveObserver(Observer* observer);
113 119
114 // Gets the current state of the bridge service. 120 // Gets the current state of the bridge service.
115 State state() const { return state_; } 121 State state() const { return state_; }
116 122
117 // Gets if ARC is available in this system. 123 // Gets if ARC is available in this system.
118 bool available() const { return available_; } 124 bool available() const { return available_; }
119 125
120 // Requests registration of an input device on the ARC instance. 126 // Requests registration of an input device on the ARC instance.
121 // TODO(denniskempin): Make this interface more typesafe. 127 // TODO(denniskempin): Make this interface more typesafe.
122 // |name| should be the displayable name of the emulated device (e.g. "Chrome 128 // |name| should be the displayable name of the emulated device (e.g. "Chrome
123 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") 129 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
124 // and |fd| a file descriptor that emulates the kernel events of the device. 130 // and |fd| a file descriptor that emulates the kernel events of the device.
125 // This can only be called on the thread that this class was created on. 131 // This can only be called on the thread that this class was created on.
126 bool RegisterInputDevice(const std::string& name, 132 virtual bool RegisterInputDevice(const std::string& name,
127 const std::string& device_type, 133 const std::string& device_type,
128 base::ScopedFD fd); 134 base::ScopedFD fd) = 0;
129 135
130 private: 136 protected:
131 friend class ArcBridgeTest;
132 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic);
133 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup);
134
135 // If all pre-requisites are true (ARC is available, it has been enabled, and
136 // the session has started), and ARC is stopped, start ARC. If ARC is running
137 // and the pre-requisites stop being true, stop ARC.
138 void PrerequisitesChanged();
139
140 // Binds to the socket specified by |socket_path|.
141 void SocketConnect(const base::FilePath& socket_path);
142
143 // Binds to the socket specified by |socket_path| after creating its parent
144 // directory is present.
145 void SocketConnectAfterEnsureParentDirectory(
146 const base::FilePath& socket_path,
147 bool directory_present);
148
149 // Internal connection method. Separated to make testing easier.
150 bool Connect(const IPC::ChannelHandle& handle, IPC::Channel::Mode mode);
151
152 // Finishes connecting after setting socket permissions.
153 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path,
154 bool socket_permissions_success);
155
156 // Stops the running instance.
157 void StopInstance();
158
159 // Called when the instance has reached a boot phase
160 void OnInstanceBootPhase(InstanceBootPhase phase);
161
162 // Changes the current state and notifies all observers. 137 // Changes the current state and notifies all observers.
163 void SetState(State state); 138 void SetState(State state);
164 139
165 // IPC::Listener: 140 // Changes the current availability and notifies all observers.
166 bool OnMessageReceived(const IPC::Message& message) override; 141 void SetAvailable(bool availability);
167
168 // DBus callbacks.
169 void OnArcAvailable(bool available);
170 void OnInstanceStarted(bool success);
171 void OnInstanceStopped(bool success);
172 142
173 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_; 143 scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
174 scoped_refptr<base::SingleThreadTaskRunner> ipc_task_runner_;
175 scoped_refptr<base::SequencedTaskRunner> file_task_runner_;
176
177 scoped_ptr<IPC::ChannelProxy> ipc_channel_;
178 144
179 base::ObserverList<Observer> observer_list_; 145 base::ObserverList<Observer> observer_list_;
hidehiko 2015/11/26 02:21:51 Following three fields can and should be private?
khmel1 2015/11/26 05:46:43 Done
180 146
181 // If the user's session has started.
182 bool session_started_;
183
184 // If the ARC instance service is available. 147 // If the ARC instance service is available.
185 bool available_; 148 bool available_;
186 149
187 // The current state of the bridge. 150 // The current state of the bridge.
188 ArcBridgeService::State state_; 151 ArcBridgeService::State state_;
189 152
190 // WeakPtrFactory to use callbacks.
191 base::WeakPtrFactory<ArcBridgeService> weak_factory_;
192
193 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); 153 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService);
hidehiko 2015/11/26 02:21:51 private:
khmel1 2015/11/26 05:46:43 Done.
194 }; 154 };
195 155
196 } // namespace arc 156 } // namespace arc
197 157
198 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ 158 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698