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

Side by Side Diff: third_party/WebKit/Source/core/mojo/MojoWatcher.cpp

Issue 2400563002: Adds Mojo IDL. (Closed)
Patch Set: addressed comments Created 3 years, 11 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/mojo/MojoWatcher.h"
6
7 #include "bindings/core/v8/MojoWatchCallback.h"
8 #include "bindings/core/v8/ScriptState.h"
9 #include "core/dom/ExecutionContext.h"
10 #include "core/dom/ExecutionContextTask.h"
11
12 namespace blink {
13
14 MojoWatcher* MojoWatcher::create(mojo::Handle handle,
15 MojoHandleSignals signals,
16 MojoWatchCallback* callback,
17 ExecutionContext* taskRunner) {
18 MojoWatcher* watcher = new MojoWatcher(handle, callback, taskRunner);
19
20 MojoResult result =
21 MojoWatch(handle.value(), signals, &MojoWatcher::onHandleReady,
22 reinterpret_cast<uintptr_t>(watcher));
23 // TODO(alokp): Consider raising an exception.
24 // Current clients expect to recieve the initial error returned by MojoWatch
25 // via watch callback.
26 if (result != MOJO_RESULT_OK) {
27 watcher->m_taskRunner->postTask(
28 BLINK_FROM_HERE,
29 createSameThreadTask(&MojoWatcher::runReadyCallback,
30 wrapWeakPersistent(watcher), result));
31 }
32 return watcher;
33 }
34
35 MojoWatcher::MojoWatcher(mojo::Handle handle,
36 MojoWatchCallback* callback,
37 ExecutionContext* taskRunner)
38 : m_handle(handle), m_callback(this, callback), m_taskRunner(taskRunner) {}
39
40 MojoWatcher::~MojoWatcher() {
41 cancel();
jbroman 2017/01/10 20:46:31 Hold on, what stops this from being cancelled the
alokp 2017/01/11 21:53:02 Done.
42 }
43
44 MojoResult MojoWatcher::cancel() {
45 MojoResult result = MOJO_RESULT_OK;
46 if (m_handle.is_valid()) {
47 result =
48 MojoCancelWatch(m_handle.value(), reinterpret_cast<uintptr_t>(this));
49 m_handle = mojo::Handle();
50 }
51 return result;
52 }
53
54 DEFINE_TRACE_WRAPPERS(MojoWatcher) {
55 visitor->traceWrappers(m_callback);
56 }
57
58 void MojoWatcher::onHandleReady(uintptr_t context,
59 MojoResult result,
60 MojoHandleSignalsState,
jbroman 2017/01/10 20:46:31 Does script not need to know which signals are rea
alokp 2017/01/11 21:53:02 C API currently does not specify the signals for w
yzshen1 2017/01/12 23:38:34 I don't think it is super useful. I am fine not ha
61 MojoWatchNotificationFlags) {
62 // It is safe to assume the MojoWatcher still exists because this
63 // callback will never be run after MojoWatcher destructor,
64 // which cancels the watch.
65 MojoWatcher* watcher = reinterpret_cast<MojoWatcher*>(context);
66 watcher->m_taskRunner->postTask(
67 BLINK_FROM_HERE,
68 createCrossThreadTask(&MojoWatcher::runReadyCallback,
69 wrapCrossThreadWeakPersistent(watcher), result));
70 }
71
72 void MojoWatcher::runReadyCallback(MojoResult result) {
73 if (!m_handle.is_valid())
74 return;
75
76 if (result != MOJO_RESULT_OK)
77 cancel();
78
79 m_callback->call(this, result);
80 }
81
82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698