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

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

Issue 558403002: Remote Assistance on Chrome OS Part II - Native Messaging renaming (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows host Created 6 years, 3 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 #include "remoting/host/setup/me2me_native_messaging_host.h" 5 #include "remoting/host/setup/me2me_native_messaging_host.h"
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/callback_helpers.h" 11 #include "base/callback_helpers.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/stringize_macros.h" 14 #include "base/strings/stringize_macros.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "base/values.h" 18 #include "base/values.h"
19 #include "google_apis/gaia/gaia_oauth_client.h" 19 #include "google_apis/gaia/gaia_oauth_client.h"
20 #include "google_apis/google_api_keys.h" 20 #include "google_apis/google_api_keys.h"
21 #include "ipc/ipc_channel.h" 21 #include "ipc/ipc_channel.h"
22 #include "net/base/net_util.h" 22 #include "net/base/net_util.h"
23 #include "remoting/base/rsa_key_pair.h" 23 #include "remoting/base/rsa_key_pair.h"
24 #include "remoting/host/native_messaging/pipe_messaging_channel.h"
24 #include "remoting/host/pin_hash.h" 25 #include "remoting/host/pin_hash.h"
25 #include "remoting/host/setup/oauth_client.h" 26 #include "remoting/host/setup/oauth_client.h"
26 #include "remoting/protocol/pairing_registry.h" 27 #include "remoting/protocol/pairing_registry.h"
27 28
28 #if defined(OS_WIN) 29 #if defined(OS_WIN)
29 #include <shellapi.h> 30 #include <shellapi.h>
30 #include "base/win/win_util.h" 31 #include "base/win/win_util.h"
31 #include "remoting/host/win/security_descriptor.h" 32 #include "remoting/host/win/security_descriptor.h"
32 #endif // defined(OS_WIN) 33 #endif // defined(OS_WIN)
33 34
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return result.Pass(); 66 return result.Pass();
66 } 67 }
67 68
68 } // namespace 69 } // namespace
69 70
70 namespace remoting { 71 namespace remoting {
71 72
72 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost( 73 Me2MeNativeMessagingHost::Me2MeNativeMessagingHost(
73 bool needs_elevation, 74 bool needs_elevation,
74 intptr_t parent_window_handle, 75 intptr_t parent_window_handle,
75 scoped_ptr<NativeMessagingChannel> channel, 76 scoped_ptr<extensions::NativeMessagingChannel> channel,
76 scoped_refptr<DaemonController> daemon_controller, 77 scoped_refptr<DaemonController> daemon_controller,
77 scoped_refptr<protocol::PairingRegistry> pairing_registry, 78 scoped_refptr<protocol::PairingRegistry> pairing_registry,
78 scoped_ptr<OAuthClient> oauth_client) 79 scoped_ptr<OAuthClient> oauth_client)
79 : needs_elevation_(needs_elevation), 80 : needs_elevation_(needs_elevation),
80 parent_window_handle_(parent_window_handle), 81 parent_window_handle_(parent_window_handle),
81 channel_(channel.Pass()), 82 channel_(channel.Pass()),
82 daemon_controller_(daemon_controller), 83 daemon_controller_(daemon_controller),
83 pairing_registry_(pairing_registry), 84 pairing_registry_(pairing_registry),
84 oauth_client_(oauth_client.Pass()), 85 oauth_client_(oauth_client.Pass()),
85 weak_factory_(this) { 86 weak_factory_(this) {
86 weak_ptr_ = weak_factory_.GetWeakPtr(); 87 weak_ptr_ = weak_factory_.GetWeakPtr();
87 } 88 }
88 89
89 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() { 90 Me2MeNativeMessagingHost::~Me2MeNativeMessagingHost() {
90 DCHECK(thread_checker_.CalledOnValidThread()); 91 DCHECK(thread_checker_.CalledOnValidThread());
91 } 92 }
92 93
93 void Me2MeNativeMessagingHost::Start( 94 void Me2MeNativeMessagingHost::Start(
94 const base::Closure& quit_closure) { 95 const base::Closure& quit_closure) {
95 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK(thread_checker_.CalledOnValidThread());
97 DCHECK(!quit_closure.is_null());
96 98
97 quit_closure_ = quit_closure; 99 quit_closure_ = quit_closure;
98 100
99 channel_->Start( 101 channel_->Start(this);
100 base::Bind(&Me2MeNativeMessagingHost::ProcessRequest, weak_ptr_),
101 base::Bind(&Me2MeNativeMessagingHost::Stop, weak_ptr_));
102 } 102 }
103 103
104 void Me2MeNativeMessagingHost::ProcessRequest( 104 void Me2MeNativeMessagingHost::OnMessage(scoped_ptr<base::Value> message) {
105 scoped_ptr<base::DictionaryValue> message) {
106 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
107 106
107 scoped_ptr<base::DictionaryValue> message_dict(
108 static_cast<base::DictionaryValue*>(message.release()));
108 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue()); 109 scoped_ptr<base::DictionaryValue> response(new base::DictionaryValue());
109 110
110 // If the client supplies an ID, it will expect it in the response. This 111 // If the client supplies an ID, it will expect it in the response. This
111 // might be a string or a number, so cope with both. 112 // might be a string or a number, so cope with both.
112 const base::Value* id; 113 const base::Value* id;
113 if (message->Get("id", &id)) 114 if (message_dict->Get("id", &id))
114 response->Set("id", id->DeepCopy()); 115 response->Set("id", id->DeepCopy());
115 116
116 std::string type; 117 std::string type;
117 if (!message->GetString("type", &type)) { 118 if (!message_dict->GetString("type", &type)) {
118 LOG(ERROR) << "'type' not found"; 119 LOG(ERROR) << "'type' not found";
119 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); 120 channel_->SendMessage(scoped_ptr<base::Value>());
120 return; 121 return;
121 } 122 }
122 123
123 response->SetString("type", type + "Response"); 124 response->SetString("type", type + "Response");
124 125
125 if (type == "hello") { 126 if (type == "hello") {
126 ProcessHello(message.Pass(), response.Pass()); 127 ProcessHello(message_dict.Pass(), response.Pass());
127 } else if (type == "clearPairedClients") { 128 } else if (type == "clearPairedClients") {
128 ProcessClearPairedClients(message.Pass(), response.Pass()); 129 ProcessClearPairedClients(message_dict.Pass(), response.Pass());
129 } else if (type == "deletePairedClient") { 130 } else if (type == "deletePairedClient") {
130 ProcessDeletePairedClient(message.Pass(), response.Pass()); 131 ProcessDeletePairedClient(message_dict.Pass(), response.Pass());
131 } else if (type == "getHostName") { 132 } else if (type == "getHostName") {
132 ProcessGetHostName(message.Pass(), response.Pass()); 133 ProcessGetHostName(message_dict.Pass(), response.Pass());
133 } else if (type == "getPinHash") { 134 } else if (type == "getPinHash") {
134 ProcessGetPinHash(message.Pass(), response.Pass()); 135 ProcessGetPinHash(message_dict.Pass(), response.Pass());
135 } else if (type == "generateKeyPair") { 136 } else if (type == "generateKeyPair") {
136 ProcessGenerateKeyPair(message.Pass(), response.Pass()); 137 ProcessGenerateKeyPair(message_dict.Pass(), response.Pass());
137 } else if (type == "updateDaemonConfig") { 138 } else if (type == "updateDaemonConfig") {
138 ProcessUpdateDaemonConfig(message.Pass(), response.Pass()); 139 ProcessUpdateDaemonConfig(message_dict.Pass(), response.Pass());
139 } else if (type == "getDaemonConfig") { 140 } else if (type == "getDaemonConfig") {
140 ProcessGetDaemonConfig(message.Pass(), response.Pass()); 141 ProcessGetDaemonConfig(message_dict.Pass(), response.Pass());
141 } else if (type == "getPairedClients") { 142 } else if (type == "getPairedClients") {
142 ProcessGetPairedClients(message.Pass(), response.Pass()); 143 ProcessGetPairedClients(message_dict.Pass(), response.Pass());
143 } else if (type == "getUsageStatsConsent") { 144 } else if (type == "getUsageStatsConsent") {
144 ProcessGetUsageStatsConsent(message.Pass(), response.Pass()); 145 ProcessGetUsageStatsConsent(message_dict.Pass(), response.Pass());
145 } else if (type == "startDaemon") { 146 } else if (type == "startDaemon") {
146 ProcessStartDaemon(message.Pass(), response.Pass()); 147 ProcessStartDaemon(message_dict.Pass(), response.Pass());
147 } else if (type == "stopDaemon") { 148 } else if (type == "stopDaemon") {
148 ProcessStopDaemon(message.Pass(), response.Pass()); 149 ProcessStopDaemon(message_dict.Pass(), response.Pass());
149 } else if (type == "getDaemonState") { 150 } else if (type == "getDaemonState") {
150 ProcessGetDaemonState(message.Pass(), response.Pass()); 151 ProcessGetDaemonState(message_dict.Pass(), response.Pass());
151 } else if (type == "getHostClientId") { 152 } else if (type == "getHostClientId") {
152 ProcessGetHostClientId(message.Pass(), response.Pass()); 153 ProcessGetHostClientId(message_dict.Pass(), response.Pass());
153 } else if (type == "getCredentialsFromAuthCode") { 154 } else if (type == "getCredentialsFromAuthCode") {
154 ProcessGetCredentialsFromAuthCode(message.Pass(), response.Pass()); 155 ProcessGetCredentialsFromAuthCode(message_dict.Pass(), response.Pass());
155 } else { 156 } else {
156 LOG(ERROR) << "Unsupported request type: " << type; 157 LOG(ERROR) << "Unsupported request type: " << type;
157 OnError(); 158 OnError();
158 } 159 }
159 } 160 }
160 161
162 void Me2MeNativeMessagingHost::OnDisconnect() {
163 if (!quit_closure_.is_null()) {
Sergey Ulanov 2014/09/18 18:08:36 remove {}
kelvinp 2014/09/18 19:03:50 Done.
164 base::ResetAndReturn(&quit_closure_).Run();
165 }
166 }
167
161 void Me2MeNativeMessagingHost::ProcessHello( 168 void Me2MeNativeMessagingHost::ProcessHello(
162 scoped_ptr<base::DictionaryValue> message, 169 scoped_ptr<base::DictionaryValue> message,
163 scoped_ptr<base::DictionaryValue> response) { 170 scoped_ptr<base::DictionaryValue> response) {
164 DCHECK(thread_checker_.CalledOnValidThread()); 171 DCHECK(thread_checker_.CalledOnValidThread());
165 172
166 response->SetString("version", STRINGIZE(VERSION)); 173 response->SetString("version", STRINGIZE(VERSION));
167 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue()); 174 scoped_ptr<base::ListValue> supported_features_list(new base::ListValue());
168 supported_features_list->AppendStrings(std::vector<std::string>( 175 supported_features_list->AppendStrings(std::vector<std::string>(
169 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures))); 176 kSupportedFeatures, kSupportedFeatures + arraysize(kSupportedFeatures)));
170 response->Set("supportedFeatures", supported_features_list.release()); 177 response->Set("supportedFeatures", supported_features_list.release());
171 channel_->SendMessage(response.Pass()); 178 channel_->SendMessage(response.PassAs<base::Value>());
172 } 179 }
173 180
174 void Me2MeNativeMessagingHost::ProcessClearPairedClients( 181 void Me2MeNativeMessagingHost::ProcessClearPairedClients(
175 scoped_ptr<base::DictionaryValue> message, 182 scoped_ptr<base::DictionaryValue> message,
176 scoped_ptr<base::DictionaryValue> response) { 183 scoped_ptr<base::DictionaryValue> response) {
177 DCHECK(thread_checker_.CalledOnValidThread()); 184 DCHECK(thread_checker_.CalledOnValidThread());
178 185
179 if (needs_elevation_) { 186 if (needs_elevation_) {
180 if (!DelegateToElevatedHost(message.Pass())) 187 if (!DelegateToElevatedHost(message.Pass()))
181 SendBooleanResult(response.Pass(), false); 188 SendBooleanResult(response.Pass(), false);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 SendBooleanResult(response.Pass(), false); 226 SendBooleanResult(response.Pass(), false);
220 } 227 }
221 } 228 }
222 229
223 void Me2MeNativeMessagingHost::ProcessGetHostName( 230 void Me2MeNativeMessagingHost::ProcessGetHostName(
224 scoped_ptr<base::DictionaryValue> message, 231 scoped_ptr<base::DictionaryValue> message,
225 scoped_ptr<base::DictionaryValue> response) { 232 scoped_ptr<base::DictionaryValue> response) {
226 DCHECK(thread_checker_.CalledOnValidThread()); 233 DCHECK(thread_checker_.CalledOnValidThread());
227 234
228 response->SetString("hostname", net::GetHostName()); 235 response->SetString("hostname", net::GetHostName());
229 channel_->SendMessage(response.Pass()); 236 channel_->SendMessage(response.PassAs<base::Value>());
230 } 237 }
231 238
232 void Me2MeNativeMessagingHost::ProcessGetPinHash( 239 void Me2MeNativeMessagingHost::ProcessGetPinHash(
233 scoped_ptr<base::DictionaryValue> message, 240 scoped_ptr<base::DictionaryValue> message,
234 scoped_ptr<base::DictionaryValue> response) { 241 scoped_ptr<base::DictionaryValue> response) {
235 DCHECK(thread_checker_.CalledOnValidThread()); 242 DCHECK(thread_checker_.CalledOnValidThread());
236 243
237 std::string host_id; 244 std::string host_id;
238 if (!message->GetString("hostId", &host_id)) { 245 if (!message->GetString("hostId", &host_id)) {
239 LOG(ERROR) << "'hostId' not found: " << message; 246 LOG(ERROR) << "'hostId' not found: " << message;
240 OnError(); 247 OnError();
241 return; 248 return;
242 } 249 }
243 std::string pin; 250 std::string pin;
244 if (!message->GetString("pin", &pin)) { 251 if (!message->GetString("pin", &pin)) {
245 LOG(ERROR) << "'pin' not found: " << message; 252 LOG(ERROR) << "'pin' not found: " << message;
246 OnError(); 253 OnError();
247 return; 254 return;
248 } 255 }
249 response->SetString("hash", MakeHostPinHash(host_id, pin)); 256 response->SetString("hash", MakeHostPinHash(host_id, pin));
250 channel_->SendMessage(response.Pass()); 257 channel_->SendMessage(response.PassAs<base::Value>());
251 } 258 }
252 259
253 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair( 260 void Me2MeNativeMessagingHost::ProcessGenerateKeyPair(
254 scoped_ptr<base::DictionaryValue> message, 261 scoped_ptr<base::DictionaryValue> message,
255 scoped_ptr<base::DictionaryValue> response) { 262 scoped_ptr<base::DictionaryValue> response) {
256 DCHECK(thread_checker_.CalledOnValidThread()); 263 DCHECK(thread_checker_.CalledOnValidThread());
257 264
258 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate(); 265 scoped_refptr<RsaKeyPair> key_pair = RsaKeyPair::Generate();
259 response->SetString("privateKey", key_pair->ToString()); 266 response->SetString("privateKey", key_pair->ToString());
260 response->SetString("publicKey", key_pair->GetPublicKey()); 267 response->SetString("publicKey", key_pair->GetPublicKey());
261 channel_->SendMessage(response.Pass()); 268 channel_->SendMessage(response.PassAs<base::Value>());
262 } 269 }
263 270
264 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( 271 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig(
265 scoped_ptr<base::DictionaryValue> message, 272 scoped_ptr<base::DictionaryValue> message,
266 scoped_ptr<base::DictionaryValue> response) { 273 scoped_ptr<base::DictionaryValue> response) {
267 DCHECK(thread_checker_.CalledOnValidThread()); 274 DCHECK(thread_checker_.CalledOnValidThread());
268 275
269 scoped_ptr<base::DictionaryValue> config_dict = 276 scoped_ptr<base::DictionaryValue> config_dict =
270 ConfigDictionaryFromMessage(message.Pass()); 277 ConfigDictionaryFromMessage(message.Pass());
271 if (!config_dict) { 278 if (!config_dict) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 case DaemonController::STATE_STARTED: 381 case DaemonController::STATE_STARTED:
375 response->SetString("state", "STARTED"); 382 response->SetString("state", "STARTED");
376 break; 383 break;
377 case DaemonController::STATE_STOPPING: 384 case DaemonController::STATE_STOPPING:
378 response->SetString("state", "STOPPING"); 385 response->SetString("state", "STOPPING");
379 break; 386 break;
380 case DaemonController::STATE_UNKNOWN: 387 case DaemonController::STATE_UNKNOWN:
381 response->SetString("state", "UNKNOWN"); 388 response->SetString("state", "UNKNOWN");
382 break; 389 break;
383 } 390 }
384 channel_->SendMessage(response.Pass()); 391 channel_->SendMessage(response.PassAs<base::Value>());
385 } 392 }
386 393
387 void Me2MeNativeMessagingHost::ProcessGetHostClientId( 394 void Me2MeNativeMessagingHost::ProcessGetHostClientId(
388 scoped_ptr<base::DictionaryValue> message, 395 scoped_ptr<base::DictionaryValue> message,
389 scoped_ptr<base::DictionaryValue> response) { 396 scoped_ptr<base::DictionaryValue> response) {
390 DCHECK(thread_checker_.CalledOnValidThread()); 397 DCHECK(thread_checker_.CalledOnValidThread());
391 398
392 response->SetString("clientId", google_apis::GetOAuth2ClientID( 399 response->SetString("clientId", google_apis::GetOAuth2ClientID(
393 google_apis::CLIENT_REMOTING_HOST)); 400 google_apis::CLIENT_REMOTING_HOST));
394 channel_->SendMessage(response.Pass()); 401 channel_->SendMessage(response.PassAs<base::Value>());
395 } 402 }
396 403
397 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode( 404 void Me2MeNativeMessagingHost::ProcessGetCredentialsFromAuthCode(
398 scoped_ptr<base::DictionaryValue> message, 405 scoped_ptr<base::DictionaryValue> message,
399 scoped_ptr<base::DictionaryValue> response) { 406 scoped_ptr<base::DictionaryValue> response) {
400 DCHECK(thread_checker_.CalledOnValidThread()); 407 DCHECK(thread_checker_.CalledOnValidThread());
401 408
402 std::string auth_code; 409 std::string auth_code;
403 if (!message->GetString("authorizationCode", &auth_code)) { 410 if (!message->GetString("authorizationCode", &auth_code)) {
404 LOG(ERROR) << "'authorizationCode' string not found."; 411 LOG(ERROR) << "'authorizationCode' string not found.";
(...skipping 16 matching lines...) Expand all
421 void Me2MeNativeMessagingHost::SendConfigResponse( 428 void Me2MeNativeMessagingHost::SendConfigResponse(
422 scoped_ptr<base::DictionaryValue> response, 429 scoped_ptr<base::DictionaryValue> response,
423 scoped_ptr<base::DictionaryValue> config) { 430 scoped_ptr<base::DictionaryValue> config) {
424 DCHECK(thread_checker_.CalledOnValidThread()); 431 DCHECK(thread_checker_.CalledOnValidThread());
425 432
426 if (config) { 433 if (config) {
427 response->Set("config", config.release()); 434 response->Set("config", config.release());
428 } else { 435 } else {
429 response->Set("config", base::Value::CreateNullValue()); 436 response->Set("config", base::Value::CreateNullValue());
430 } 437 }
431 channel_->SendMessage(response.Pass()); 438 channel_->SendMessage(response.PassAs<base::Value>());
432 } 439 }
433 440
434 void Me2MeNativeMessagingHost::SendPairedClientsResponse( 441 void Me2MeNativeMessagingHost::SendPairedClientsResponse(
435 scoped_ptr<base::DictionaryValue> response, 442 scoped_ptr<base::DictionaryValue> response,
436 scoped_ptr<base::ListValue> pairings) { 443 scoped_ptr<base::ListValue> pairings) {
437 DCHECK(thread_checker_.CalledOnValidThread()); 444 DCHECK(thread_checker_.CalledOnValidThread());
438 445
439 response->Set("pairedClients", pairings.release()); 446 response->Set("pairedClients", pairings.release());
440 channel_->SendMessage(response.Pass()); 447 channel_->SendMessage(response.PassAs<base::Value>());
441 } 448 }
442 449
443 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse( 450 void Me2MeNativeMessagingHost::SendUsageStatsConsentResponse(
444 scoped_ptr<base::DictionaryValue> response, 451 scoped_ptr<base::DictionaryValue> response,
445 const DaemonController::UsageStatsConsent& consent) { 452 const DaemonController::UsageStatsConsent& consent) {
446 DCHECK(thread_checker_.CalledOnValidThread()); 453 DCHECK(thread_checker_.CalledOnValidThread());
447 454
448 response->SetBoolean("supported", consent.supported); 455 response->SetBoolean("supported", consent.supported);
449 response->SetBoolean("allowed", consent.allowed); 456 response->SetBoolean("allowed", consent.allowed);
450 response->SetBoolean("setByPolicy", consent.set_by_policy); 457 response->SetBoolean("setByPolicy", consent.set_by_policy);
451 channel_->SendMessage(response.Pass()); 458 channel_->SendMessage(response.PassAs<base::Value>());
452 } 459 }
453 460
454 void Me2MeNativeMessagingHost::SendAsyncResult( 461 void Me2MeNativeMessagingHost::SendAsyncResult(
455 scoped_ptr<base::DictionaryValue> response, 462 scoped_ptr<base::DictionaryValue> response,
456 DaemonController::AsyncResult result) { 463 DaemonController::AsyncResult result) {
457 DCHECK(thread_checker_.CalledOnValidThread()); 464 DCHECK(thread_checker_.CalledOnValidThread());
458 465
459 switch (result) { 466 switch (result) {
460 case DaemonController::RESULT_OK: 467 case DaemonController::RESULT_OK:
461 response->SetString("result", "OK"); 468 response->SetString("result", "OK");
462 break; 469 break;
463 case DaemonController::RESULT_FAILED: 470 case DaemonController::RESULT_FAILED:
464 response->SetString("result", "FAILED"); 471 response->SetString("result", "FAILED");
465 break; 472 break;
466 case DaemonController::RESULT_CANCELLED: 473 case DaemonController::RESULT_CANCELLED:
467 response->SetString("result", "CANCELLED"); 474 response->SetString("result", "CANCELLED");
468 break; 475 break;
469 case DaemonController::RESULT_FAILED_DIRECTORY: 476 case DaemonController::RESULT_FAILED_DIRECTORY:
470 response->SetString("result", "FAILED_DIRECTORY"); 477 response->SetString("result", "FAILED_DIRECTORY");
471 break; 478 break;
472 } 479 }
473 channel_->SendMessage(response.Pass()); 480 channel_->SendMessage(response.PassAs<base::Value>());
474 } 481 }
475 482
476 void Me2MeNativeMessagingHost::SendBooleanResult( 483 void Me2MeNativeMessagingHost::SendBooleanResult(
477 scoped_ptr<base::DictionaryValue> response, bool result) { 484 scoped_ptr<base::DictionaryValue> response, bool result) {
478 DCHECK(thread_checker_.CalledOnValidThread()); 485 DCHECK(thread_checker_.CalledOnValidThread());
479 486
480 response->SetBoolean("result", result); 487 response->SetBoolean("result", result);
481 channel_->SendMessage(response.Pass()); 488 channel_->SendMessage(response.PassAs<base::Value>());
482 } 489 }
483 490
484 void Me2MeNativeMessagingHost::SendCredentialsResponse( 491 void Me2MeNativeMessagingHost::SendCredentialsResponse(
485 scoped_ptr<base::DictionaryValue> response, 492 scoped_ptr<base::DictionaryValue> response,
486 const std::string& user_email, 493 const std::string& user_email,
487 const std::string& refresh_token) { 494 const std::string& refresh_token) {
488 DCHECK(thread_checker_.CalledOnValidThread()); 495 DCHECK(thread_checker_.CalledOnValidThread());
489 496
490 response->SetString("userEmail", user_email); 497 response->SetString("userEmail", user_email);
491 response->SetString("refreshToken", refresh_token); 498 response->SetString("refreshToken", refresh_token);
492 channel_->SendMessage(response.Pass()); 499 channel_->SendMessage(response.PassAs<base::Value>());
493 } 500 }
494 501
495 void Me2MeNativeMessagingHost::OnError() { 502 void Me2MeNativeMessagingHost::OnError() {
496 // Trigger a host shutdown by sending a NULL message. 503 // Trigger a host shutdown by sending a NULL message.
497 channel_->SendMessage(scoped_ptr<base::DictionaryValue>()); 504 channel_->SendMessage(scoped_ptr<base::Value>());
498 } 505 }
499 506
500 void Me2MeNativeMessagingHost::Stop() { 507 void Me2MeNativeMessagingHost::Stop() {
501 DCHECK(thread_checker_.CalledOnValidThread()); 508 DCHECK(thread_checker_.CalledOnValidThread());
502 509
503 if (!quit_closure_.is_null()) 510 if (!quit_closure_.is_null())
504 base::ResetAndReturn(&quit_closure_).Run(); 511 base::ResetAndReturn(&quit_closure_).Run();
505 } 512 }
506 513
507 #if defined(OS_WIN) 514 #if defined(OS_WIN)
515 Me2MeNativeMessagingHost::ElevatedChannelEventHandler::
516 ElevatedChannelEventHandler(Me2MeNativeMessagingHost* host)
517 : parent_(host) {
518 }
519
520 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnMessage(
521 scoped_ptr<base::Value> message) {
522 DCHECK(parent_->thread_checker_.CalledOnValidThread());
523
524 // Simply pass along the response from the elevated host to the client.
525 parent_->channel_->SendMessage(message.Pass());
526 }
527
528 void Me2MeNativeMessagingHost::ElevatedChannelEventHandler::OnDisconnect() {
529 parent_->OnDisconnect();
530 }
508 531
509 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( 532 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(
510 scoped_ptr<base::DictionaryValue> message) { 533 scoped_ptr<base::DictionaryValue> message) {
511 DCHECK(thread_checker_.CalledOnValidThread()); 534 DCHECK(thread_checker_.CalledOnValidThread());
512 535
513 EnsureElevatedHostCreated(); 536 EnsureElevatedHostCreated();
514 537
515 // elevated_channel_ will be null if user rejects the UAC request. 538 // elevated_channel_ will be null if user rejects the UAC request.
516 if (elevated_channel_) 539 if (elevated_channel_)
517 elevated_channel_->SendMessage(message.Pass()); 540 elevated_channel_->SendMessage(message.PassAs<base::Value>());
518 541
519 return elevated_channel_ != NULL; 542 return elevated_channel_ != NULL;
520 } 543 }
521 544
522 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() { 545 void Me2MeNativeMessagingHost::EnsureElevatedHostCreated() {
523 DCHECK(thread_checker_.CalledOnValidThread()); 546 DCHECK(thread_checker_.CalledOnValidThread());
524 DCHECK(needs_elevation_); 547 DCHECK(needs_elevation_);
525 548
526 if (elevated_channel_) 549 if (elevated_channel_)
527 return; 550 return;
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) { 674 if (!::ConnectNamedPipe(delegate_read_handle.Get(), NULL)) {
652 DWORD error = ::GetLastError(); 675 DWORD error = ::GetLastError();
653 if (error != ERROR_PIPE_CONNECTED) { 676 if (error != ERROR_PIPE_CONNECTED) {
654 PLOG(ERROR) << "Unable to connect '" << output_pipe_name << "'"; 677 PLOG(ERROR) << "Unable to connect '" << output_pipe_name << "'";
655 OnError(); 678 OnError();
656 return; 679 return;
657 } 680 }
658 } 681 }
659 682
660 // Set up the native messaging channel to talk to the elevated host. 683 // Set up the native messaging channel to talk to the elevated host.
661 // Note that input for the elevate channel is output forthe elevated host. 684 // Note that input for the elevated channel is output for the elevated host.
662 elevated_channel_.reset(new NativeMessagingChannel( 685 scoped_ptr<PipeMessagingChannel> channel(
663 base::File(delegate_read_handle.Take()), 686 new PipeMessagingChannel(base::File(delegate_read_handle.Take()),
664 base::File(delegate_write_handle.Take()))); 687 base::File(delegate_write_handle.Take())));
688 elevated_channel_.reset(
689 static_cast<extensions::NativeMessagingChannel*>(channel.release()));
Sergey Ulanov 2014/09/18 18:08:36 Why static_cast<> instead of PassAs<>? But I think
kelvinp 2014/09/18 19:03:50 Done.
665 690
666 elevated_channel_->Start( 691 elevated_channel_event_handler_.reset(
667 base::Bind(&Me2MeNativeMessagingHost::ProcessDelegateResponse, weak_ptr_), 692 new Me2MeNativeMessagingHost::ElevatedChannelEventHandler(this));
668 base::Bind(&Me2MeNativeMessagingHost::Stop, weak_ptr_)); 693 elevated_channel_->Start(elevated_channel_event_handler_.get());
669 694
670 elevated_host_timer_.Start( 695 elevated_host_timer_.Start(
671 FROM_HERE, base::TimeDelta::FromSeconds(kElevatedHostTimeoutSeconds), 696 FROM_HERE, base::TimeDelta::FromSeconds(kElevatedHostTimeoutSeconds),
672 this, &Me2MeNativeMessagingHost::DisconnectElevatedHost); 697 this, &Me2MeNativeMessagingHost::DisconnectElevatedHost);
673 } 698 }
674 699
675 void Me2MeNativeMessagingHost::ProcessDelegateResponse(
676 scoped_ptr<base::DictionaryValue> message) {
677 DCHECK(thread_checker_.CalledOnValidThread());
678
679 // Simply pass along the response from the elevated host to the client.
680 channel_->SendMessage(message.Pass());
681 }
682
683 void Me2MeNativeMessagingHost::DisconnectElevatedHost() { 700 void Me2MeNativeMessagingHost::DisconnectElevatedHost() {
684 DCHECK(thread_checker_.CalledOnValidThread()); 701 DCHECK(thread_checker_.CalledOnValidThread());
685 702
686 // This will send an EOF to the elevated host, triggering its shutdown. 703 // This will send an EOF to the elevated host, triggering its shutdown.
687 elevated_channel_.reset(); 704 elevated_channel_.reset();
688 } 705 }
689 706
690 #else // defined(OS_WIN) 707 #else // defined(OS_WIN)
691 708
692 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( 709 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(
693 scoped_ptr<base::DictionaryValue> message) { 710 scoped_ptr<base::DictionaryValue> message) {
694 NOTREACHED(); 711 NOTREACHED();
695 return false; 712 return false;
696 } 713 }
697 714
698 #endif // !defined(OS_WIN) 715 #endif // !defined(OS_WIN)
699 716
700 } // namespace remoting 717 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698