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/common/arc_notification_types.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" |
14 | 15 |
15 namespace arc { | 16 namespace arc { |
16 | 17 |
17 // The Chrome-side service that handles ARC instances and ARC bridge creation. | 18 // The Chrome-side service that handles ARC instances and ARC bridge creation. |
18 // This service handles the lifetime of ARC instances and sets up the | 19 // This service handles the lifetime of ARC instances and sets up the |
19 // communication channel (the ARC bridge) used to send and receive messages. | 20 // communication channel (the ARC bridge) used to send and receive messages. |
20 class ArcBridgeService : public IPC::Listener { | 21 class ArcBridgeService : public IPC::Listener { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 }; | 61 }; |
61 | 62 |
62 class Observer { | 63 class Observer { |
63 public: | 64 public: |
64 // Called whenever the state of the bridge has changed. | 65 // Called whenever the state of the bridge has changed. |
65 virtual void OnStateChanged(State state) {} | 66 virtual void OnStateChanged(State state) {} |
66 | 67 |
67 // Called whenever ARC's availability has changed for this system. | 68 // Called whenever ARC's availability has changed for this system. |
68 virtual void OnAvailableChanged(bool available) {} | 69 virtual void OnAvailableChanged(bool available) {} |
69 | 70 |
| 71 // Called whenever a notification has been posted on Android side. This |
| 72 // event is used for both creation and update. |
| 73 virtual void OnNotificationPostedFromAndroid( |
| 74 const ArcNotificationData& data) {} |
| 75 // Called whenever a notification has been removed on Android side. |
| 76 virtual void OnNotificationRemovedFromAndroid(const std::string& key) {} |
| 77 |
70 protected: | 78 protected: |
71 virtual ~Observer() {} | 79 virtual ~Observer() {} |
72 }; | 80 }; |
73 | 81 |
74 ArcBridgeService( | 82 ArcBridgeService( |
75 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, | 83 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
76 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); | 84 const scoped_refptr<base::SequencedTaskRunner>& file_task_runner); |
77 ~ArcBridgeService() override; | 85 ~ArcBridgeService() override; |
78 | 86 |
79 // Gets the global instance of the ARC Bridge Service. This can only be | 87 // Gets the global instance of the ARC Bridge Service. This can only be |
(...skipping 28 matching lines...) Expand all Loading... |
108 // Requests registration of an input device on the ARC instance. | 116 // Requests registration of an input device on the ARC instance. |
109 // TODO(denniskempin): Make this interface more typesafe. | 117 // TODO(denniskempin): Make this interface more typesafe. |
110 // |name| should be the displayable name of the emulated device (e.g. "Chrome | 118 // |name| should be the displayable name of the emulated device (e.g. "Chrome |
111 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") | 119 // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard") |
112 // and |fd| a file descriptor that emulates the kernel events of the device. | 120 // and |fd| a file descriptor that emulates the kernel events of the device. |
113 // This can only be called on the thread that this class was created on. | 121 // This can only be called on the thread that this class was created on. |
114 bool RegisterInputDevice(const std::string& name, | 122 bool RegisterInputDevice(const std::string& name, |
115 const std::string& device_type, | 123 const std::string& device_type, |
116 base::ScopedFD fd); | 124 base::ScopedFD fd); |
117 | 125 |
| 126 // Notifys a notification event to Android side. |
| 127 bool NotifyNotificationEvent(const std::string& key, NotificationEvent event); |
| 128 |
118 private: | 129 private: |
119 friend class ArcBridgeTest; | 130 friend class ArcBridgeTest; |
120 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); | 131 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, Basic); |
121 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); | 132 FRIEND_TEST_ALL_PREFIXES(ArcBridgeTest, ShutdownMidStartup); |
122 | 133 |
123 // If all pre-requisites are true (ARC is available, it has been enabled, and | 134 // If all pre-requisites are true (ARC is available, it has been enabled, and |
124 // the session has started), and ARC is stopped, start ARC. If ARC is running | 135 // the session has started), and ARC is stopped, start ARC. If ARC is running |
125 // and the pre-requisites stop being true, stop ARC. | 136 // and the pre-requisites stop being true, stop ARC. |
126 void PrerequisitesChanged(); | 137 void PrerequisitesChanged(); |
127 | 138 |
(...skipping 13 matching lines...) Expand all Loading... |
141 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path, | 152 void SocketConnectAfterSetSocketPermissions(const base::FilePath& socket_path, |
142 bool socket_permissions_success); | 153 bool socket_permissions_success); |
143 | 154 |
144 // Stops the running instance. | 155 // Stops the running instance. |
145 void StopInstance(); | 156 void StopInstance(); |
146 | 157 |
147 // Called when the ARC instance has finished setting up and is ready for user | 158 // Called when the ARC instance has finished setting up and is ready for user |
148 // interaction. | 159 // interaction. |
149 void OnInstanceReady(); | 160 void OnInstanceReady(); |
150 | 161 |
| 162 // Handler for ArcInstanceHostMsg_NotificationPosted message. |
| 163 void OnNotificationPosted(const ArcNotificationData& data); |
| 164 // Handler for ArcInstanceHostMsg_NotificationRemoved message. |
| 165 void OnNotificationRemoved(const std::string& key); |
| 166 |
151 // Changes the current state and notifies all observers. | 167 // Changes the current state and notifies all observers. |
152 void SetState(State state); | 168 void SetState(State state); |
153 | 169 |
154 // IPC::Listener: | 170 // IPC::Listener: |
155 bool OnMessageReceived(const IPC::Message& message) override; | 171 bool OnMessageReceived(const IPC::Message& message) override; |
156 | 172 |
157 // DBus callbacks. | 173 // DBus callbacks. |
158 void OnArcAvailable(bool available); | 174 void OnArcAvailable(bool available); |
159 void OnInstanceStarted(bool success); | 175 void OnInstanceStarted(bool success); |
160 void OnInstanceStopped(bool success); | 176 void OnInstanceStopped(bool success); |
(...skipping 17 matching lines...) Expand all Loading... |
178 | 194 |
179 // WeakPtrFactory to use callbacks. | 195 // WeakPtrFactory to use callbacks. |
180 base::WeakPtrFactory<ArcBridgeService> weak_factory_; | 196 base::WeakPtrFactory<ArcBridgeService> weak_factory_; |
181 | 197 |
182 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); | 198 DISALLOW_COPY_AND_ASSIGN(ArcBridgeService); |
183 }; | 199 }; |
184 | 200 |
185 } // namespace arc | 201 } // namespace arc |
186 | 202 |
187 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ | 203 #endif // COMPONENTS_ARC_ARC_BRIDGE_SERVICE_H_ |
OLD | NEW |