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

Side by Side Diff: mojo/message_pump/handle_watcher.cc

Issue 1508053003: Show the callstack that a nontransferable message pipe was first used if it's erroneously sent later (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove frame fix Created 5 years 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/runner/android/main.cc » ('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 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 "mojo/message_pump/handle_watcher.h" 5 #include "mojo/message_pump/handle_watcher.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/singleton.h" 14 #include "base/memory/singleton.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/profiler/scoped_tracker.h" 17 #include "base/profiler/scoped_tracker.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/synchronization/lock.h" 19 #include "base/synchronization/lock.h"
20 #include "base/thread_task_runner_handle.h" 20 #include "base/thread_task_runner_handle.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "mojo/message_pump/message_pump_mojo.h" 23 #include "mojo/message_pump/message_pump_mojo.h"
24 #include "mojo/message_pump/message_pump_mojo_handler.h" 24 #include "mojo/message_pump/message_pump_mojo_handler.h"
25 #include "mojo/message_pump/time_helper.h" 25 #include "mojo/message_pump/time_helper.h"
26 #include "mojo/public/c/system/message_pipe.h"
26 27
27 namespace mojo { 28 namespace mojo {
28 namespace common { 29 namespace common {
29 30
30 typedef int WatcherID; 31 typedef int WatcherID;
31 32
32 namespace { 33 namespace {
33 34
34 const char kWatcherThreadName[] = "handle-watcher-thread"; 35 const char kWatcherThreadName[] = "handle-watcher-thread";
35 36
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 const base::Callback<void(MojoResult)>& callback) { 451 const base::Callback<void(MojoResult)>& callback) {
451 DCHECK(handle.is_valid()); 452 DCHECK(handle.is_valid());
452 DCHECK_NE(MOJO_HANDLE_SIGNAL_NONE, handle_signals); 453 DCHECK_NE(MOJO_HANDLE_SIGNAL_NONE, handle_signals);
453 454
454 // Need to clear the state before creating a new one. 455 // Need to clear the state before creating a new one.
455 state_.reset(); 456 state_.reset();
456 if (MessagePumpMojo::IsCurrent()) { 457 if (MessagePumpMojo::IsCurrent()) {
457 state_.reset(new SameThreadWatchingState( 458 state_.reset(new SameThreadWatchingState(
458 this, handle, handle_signals, deadline, callback)); 459 this, handle, handle_signals, deadline, callback));
459 } else { 460 } else {
461 #if !defined(OFFICIAL_BUILD)
462 // Just for making debugging non-transferable message pipes easier. Since
463 // they can't be sent after they're read/written/listened to,
464 // MessagePipeDispatcher saves the callstack of when it's "bound" to a
465 // pipe id. Triggering a read here, instead of later in the PostTask, means
466 // we have a callstack that is useful to check if the pipe is erronously
467 // attempted to be sent.
468 uint32_t temp = 0;
469 MojoReadMessage(handle.value(), nullptr, &temp, nullptr, nullptr,
470 MOJO_READ_MESSAGE_FLAG_NONE);
471 #endif
460 state_.reset(new SecondaryThreadWatchingState( 472 state_.reset(new SecondaryThreadWatchingState(
461 this, handle, handle_signals, deadline, callback)); 473 this, handle, handle_signals, deadline, callback));
462 } 474 }
463 } 475 }
464 476
465 void HandleWatcher::Stop() { 477 void HandleWatcher::Stop() {
466 state_.reset(); 478 state_.reset();
467 } 479 }
468 480
469 } // namespace common 481 } // namespace common
470 } // namespace mojo 482 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/runner/android/main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698