Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/public/cpp/system/watcher.h" | 5 #include "mojo/public/cpp/system/watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/trace_event/heap_profiler.h" | |
| 10 #include "mojo/public/c/system/functions.h" | 11 #include "mojo/public/c/system/functions.h" |
| 11 | 12 |
| 12 namespace mojo { | 13 namespace mojo { |
| 13 | 14 |
| 14 Watcher::Watcher(scoped_refptr<base::SingleThreadTaskRunner> runner) | 15 Watcher::Watcher(const tracked_objects::Location& from_here, |
| 16 scoped_refptr<base::SingleThreadTaskRunner> runner) | |
| 15 : task_runner_(std::move(runner)), | 17 : task_runner_(std::move(runner)), |
| 16 is_default_task_runner_(task_runner_ == | 18 is_default_task_runner_(task_runner_ == |
| 17 base::ThreadTaskRunnerHandle::Get()), | 19 base::ThreadTaskRunnerHandle::Get()), |
| 20 heap_profiler_tag_(from_here.file_name()), | |
| 18 weak_factory_(this) { | 21 weak_factory_(this) { |
| 19 DCHECK(task_runner_->BelongsToCurrentThread()); | 22 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 20 weak_self_ = weak_factory_.GetWeakPtr(); | 23 weak_self_ = weak_factory_.GetWeakPtr(); |
| 21 } | 24 } |
| 22 | 25 |
| 23 Watcher::~Watcher() { | 26 Watcher::~Watcher() { |
| 24 if(IsWatching()) | 27 if(IsWatching()) |
| 25 Cancel(); | 28 Cancel(); |
| 26 } | 29 } |
| 27 | 30 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 void Watcher::OnHandleReady(MojoResult result) { | 75 void Watcher::OnHandleReady(MojoResult result) { |
| 73 DCHECK(thread_checker_.CalledOnValidThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
| 74 | 77 |
| 75 ReadyCallback callback = callback_; | 78 ReadyCallback callback = callback_; |
| 76 if (result == MOJO_RESULT_CANCELLED) { | 79 if (result == MOJO_RESULT_CANCELLED) { |
| 77 handle_.set_value(kInvalidHandleValue); | 80 handle_.set_value(kInvalidHandleValue); |
| 78 callback_.Reset(); | 81 callback_.Reset(); |
| 79 } | 82 } |
| 80 | 83 |
| 81 // NOTE: It's legal for |callback| to delete |this|. | 84 // NOTE: It's legal for |callback| to delete |this|. |
| 82 if (!callback.is_null()) | 85 if (!callback.is_null()) { |
| 86 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event(heap_profiler_tag_); | |
|
Jay Civelli
2017/01/13 01:09:28
I moved the macro here so it catches allocation wh
ssid
2017/01/13 01:46:17
I just noticed the post task.
Yes this would captu
| |
| 83 callback.Run(result); | 87 callback.Run(result); |
| 88 } | |
| 84 } | 89 } |
| 85 | 90 |
| 86 // static | 91 // static |
| 87 void Watcher::CallOnHandleReady(uintptr_t context, | 92 void Watcher::CallOnHandleReady(uintptr_t context, |
| 88 MojoResult result, | 93 MojoResult result, |
| 89 MojoHandleSignalsState signals_state, | 94 MojoHandleSignalsState signals_state, |
| 90 MojoWatchNotificationFlags flags) { | 95 MojoWatchNotificationFlags flags) { |
| 91 // NOTE: It is safe to assume the Watcher still exists because this callback | 96 // NOTE: It is safe to assume the Watcher still exists because this callback |
| 92 // will never be run after the Watcher's destructor. | 97 // will never be run after the Watcher's destructor. |
| 93 // | 98 // |
| 94 // TODO: Maybe we should also expose |signals_state| through the Watcher API. | 99 // TODO: Maybe we should also expose |signals_state| through the Watcher API. |
| 95 // Current HandleWatcher users have no need for it, so it's omitted here. | 100 // Current HandleWatcher users have no need for it, so it's omitted here. |
| 96 Watcher* watcher = reinterpret_cast<Watcher*>(context); | 101 Watcher* watcher = reinterpret_cast<Watcher*>(context); |
| 102 | |
| 97 if ((flags & MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM) && | 103 if ((flags & MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM) && |
| 98 watcher->task_runner_->RunsTasksOnCurrentThread() && | 104 watcher->task_runner_->RunsTasksOnCurrentThread() && |
| 99 watcher->is_default_task_runner_) { | 105 watcher->is_default_task_runner_) { |
| 100 // System notifications will trigger from the task runner passed to | 106 // System notifications will trigger from the task runner passed to |
| 101 // mojo::edk::InitIPCSupport(). In Chrome this happens to always be the | 107 // mojo::edk::InitIPCSupport(). In Chrome this happens to always be the |
| 102 // default task runner for the IO thread. | 108 // default task runner for the IO thread. |
| 103 watcher->OnHandleReady(result); | 109 watcher->OnHandleReady(result); |
| 104 } else { | 110 } else { |
| 105 watcher->task_runner_->PostTask( | 111 watcher->task_runner_->PostTask( |
| 106 FROM_HERE, | 112 FROM_HERE, |
| 107 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); | 113 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); |
| 108 } | 114 } |
| 109 } | 115 } |
| 110 | 116 |
| 111 } // namespace mojo | 117 } // namespace mojo |
| OLD | NEW |