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