OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 5 #ifndef REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 6 #define REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "base/threading/thread_checker.h" | 11 #include "base/threading/thread_checker.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "remoting/host/native_messaging/native_messaging_channel.h" | 13 #include "extensions/browser/api/messaging/native_messaging_channel.h" |
14 #include "remoting/host/setup/daemon_controller.h" | 14 #include "remoting/host/setup/daemon_controller.h" |
15 #include "remoting/host/setup/oauth_client.h" | 15 #include "remoting/host/setup/oauth_client.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class DictionaryValue; | 18 class DictionaryValue; |
19 class ListValue; | 19 class ListValue; |
20 } // namespace base | 20 } // namespace base |
21 | 21 |
22 namespace gaia { | 22 namespace gaia { |
23 class GaiaOAuthClient; | 23 class GaiaOAuthClient; |
24 } // namespace gaia | 24 } // namespace gaia |
25 | 25 |
26 namespace remoting { | 26 namespace remoting { |
27 | 27 |
28 const char kElevatingSwitchName[] = "elevate"; | 28 const char kElevatingSwitchName[] = "elevate"; |
29 const char kInputSwitchName[] = "input"; | 29 const char kInputSwitchName[] = "input"; |
30 const char kOutputSwitchName[] = "output"; | 30 const char kOutputSwitchName[] = "output"; |
31 | 31 |
32 namespace protocol { | 32 namespace protocol { |
33 class PairingRegistry; | 33 class PairingRegistry; |
34 } // namespace protocol | 34 } // namespace protocol |
35 | 35 |
36 // Implementation of the me2me native messaging host. | 36 // Implementation of the me2me native messaging host. |
37 class Me2MeNativeMessagingHost { | 37 class Me2MeNativeMessagingHost |
| 38 : public extensions::NativeMessagingChannel::EventHandler { |
38 public: | 39 public: |
39 typedef NativeMessagingChannel::SendMessageCallback SendMessageCallback; | |
40 | |
41 Me2MeNativeMessagingHost( | 40 Me2MeNativeMessagingHost( |
42 bool needs_elevation, | 41 bool needs_elevation, |
43 intptr_t parent_window_handle, | 42 intptr_t parent_window_handle, |
44 scoped_ptr<NativeMessagingChannel> channel, | 43 scoped_ptr<extensions::NativeMessagingChannel> channel, |
45 scoped_refptr<DaemonController> daemon_controller, | 44 scoped_refptr<DaemonController> daemon_controller, |
46 scoped_refptr<protocol::PairingRegistry> pairing_registry, | 45 scoped_refptr<protocol::PairingRegistry> pairing_registry, |
47 scoped_ptr<OAuthClient> oauth_client); | 46 scoped_ptr<OAuthClient> oauth_client); |
48 virtual ~Me2MeNativeMessagingHost(); | 47 virtual ~Me2MeNativeMessagingHost(); |
49 | 48 |
50 void Start(const base::Closure& quit_closure); | 49 void Start(const base::Closure& quit_closure); |
51 | 50 |
| 51 // extensions::NativeMessagingChannel::EventHandler implementation |
| 52 virtual void OnMessage(scoped_ptr<base::Value> message) OVERRIDE; |
| 53 virtual void OnDisconnect() OVERRIDE; |
| 54 |
52 private: | 55 private: |
53 // Callback to process messages from the native messaging client through | |
54 // |channel_|. | |
55 void ProcessRequest(scoped_ptr<base::DictionaryValue> message); | |
56 | |
57 // These "Process.." methods handle specific request types. The |response| | 56 // These "Process.." methods handle specific request types. The |response| |
58 // dictionary is pre-filled by ProcessMessage() with the parts of the | 57 // dictionary is pre-filled by ProcessMessage() with the parts of the |
59 // response already known ("id" and "type" fields). | 58 // response already known ("id" and "type" fields). |
60 void ProcessHello( | 59 void ProcessHello( |
61 scoped_ptr<base::DictionaryValue> message, | 60 scoped_ptr<base::DictionaryValue> message, |
62 scoped_ptr<base::DictionaryValue> response); | 61 scoped_ptr<base::DictionaryValue> response); |
63 void ProcessClearPairedClients( | 62 void ProcessClearPairedClients( |
64 scoped_ptr<base::DictionaryValue> message, | 63 scoped_ptr<base::DictionaryValue> message, |
65 scoped_ptr<base::DictionaryValue> response); | 64 scoped_ptr<base::DictionaryValue> response); |
66 void ProcessDeletePairedClient( | 65 void ProcessDeletePairedClient( |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 123 |
125 void OnError(); | 124 void OnError(); |
126 | 125 |
127 void Stop(); | 126 void Stop(); |
128 | 127 |
129 // Returns true if the request was successfully delegated to the elevated | 128 // Returns true if the request was successfully delegated to the elevated |
130 // host and false otherwise. | 129 // host and false otherwise. |
131 bool DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message); | 130 bool DelegateToElevatedHost(scoped_ptr<base::DictionaryValue> message); |
132 | 131 |
133 #if defined(OS_WIN) | 132 #if defined(OS_WIN) |
| 133 class ElevatedChannelEventHandler |
| 134 : public extensions::NativeMessagingChannel::EventHandler { |
| 135 public: |
| 136 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host); |
| 137 |
| 138 virtual void OnMessage(scoped_ptr<base::Value> message) OVERRIDE; |
| 139 virtual void OnDisconnect() OVERRIDE; |
| 140 private: |
| 141 Me2MeNativeMessagingHost* parent_; |
| 142 }; |
| 143 |
134 // Create and connect to an elevated host process if necessary. | 144 // Create and connect to an elevated host process if necessary. |
135 // |elevated_channel_| will contain the native messaging channel to the | 145 // |elevated_channel_| will contain the native messaging channel to the |
136 // elevated host if the function succeeds. | 146 // elevated host if the function succeeds. |
137 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated(); | 147 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated(); |
138 | 148 |
139 // Callback to process messages from the elevated host through | |
140 // |elevated_channel_|. | |
141 void ProcessDelegateResponse(scoped_ptr<base::DictionaryValue> message); | |
142 | |
143 // Disconnect and shut down the elevated host. | 149 // Disconnect and shut down the elevated host. |
144 void DisconnectElevatedHost(); | 150 void DisconnectElevatedHost(); |
145 | 151 |
146 // Native messaging channel used to communicate with the elevated host. | 152 // Native messaging channel used to communicate with the elevated host. |
147 scoped_ptr<NativeMessagingChannel> elevated_channel_; | 153 scoped_ptr<extensions::NativeMessagingChannel> elevated_channel_; |
| 154 |
| 155 // Native messaging event handler used to process responses from the elevated |
| 156 // host. |
| 157 scoped_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; |
148 | 158 |
149 // Timer to control the lifetime of the elevated host. | 159 // Timer to control the lifetime of the elevated host. |
150 base::OneShotTimer<Me2MeNativeMessagingHost> elevated_host_timer_; | 160 base::OneShotTimer<Me2MeNativeMessagingHost> elevated_host_timer_; |
151 #endif // defined(OS_WIN) | 161 #endif // defined(OS_WIN) |
152 | 162 |
153 bool needs_elevation_; | 163 bool needs_elevation_; |
154 | 164 |
155 // Handle of the parent window. | 165 // Handle of the parent window. |
156 intptr_t parent_window_handle_; | 166 intptr_t parent_window_handle_; |
157 | 167 |
158 base::Closure quit_closure_; | 168 base::Closure quit_closure_; |
159 | 169 |
160 // Native messaging channel used to communicate with the native message | 170 // Native messaging channel used to communicate with the native message |
161 // client. | 171 // client. |
162 scoped_ptr<NativeMessagingChannel> channel_; | 172 scoped_ptr<extensions::NativeMessagingChannel> channel_; |
163 scoped_refptr<DaemonController> daemon_controller_; | 173 scoped_refptr<DaemonController> daemon_controller_; |
164 | 174 |
165 // Used to load and update the paired clients for this host. | 175 // Used to load and update the paired clients for this host. |
166 scoped_refptr<protocol::PairingRegistry> pairing_registry_; | 176 scoped_refptr<protocol::PairingRegistry> pairing_registry_; |
167 | 177 |
168 // Used to exchange the service account authorization code for credentials. | 178 // Used to exchange the service account authorization code for credentials. |
169 scoped_ptr<OAuthClient> oauth_client_; | 179 scoped_ptr<OAuthClient> oauth_client_; |
170 | 180 |
171 base::ThreadChecker thread_checker_; | 181 base::ThreadChecker thread_checker_; |
172 | 182 |
173 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; | 183 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; |
174 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; | 184 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; |
175 | 185 |
176 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); | 186 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); |
177 }; | 187 }; |
178 | 188 |
179 } // namespace remoting | 189 } // namespace remoting |
180 | 190 |
181 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ | 191 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ |
OLD | NEW |