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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/mojo/MojoHandleWatcher.cpp
diff --git a/third_party/WebKit/Source/core/mojo/MojoHandleWatcher.cpp b/third_party/WebKit/Source/core/mojo/MojoHandleWatcher.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..3d0367431d4b071097c121325e069f90989baf5b
--- /dev/null
+++ b/third_party/WebKit/Source/core/mojo/MojoHandleWatcher.cpp
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/mojo/MojoHandleWatcher.h"
+
+#include "public/platform/WebTaskRunner.h"
+
+namespace blink {
+
+class MojoHandleWatcher::RunReadyCallbackTask : public WebTaskRunner::Task {
+ public:
+ RunReadyCallbackTask(MojoHandleWatcher* watcher, MojoResult result)
+ : m_watcher(watcher), m_result(result) {}
+ void run() final { m_watcher->runReadyCallback(m_result); }
+
+ private:
+ MojoHandleWatcher* m_watcher;
+ MojoResult m_result;
+};
+
+MojoHandleWatcher::MojoHandleWatcher(WebTaskRunner* taskRunner)
+ : m_taskRunner(taskRunner), m_handle(MOJO_HANDLE_INVALID) {}
+
+MojoHandleWatcher::~MojoHandleWatcher() {
+ DCHECK(m_taskRunner->runsTasksOnCurrentThread());
+
+ if (m_handle != MOJO_HANDLE_INVALID)
+ cancel();
+}
+
+MojoResult MojoHandleWatcher::start(MojoHandle handle,
+ MojoHandleSignals signals,
+ std::unique_ptr<ReadyCallback> callback) {
+ DCHECK(m_taskRunner->runsTasksOnCurrentThread());
+ DCHECK(handle != MOJO_HANDLE_INVALID);
+ DCHECK(callback);
+
+ MojoResult result =
+ MojoWatch(handle, signals, &MojoHandleWatcher::onHandleReady,
+ reinterpret_cast<uintptr_t>(this));
+
+ if (result == MOJO_RESULT_OK) {
+ m_handle = handle;
+ m_callback = std::move(callback);
+ }
+ return result;
+}
+
+void MojoHandleWatcher::cancel() {
+ DCHECK(m_taskRunner->runsTasksOnCurrentThread());
+ DCHECK(m_handle != MOJO_HANDLE_INVALID);
+
+ MojoCancelWatch(m_handle, reinterpret_cast<uintptr_t>(this));
+ m_handle = MOJO_HANDLE_INVALID;
+ m_callback.reset();
+}
+
+void MojoHandleWatcher::onHandleReady(uintptr_t context,
+ MojoResult result,
+ MojoHandleSignalsState,
+ MojoWatchNotificationFlags) {
+ 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.
+ if (watcher->m_taskRunner->runsTasksOnCurrentThread()) {
+ watcher->runReadyCallback(result);
+ } else {
+ watcher->m_taskRunner->postTask(BLINK_FROM_HERE,
+ new RunReadyCallbackTask(watcher, result));
+ }
+}
+
+void MojoHandleWatcher::runReadyCallback(MojoResult result) {
+ DCHECK(m_taskRunner->runsTasksOnCurrentThread());
+ (*m_callback)(result);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698