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

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

Issue 2207153004: Fixing a hang in the native messaging hosts on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding a comment describing why we need to cancel the pending read operation on Windows. 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
« no previous file with comments | « remoting/host/native_messaging/native_messaging_reader_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 6
7 #include <cstdint> 7 #include <cstdint>
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 response->Set("supportedFeatures", supported_features_list.release()); 186 response->Set("supportedFeatures", supported_features_list.release());
187 SendMessageToClient(std::move(response)); 187 SendMessageToClient(std::move(response));
188 } 188 }
189 189
190 void Me2MeNativeMessagingHost::ProcessClearPairedClients( 190 void Me2MeNativeMessagingHost::ProcessClearPairedClients(
191 std::unique_ptr<base::DictionaryValue> message, 191 std::unique_ptr<base::DictionaryValue> message,
192 std::unique_ptr<base::DictionaryValue> response) { 192 std::unique_ptr<base::DictionaryValue> response) {
193 DCHECK(task_runner()->BelongsToCurrentThread()); 193 DCHECK(task_runner()->BelongsToCurrentThread());
194 194
195 if (needs_elevation_) { 195 if (needs_elevation_) {
196 if (!DelegateToElevatedHost(std::move(message))) 196 if (!DelegateToElevatedHost(std::move(message))) {
197 SendBooleanResult(std::move(response), false); 197 SendBooleanResult(std::move(response), false);
198 }
198 return; 199 return;
199 } 200 }
200 201
201 if (pairing_registry_.get()) { 202 if (pairing_registry_.get()) {
202 pairing_registry_->ClearAllPairings( 203 pairing_registry_->ClearAllPairings(
203 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_, 204 base::Bind(&Me2MeNativeMessagingHost::SendBooleanResult, weak_ptr_,
204 base::Passed(&response))); 205 base::Passed(&response)));
205 } else { 206 } else {
206 SendBooleanResult(std::move(response), false); 207 SendBooleanResult(std::move(response), false);
207 } 208 }
208 } 209 }
209 210
210 void Me2MeNativeMessagingHost::ProcessDeletePairedClient( 211 void Me2MeNativeMessagingHost::ProcessDeletePairedClient(
211 std::unique_ptr<base::DictionaryValue> message, 212 std::unique_ptr<base::DictionaryValue> message,
212 std::unique_ptr<base::DictionaryValue> response) { 213 std::unique_ptr<base::DictionaryValue> response) {
213 DCHECK(task_runner()->BelongsToCurrentThread()); 214 DCHECK(task_runner()->BelongsToCurrentThread());
214 215
215 if (needs_elevation_) { 216 if (needs_elevation_) {
216 if (!DelegateToElevatedHost(std::move(message))) 217 if (!DelegateToElevatedHost(std::move(message))) {
217 SendBooleanResult(std::move(response), false); 218 SendBooleanResult(std::move(response), false);
219 }
218 return; 220 return;
219 } 221 }
220 222
221 std::string client_id; 223 std::string client_id;
222 if (!message->GetString(protocol::PairingRegistry::kClientIdKey, 224 if (!message->GetString(protocol::PairingRegistry::kClientIdKey,
223 &client_id)) { 225 &client_id)) {
224 OnError("'" + std::string(protocol::PairingRegistry::kClientIdKey) + 226 OnError("'" + std::string(protocol::PairingRegistry::kClientIdKey) +
225 "' string not found."); 227 "' string not found.");
226 return; 228 return;
227 } 229 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 response->SetString("publicKey", key_pair->GetPublicKey()); 279 response->SetString("publicKey", key_pair->GetPublicKey());
278 SendMessageToClient(std::move(response)); 280 SendMessageToClient(std::move(response));
279 } 281 }
280 282
281 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig( 283 void Me2MeNativeMessagingHost::ProcessUpdateDaemonConfig(
282 std::unique_ptr<base::DictionaryValue> message, 284 std::unique_ptr<base::DictionaryValue> message,
283 std::unique_ptr<base::DictionaryValue> response) { 285 std::unique_ptr<base::DictionaryValue> response) {
284 DCHECK(task_runner()->BelongsToCurrentThread()); 286 DCHECK(task_runner()->BelongsToCurrentThread());
285 287
286 if (needs_elevation_) { 288 if (needs_elevation_) {
287 if (!DelegateToElevatedHost(std::move(message))) 289 if (!DelegateToElevatedHost(std::move(message))) {
288 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); 290 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
291 }
289 return; 292 return;
290 } 293 }
291 294
292 std::unique_ptr<base::DictionaryValue> config_dict = 295 std::unique_ptr<base::DictionaryValue> config_dict =
293 ConfigDictionaryFromMessage(std::move(message)); 296 ConfigDictionaryFromMessage(std::move(message));
294 if (!config_dict) { 297 if (!config_dict) {
295 OnError("'config' dictionary not found"); 298 OnError("'config' dictionary not found");
296 return; 299 return;
297 } 300 }
298 301
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse, 340 base::Bind(&Me2MeNativeMessagingHost::SendUsageStatsConsentResponse,
338 weak_ptr_, base::Passed(&response))); 341 weak_ptr_, base::Passed(&response)));
339 } 342 }
340 343
341 void Me2MeNativeMessagingHost::ProcessStartDaemon( 344 void Me2MeNativeMessagingHost::ProcessStartDaemon(
342 std::unique_ptr<base::DictionaryValue> message, 345 std::unique_ptr<base::DictionaryValue> message,
343 std::unique_ptr<base::DictionaryValue> response) { 346 std::unique_ptr<base::DictionaryValue> response) {
344 DCHECK(task_runner()->BelongsToCurrentThread()); 347 DCHECK(task_runner()->BelongsToCurrentThread());
345 348
346 if (needs_elevation_) { 349 if (needs_elevation_) {
347 if (!DelegateToElevatedHost(std::move(message))) 350 if (!DelegateToElevatedHost(std::move(message))) {
348 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); 351 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
352 }
349 return; 353 return;
350 } 354 }
351 355
352 bool consent; 356 bool consent;
353 if (!message->GetBoolean("consent", &consent)) { 357 if (!message->GetBoolean("consent", &consent)) {
354 OnError("'consent' not found."); 358 OnError("'consent' not found.");
355 return; 359 return;
356 } 360 }
357 361
358 std::unique_ptr<base::DictionaryValue> config_dict = 362 std::unique_ptr<base::DictionaryValue> config_dict =
359 ConfigDictionaryFromMessage(std::move(message)); 363 ConfigDictionaryFromMessage(std::move(message));
360 if (!config_dict) { 364 if (!config_dict) {
361 OnError("'config' dictionary not found"); 365 OnError("'config' dictionary not found");
362 return; 366 return;
363 } 367 }
364 368
365 daemon_controller_->SetConfigAndStart( 369 daemon_controller_->SetConfigAndStart(
366 std::move(config_dict), consent, 370 std::move(config_dict), consent,
367 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, 371 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_,
368 base::Passed(&response))); 372 base::Passed(&response)));
369 } 373 }
370 374
371 void Me2MeNativeMessagingHost::ProcessStopDaemon( 375 void Me2MeNativeMessagingHost::ProcessStopDaemon(
372 std::unique_ptr<base::DictionaryValue> message, 376 std::unique_ptr<base::DictionaryValue> message,
373 std::unique_ptr<base::DictionaryValue> response) { 377 std::unique_ptr<base::DictionaryValue> response) {
374 DCHECK(task_runner()->BelongsToCurrentThread()); 378 DCHECK(task_runner()->BelongsToCurrentThread());
375 379
376 if (needs_elevation_) { 380 if (needs_elevation_) {
377 if (!DelegateToElevatedHost(std::move(message))) 381 if (!DelegateToElevatedHost(std::move(message))) {
378 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED); 382 SendAsyncResult(std::move(response), DaemonController::RESULT_FAILED);
383 }
379 return; 384 return;
380 } 385 }
381 386
382 daemon_controller_->Stop( 387 daemon_controller_->Stop(
383 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_, 388 base::Bind(&Me2MeNativeMessagingHost::SendAsyncResult, weak_ptr_,
384 base::Passed(&response))); 389 base::Passed(&response)));
385 } 390 }
386 391
387 void Me2MeNativeMessagingHost::ProcessGetDaemonState( 392 void Me2MeNativeMessagingHost::ProcessGetDaemonState(
388 std::unique_ptr<base::DictionaryValue> message, 393 std::unique_ptr<base::DictionaryValue> message,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return; 586 return;
582 587
583 base::win::ScopedHandle read_handle; 588 base::win::ScopedHandle read_handle;
584 base::win::ScopedHandle write_handle; 589 base::win::ScopedHandle write_handle;
585 // Get the name of the binary to launch. 590 // Get the name of the binary to launch.
586 base::FilePath binary = base::CommandLine::ForCurrentProcess()->GetProgram(); 591 base::FilePath binary = base::CommandLine::ForCurrentProcess()->GetProgram();
587 ProcessLaunchResult result = LaunchNativeMessagingHostProcess( 592 ProcessLaunchResult result = LaunchNativeMessagingHostProcess(
588 binary, parent_window_handle_, 593 binary, parent_window_handle_,
589 /*elevate_process=*/true, &read_handle, &write_handle); 594 /*elevate_process=*/true, &read_handle, &write_handle);
590 if (result != PROCESS_LAUNCH_RESULT_SUCCESS) { 595 if (result != PROCESS_LAUNCH_RESULT_SUCCESS) {
591 if (result != PROCESS_LAUNCH_RESULT_CANCELLED) {
592 OnError(std::string());
593 }
594 return; 596 return;
595 } 597 }
596 598
597 // Set up the native messaging channel to talk to the elevated host. 599 // Set up the native messaging channel to talk to the elevated host.
598 // Note that input for the elevated channel is output for the elevated host. 600 // Note that input for the elevated channel is output for the elevated host.
599 elevated_channel_.reset(new PipeMessagingChannel( 601 elevated_channel_.reset(new PipeMessagingChannel(
600 base::File(read_handle.Take()), base::File(write_handle.Take()))); 602 base::File(read_handle.Take()), base::File(write_handle.Take())));
601 603
602 elevated_channel_event_handler_.reset( 604 elevated_channel_event_handler_.reset(
603 new Me2MeNativeMessagingHost::ElevatedChannelEventHandler(client_)); 605 new Me2MeNativeMessagingHost::ElevatedChannelEventHandler(client_));
(...skipping 15 matching lines...) Expand all
619 621
620 bool Me2MeNativeMessagingHost::DelegateToElevatedHost( 622 bool Me2MeNativeMessagingHost::DelegateToElevatedHost(
621 std::unique_ptr<base::DictionaryValue> message) { 623 std::unique_ptr<base::DictionaryValue> message) {
622 NOTREACHED(); 624 NOTREACHED();
623 return false; 625 return false;
624 } 626 }
625 627
626 #endif // !defined(OS_WIN) 628 #endif // !defined(OS_WIN)
627 629
628 } // namespace remoting 630 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/native_messaging/native_messaging_reader_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698