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.ToString()), | |
|
ssid
2017/01/12 21:50:03
Can you please just use file_name() here instead o
Jay Civelli
2017/01/13 01:09:27
Done.
| |
| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 void Watcher::CallOnHandleReady(uintptr_t context, | 90 void Watcher::CallOnHandleReady(uintptr_t context, |
| 88 MojoResult result, | 91 MojoResult result, |
| 89 MojoHandleSignalsState signals_state, | 92 MojoHandleSignalsState signals_state, |
| 90 MojoWatchNotificationFlags flags) { | 93 MojoWatchNotificationFlags flags) { |
| 91 // NOTE: It is safe to assume the Watcher still exists because this callback | 94 // NOTE: It is safe to assume the Watcher still exists because this callback |
| 92 // will never be run after the Watcher's destructor. | 95 // will never be run after the Watcher's destructor. |
| 93 // | 96 // |
| 94 // TODO: Maybe we should also expose |signals_state| through the Watcher API. | 97 // 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. | 98 // Current HandleWatcher users have no need for it, so it's omitted here. |
| 96 Watcher* watcher = reinterpret_cast<Watcher*>(context); | 99 Watcher* watcher = reinterpret_cast<Watcher*>(context); |
| 100 | |
| 101 TRACE_HEAP_PROFILER_API_SCOPED_TASK_EXECUTION event( | |
| 102 watcher->heap_profiler_tag_.c_str()); | |
| 103 | |
| 97 if ((flags & MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM) && | 104 if ((flags & MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM) && |
| 98 watcher->task_runner_->RunsTasksOnCurrentThread() && | 105 watcher->task_runner_->RunsTasksOnCurrentThread() && |
| 99 watcher->is_default_task_runner_) { | 106 watcher->is_default_task_runner_) { |
| 100 // System notifications will trigger from the task runner passed to | 107 // System notifications will trigger from the task runner passed to |
| 101 // mojo::edk::InitIPCSupport(). In Chrome this happens to always be the | 108 // mojo::edk::InitIPCSupport(). In Chrome this happens to always be the |
| 102 // default task runner for the IO thread. | 109 // default task runner for the IO thread. |
| 103 watcher->OnHandleReady(result); | 110 watcher->OnHandleReady(result); |
| 104 } else { | 111 } else { |
| 105 watcher->task_runner_->PostTask( | 112 watcher->task_runner_->PostTask( |
| 106 FROM_HERE, | 113 FROM_HERE, |
| 107 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); | 114 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); |
| 108 } | 115 } |
| 109 } | 116 } |
| 110 | 117 |
| 111 } // namespace mojo | 118 } // namespace mojo |
| OLD | NEW |