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

Unified Diff: public/platform/WebDataConsumerHandle.h

Issue 626803002: Introduce WebDataConsumerHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: public/platform/WebDataConsumerHandle.h
diff --git a/public/platform/WebDataConsumerHandle.h b/public/platform/WebDataConsumerHandle.h
new file mode 100644
index 0000000000000000000000000000000000000000..1f4bbad8c53faf11732a0de5d3febdbe4ca9c273
--- /dev/null
+++ b/public/platform/WebDataConsumerHandle.h
@@ -0,0 +1,73 @@
+// Copyright 2014 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.
+
+#ifndef WebDataConsumerHandle_h
+#define WebDataConsumerHandle_h
+
+#include <stdlib.h>
+
+namespace blink {
+
+// WebDataConsumerHandle represents the "consumer" side of a data pipe. A user
+// can read data from it.
+// This data type is basically a wrapper of mojo data pipe consumer handle.
+// See mojo/public/c/system/data_pipe.h for details.
+//
+// Note:
+// - If you register a client, all of read / beginRead / endRead /
+// registerClient / unregisterClient must be called on the same thread.
+// Client notification is called on the thread.
+class WebDataConsumerHandle {
+public:
+ using Flags = unsigned;
tyoshino (SeeGerritForStatus) 2014/10/06 16:12:25 say that this corresponds to MojoReadDataFlags
yhirano 2014/10/07 02:28:12 Done.
+ static const Flags FlagNone = 0;
+
+ enum Result {
+ Ok,
+ Done,
+ Busy,
+ ShouldWait,
+ ResourceExhausted,
+ UnexpectedError,
+ };
+
+ // Client gets notification from the pipe.
+ class Client {
+ public:
+ virtual ~Client() { }
+ // The associated handle gets readable.
+ virtual void didGetReadable() = 0;
+ };
+
+ virtual ~WebDataConsumerHandle() { }
+
+ // Reads data into |data| upto |size| bytes. The actual read size will be
+ // stored in |*readSize|. This function cannot be called when a two-phase
+ // read is in progress.
+ // Returns Done when it reaches to the end of the data.
+ virtual Result read(void* data, size_t /* size */, Flags, size_t* readSize) = 0;
+
+ // Begins a two-phase read. On success, the function stores a buffer that
+ // contains the read data of length |*available| into |*buffer|.
+ // Returns Done when it reaches to the end of the data.
+ // On fail, you don't have to (and should not) call endRead, because the
+ // read session implicitly ends in that case.
+ virtual Result beginRead(const void** buffer, Flags, size_t* available) = 0;
+
+ // Ends a two-phase read.
+ // |readSize| indicates the actual read size.
+ virtual Result endRead(size_t readSize) = 0;
+
+ // Register |client| to this handle. The client must not be null and must
tyoshino (SeeGerritForStatus) 2014/10/06 16:12:25 Registers
yhirano 2014/10/07 02:28:12 Done.
+ // be valid until it is unregistered (or the handle is destructed).
+ // Only one registration can be made for a handle at a time.
+ virtual void registerClient(Client* /* client */) = 0;
+
+ // Unregister |client| from this handle.
tyoshino (SeeGerritForStatus) 2014/10/06 16:12:25 Unregisters
yhirano 2014/10/07 02:28:12 Done.
+ virtual void unregisterClient() = 0;
+};
+
+} // namespace blink
+
+#endif // WebDataConsumerHandle_h
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698