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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 114 } |
115 | 115 |
116 // NOTE: It's legal for |callback| to delete |this|. | 116 // NOTE: It's legal for |callback| to delete |this|. |
117 if (!callback.is_null()) | 117 if (!callback.is_null()) |
118 callback.Run(result); | 118 callback.Run(result); |
119 } | 119 } |
120 | 120 |
121 // static | 121 // static |
122 void Watcher::CallOnHandleReady(uintptr_t context, | 122 void Watcher::CallOnHandleReady(uintptr_t context, |
123 MojoResult result, | 123 MojoResult result, |
124 MojoHandleSignalsState signals_state) { | 124 MojoHandleSignalsState signals_state, |
| 125 MojoWatchNotificationFlags flags) { |
125 // NOTE: It is safe to assume the Watcher still exists because this callback | 126 // NOTE: It is safe to assume the Watcher still exists because this callback |
126 // will never be run after the Watcher's destructor. | 127 // will never be run after the Watcher's destructor. |
127 // | 128 // |
128 // TODO: Maybe we should also expose |signals_state| throught he Watcher API. | 129 // TODO: Maybe we should also expose |signals_state| throught he Watcher API. |
129 // Current HandleWatcher users have no need for it, so it's omitted here. | 130 // Current HandleWatcher users have no need for it, so it's omitted here. |
130 Watcher* watcher = reinterpret_cast<Watcher*>(context); | 131 Watcher* watcher = reinterpret_cast<Watcher*>(context); |
131 watcher->task_runner_->PostTask( | 132 if ((flags & MOJO_WATCH_NOTIFICATION_FLAG_FROM_SYSTEM) && |
132 FROM_HERE, | 133 watcher->task_runner_->RunsTasksOnCurrentThread()) { |
133 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); | 134 watcher->OnHandleReady(result); |
| 135 } else { |
| 136 watcher->task_runner_->PostTask( |
| 137 FROM_HERE, |
| 138 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); |
| 139 } |
134 } | 140 } |
135 | 141 |
136 } // namespace mojo | 142 } // namespace mojo |
OLD | NEW |