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

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

Issue 2400563002: Adds Mojo IDL. (Closed)
Patch Set: implements messagepipe Created 4 years, 2 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/MojoHandleWatcher.h"
6
7 #include "public/platform/WebTaskRunner.h"
8
9 namespace blink {
10
11 class MojoHandleWatcher::RunReadyCallbackTask : public WebTaskRunner::Task {
12 public:
13 RunReadyCallbackTask(MojoHandleWatcher* watcher, MojoResult result)
14 : m_watcher(watcher), m_result(result) {}
15 void run() final { m_watcher->runReadyCallback(m_result); }
16
17 private:
18 MojoHandleWatcher* m_watcher;
19 MojoResult m_result;
20 };
21
22 MojoHandleWatcher::MojoHandleWatcher(WebTaskRunner* taskRunner)
23 : m_taskRunner(taskRunner), m_handle(MOJO_HANDLE_INVALID) {}
24
25 MojoHandleWatcher::~MojoHandleWatcher() {
26 DCHECK(m_taskRunner->runsTasksOnCurrentThread());
27
28 if (m_handle != MOJO_HANDLE_INVALID)
29 cancel();
30 }
31
32 MojoResult MojoHandleWatcher::start(MojoHandle handle,
33 MojoHandleSignals signals,
34 std::unique_ptr<ReadyCallback> callback) {
35 DCHECK(m_taskRunner->runsTasksOnCurrentThread());
36 DCHECK(handle != MOJO_HANDLE_INVALID);
37 DCHECK(callback);
38
39 MojoResult result =
40 MojoWatch(handle, signals, &MojoHandleWatcher::onHandleReady,
41 reinterpret_cast<uintptr_t>(this));
42
43 if (result == MOJO_RESULT_OK) {
44 m_handle = handle;
45 m_callback = std::move(callback);
46 }
47 return result;
48 }
49
50 void MojoHandleWatcher::cancel() {
51 DCHECK(m_taskRunner->runsTasksOnCurrentThread());
52 DCHECK(m_handle != MOJO_HANDLE_INVALID);
53
54 MojoCancelWatch(m_handle, reinterpret_cast<uintptr_t>(this));
55 m_handle = MOJO_HANDLE_INVALID;
56 m_callback.reset();
57 }
58
59 void MojoHandleWatcher::onHandleReady(uintptr_t context,
60 MojoResult result,
61 MojoHandleSignalsState,
62 MojoWatchNotificationFlags) {
63 MojoHandleWatcher* watcher = reinterpret_cast<MojoHandleWatcher*>(context);
Ken Rockot(use gerrit already) 2016/10/18 15:47:10 Please explicitly document here that |watcher| is
alokp 2016/10/18 16:48:37 Done.
64 if (watcher->m_taskRunner->runsTasksOnCurrentThread()) {
65 watcher->runReadyCallback(result);
66 } else {
67 watcher->m_taskRunner->postTask(BLINK_FROM_HERE,
68 new RunReadyCallbackTask(watcher, result));
69 }
70 }
71
72 void MojoHandleWatcher::runReadyCallback(MojoResult result) {
73 DCHECK(m_taskRunner->runsTasksOnCurrentThread());
74 (*m_callback)(result);
75 }
76
77 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698