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

Side by Side Diff: remoting/host/setup/me2me_native_messaging_host.h

Issue 2153313002: Refactoring Me2MeNativeMessagingHost to implement NativeMessageHost interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@process_helper
Patch Set: Merging upstream changes. Created 4 years, 4 months 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 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 <cstdint> 8 #include <cstdint>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "extensions/browser/api/messaging/native_message_host.h"
18 #include "extensions/browser/api/messaging/native_messaging_channel.h" 19 #include "extensions/browser/api/messaging/native_messaging_channel.h"
19 #include "remoting/host/native_messaging/log_message_handler.h"
20 #include "remoting/host/setup/daemon_controller.h" 20 #include "remoting/host/setup/daemon_controller.h"
21 #include "remoting/host/setup/oauth_client.h" 21 #include "remoting/host/setup/oauth_client.h"
22 22
23 namespace base { 23 namespace base {
24 class DictionaryValue; 24 class DictionaryValue;
25 class ListValue; 25 class ListValue;
26 class SingleThreadTaskRunner;
26 } // namespace base 27 } // namespace base
27 28
28 namespace gaia { 29 namespace gaia {
29 class GaiaOAuthClient; 30 class GaiaOAuthClient;
30 } // namespace gaia 31 } // namespace gaia
31 32
32 namespace remoting { 33 namespace remoting {
33 34
34 namespace protocol { 35 namespace protocol {
35 class PairingRegistry; 36 class PairingRegistry;
36 } // namespace protocol 37 } // namespace protocol
37 38
39 class ChromotingHostContext;
40 class LogMessageHandler;
41
38 // Implementation of the me2me native messaging host. 42 // Implementation of the me2me native messaging host.
39 class Me2MeNativeMessagingHost 43 class Me2MeNativeMessagingHost : public extensions::NativeMessageHost {
40 : public extensions::NativeMessagingChannel::EventHandler {
41 public: 44 public:
42 Me2MeNativeMessagingHost( 45 Me2MeNativeMessagingHost(
43 bool needs_elevation, 46 bool needs_elevation,
44 intptr_t parent_window_handle, 47 intptr_t parent_window_handle,
45 std::unique_ptr<extensions::NativeMessagingChannel> channel, 48 std::unique_ptr<ChromotingHostContext> host_context,
46 scoped_refptr<DaemonController> daemon_controller, 49 scoped_refptr<DaemonController> daemon_controller,
47 scoped_refptr<protocol::PairingRegistry> pairing_registry, 50 scoped_refptr<protocol::PairingRegistry> pairing_registry,
48 std::unique_ptr<OAuthClient> oauth_client); 51 std::unique_ptr<OAuthClient> oauth_client);
49 ~Me2MeNativeMessagingHost() override; 52 ~Me2MeNativeMessagingHost() override;
50 53
51 void Start(const base::Closure& quit_closure); 54 // extensions::NativeMessageHost implementation.
52 55 void OnMessage(const std::string& message) override;
53 // extensions::NativeMessagingChannel::EventHandler implementation 56 void Start(extensions::NativeMessageHost::Client* client) override;
54 void OnMessage(std::unique_ptr<base::Value> message) override; 57 scoped_refptr<base::SingleThreadTaskRunner> task_runner() const override;
55 void OnDisconnect() override;
56 58
57 private: 59 private:
58 // These "Process.." methods handle specific request types. The |response| 60 // These "Process.." methods handle specific request types. The |response|
59 // dictionary is pre-filled by ProcessMessage() with the parts of the 61 // dictionary is pre-filled by ProcessMessage() with the parts of the
60 // response already known ("id" and "type" fields). 62 // response already known ("id" and "type" fields).
61 void ProcessHello(std::unique_ptr<base::DictionaryValue> message, 63 void ProcessHello(std::unique_ptr<base::DictionaryValue> message,
62 std::unique_ptr<base::DictionaryValue> response); 64 std::unique_ptr<base::DictionaryValue> response);
63 void ProcessClearPairedClients( 65 void ProcessClearPairedClients(
64 std::unique_ptr<base::DictionaryValue> message, 66 std::unique_ptr<base::DictionaryValue> message,
65 std::unique_ptr<base::DictionaryValue> response); 67 std::unique_ptr<base::DictionaryValue> response);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void SendUsageStatsConsentResponse( 109 void SendUsageStatsConsentResponse(
108 std::unique_ptr<base::DictionaryValue> response, 110 std::unique_ptr<base::DictionaryValue> response,
109 const DaemonController::UsageStatsConsent& consent); 111 const DaemonController::UsageStatsConsent& consent);
110 void SendAsyncResult(std::unique_ptr<base::DictionaryValue> response, 112 void SendAsyncResult(std::unique_ptr<base::DictionaryValue> response,
111 DaemonController::AsyncResult result); 113 DaemonController::AsyncResult result);
112 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response, 114 void SendBooleanResult(std::unique_ptr<base::DictionaryValue> response,
113 bool result); 115 bool result);
114 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response, 116 void SendCredentialsResponse(std::unique_ptr<base::DictionaryValue> response,
115 const std::string& user_email, 117 const std::string& user_email,
116 const std::string& refresh_token); 118 const std::string& refresh_token);
119 void SendMessageToClient(std::unique_ptr<base::Value> message) const;
117 120
118 void OnError(); 121 void OnError(const std::string& error_message);
119
120 void Stop();
121 122
122 // Returns true if the request was successfully delegated to the elevated 123 // Returns true if the request was successfully delegated to the elevated
123 // host and false otherwise. 124 // host and false otherwise.
124 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message); 125 bool DelegateToElevatedHost(std::unique_ptr<base::DictionaryValue> message);
125 126
126 #if defined(OS_WIN) 127 #if defined(OS_WIN)
127 class ElevatedChannelEventHandler 128 class ElevatedChannelEventHandler
128 : public extensions::NativeMessagingChannel::EventHandler { 129 : public extensions::NativeMessagingChannel::EventHandler {
129 public: 130 public:
130 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host); 131 ElevatedChannelEventHandler(extensions::NativeMessageHost::Client* client);
131 132
133 // extensions::NativeMessagingChannel::EventHandler implementation.
132 void OnMessage(std::unique_ptr<base::Value> message) override; 134 void OnMessage(std::unique_ptr<base::Value> message) override;
133 void OnDisconnect() override; 135 void OnDisconnect() override;
134 private: 136 private:
Sergey Ulanov 2016/08/01 18:45:19 nit: empty line above this one
joedow 2016/08/01 19:21:34 Done.
135 Me2MeNativeMessagingHost* parent_; 137 extensions::NativeMessageHost::Client* client_;
138
139 base::ThreadChecker thread_checker_;
136 }; 140 };
137 141
138 // Create and connect to an elevated host process if necessary. 142 // Create and connect to an elevated host process if necessary.
139 // |elevated_channel_| will contain the native messaging channel to the 143 // |elevated_channel_| will contain the native messaging channel to the
140 // elevated host if the function succeeds. 144 // elevated host if the function succeeds.
141 void EnsureElevatedHostCreated(); 145 void EnsureElevatedHostCreated();
142 146
143 // Disconnect and shut down the elevated host. 147 // Disconnect and shut down the elevated host.
144 void DisconnectElevatedHost(); 148 void DisconnectElevatedHost();
145 149
146 // Native messaging channel used to communicate with the elevated host. 150 // Native messaging channel used to communicate with the elevated host.
147 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_; 151 std::unique_ptr<extensions::NativeMessagingChannel> elevated_channel_;
148 152
149 // Native messaging event handler used to process responses from the elevated 153 // Native messaging event handler used to process responses from the elevated
150 // host. 154 // host.
151 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_; 155 std::unique_ptr<ElevatedChannelEventHandler> elevated_channel_event_handler_;
152 156
153 // Timer to control the lifetime of the elevated host. 157 // Timer to control the lifetime of the elevated host.
154 base::OneShotTimer elevated_host_timer_; 158 base::OneShotTimer elevated_host_timer_;
155 #endif // defined(OS_WIN) 159 #endif // defined(OS_WIN)
156 160
157 bool needs_elevation_; 161 bool needs_elevation_;
158 162
159 #if defined(OS_WIN) 163 #if defined(OS_WIN)
160 // Handle of the parent window. 164 // Handle of the parent window.
161 intptr_t parent_window_handle_; 165 intptr_t parent_window_handle_;
162 #endif // defined(OS_WIN) 166 #endif // defined(OS_WIN)
163 167
164 base::Closure quit_closure_; 168 extensions::NativeMessageHost::Client* client_;
169 std::unique_ptr<ChromotingHostContext> host_context_;
165 170
166 // Native messaging channel used to communicate with the native message 171 std::unique_ptr<LogMessageHandler> log_message_handler_;
167 // client.
168 std::unique_ptr<extensions::NativeMessagingChannel> channel_;
169
170 LogMessageHandler log_message_handler_;
171 172
172 scoped_refptr<DaemonController> daemon_controller_; 173 scoped_refptr<DaemonController> daemon_controller_;
173 174
174 // Used to load and update the paired clients for this host. 175 // Used to load and update the paired clients for this host.
175 scoped_refptr<protocol::PairingRegistry> pairing_registry_; 176 scoped_refptr<protocol::PairingRegistry> pairing_registry_;
176 177
177 // Used to exchange the service account authorization code for credentials. 178 // Used to exchange the service account authorization code for credentials.
178 std::unique_ptr<OAuthClient> oauth_client_; 179 std::unique_ptr<OAuthClient> oauth_client_;
179 180
180 base::ThreadChecker thread_checker_;
181
182 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_; 181 base::WeakPtr<Me2MeNativeMessagingHost> weak_ptr_;
183 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_; 182 base::WeakPtrFactory<Me2MeNativeMessagingHost> weak_factory_;
184 183
185 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost); 184 DISALLOW_COPY_AND_ASSIGN(Me2MeNativeMessagingHost);
186 }; 185 };
187 186
188 } // namespace remoting 187 } // namespace remoting
189 188
190 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_ 189 #endif // REMOTING_HOST_SETUP_ME2ME_NATIVE_MESSAGING_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698