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

Side by Side Diff: mojo/edk/system/node_channel.cc

Issue 1811433002: [mojo-edk] Expose notification source to MojoWatch callbacks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/request_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/edk/system/node_channel.h" 5 #include "mojo/edk/system/node_channel.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "mojo/edk/system/channel.h" 12 #include "mojo/edk/system/channel.h"
13 #include "mojo/edk/system/request_context.h"
13 14
14 namespace mojo { 15 namespace mojo {
15 namespace edk { 16 namespace edk {
16 17
17 namespace { 18 namespace {
18 19
19 template <typename T> 20 template <typename T>
20 T Align(T t) { 21 T Align(T t) {
21 const auto k = kChannelMessageAlignment; 22 const auto k = kChannelMessageAlignment;
22 return t + (k - (t % k)) % k; 23 return t + (k - (t % k)) % k;
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 341
341 NodeChannel::~NodeChannel() { 342 NodeChannel::~NodeChannel() {
342 ShutDown(); 343 ShutDown();
343 } 344 }
344 345
345 void NodeChannel::OnChannelMessage(const void* payload, 346 void NodeChannel::OnChannelMessage(const void* payload,
346 size_t payload_size, 347 size_t payload_size,
347 ScopedPlatformHandleVectorPtr handles) { 348 ScopedPlatformHandleVectorPtr handles) {
348 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 349 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
349 350
351 RequestContext request_context(RequestContext::Source::SYSTEM);
352
350 #if defined(OS_WIN) 353 #if defined(OS_WIN)
351 // If we receive handles from a known process, rewrite them to our own 354 // If we receive handles from a known process, rewrite them to our own
352 // process. This can occur when a privileged node receives handles directly 355 // process. This can occur when a privileged node receives handles directly
353 // from a privileged descendant. 356 // from a privileged descendant.
354 { 357 {
355 base::AutoLock lock(remote_process_handle_lock_); 358 base::AutoLock lock(remote_process_handle_lock_);
356 if (handles && remote_process_handle_ != base::kNullProcessHandle) { 359 if (handles && remote_process_handle_ != base::kNullProcessHandle) {
357 if (!Channel::Message::RewriteHandles(remote_process_handle_, 360 if (!Channel::Message::RewriteHandles(remote_process_handle_,
358 base::GetCurrentProcessHandle(), 361 base::GetCurrentProcessHandle(),
359 handles->data(), handles->size())) { 362 handles->data(), handles->size())) {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 << static_cast<uint32_t>(header->type) << " from node " 514 << static_cast<uint32_t>(header->type) << " from node "
512 << remote_node_name_; 515 << remote_node_name_;
513 delegate_->OnChannelError(remote_node_name_); 516 delegate_->OnChannelError(remote_node_name_);
514 break; 517 break;
515 } 518 }
516 } 519 }
517 520
518 void NodeChannel::OnChannelError() { 521 void NodeChannel::OnChannelError() {
519 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 522 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
520 523
524 RequestContext request_context(RequestContext::Source::SYSTEM);
525
521 ShutDown(); 526 ShutDown();
522 // |OnChannelError()| may cause |this| to be destroyed, but still need access 527 // |OnChannelError()| may cause |this| to be destroyed, but still need access
523 // to the name name after that destruction. So may a copy of 528 // to the name name after that destruction. So may a copy of
524 // |remote_node_name_| so it can be used if |this| becomes destroyed. 529 // |remote_node_name_| so it can be used if |this| becomes destroyed.
525 ports::NodeName node_name = remote_node_name_; 530 ports::NodeName node_name = remote_node_name_;
526 delegate_->OnChannelError(node_name); 531 delegate_->OnChannelError(node_name);
527 } 532 }
528 533
529 void NodeChannel::WriteChannelMessage(Channel::MessagePtr message) { 534 void NodeChannel::WriteChannelMessage(Channel::MessagePtr message) {
530 #if defined(OS_WIN) 535 #if defined(OS_WIN)
(...skipping 23 matching lines...) Expand all
554 559
555 base::AutoLock lock(channel_lock_); 560 base::AutoLock lock(channel_lock_);
556 if (!channel_) 561 if (!channel_)
557 DLOG(ERROR) << "Dropping message on closed channel."; 562 DLOG(ERROR) << "Dropping message on closed channel.";
558 else 563 else
559 channel_->Write(std::move(message)); 564 channel_->Write(std::move(message));
560 } 565 }
561 566
562 } // namespace edk 567 } // namespace edk
563 } // namespace mojo 568 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/request_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698