Chromium Code Reviews| Index: public/platform/WebDataProducerHandle.h |
| diff --git a/public/platform/WebDataProducerHandle.h b/public/platform/WebDataProducerHandle.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ad28bc4ccc8625e202a83db4d9641038efc3bca |
| --- /dev/null |
| +++ b/public/platform/WebDataProducerHandle.h |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2015 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 WebDataProducerHandle_h |
| +#define WebDataProducerHandle_h |
| + |
| +#include <stddef.h> |
| + |
| +namespace blink { |
| + |
| +// WebDataProducerHandle represents the "producer" side of a data pipe. A user |
| +// can write data to it. Destroying a handle will close the associated pipe. |
| +// This data type is basically a wrapper of mojo data pipe producer handle. |
| +// See mojo/public/c/system/data_pipe.h for details. |
| +// |
| +// Note: |
| +// - If you register a client, all of write / beginWrite / endWrite / |
| +// registerClient / unregisterClient must be called on the same thread. |
| +// Client notification is called on the thread. |
| +class WebDataProducerHandle { |
| +public: |
| + // This corresponds to MojoWriteDataFlags. |
| + using Flags = unsigned; |
|
tyoshino (SeeGerritForStatus)
2015/01/23 08:24:20
uint32_t?
yhirano
2015/01/23 10:49:02
Good catch! I fixed WebDataConsumerHandle::Flags a
|
| + static const Flags FlagNone = 0; |
| + |
| + enum Result { |
| + Ok, |
| + ShouldWait, |
| + AlreadyClosed, |
| + ResourceExhausted, |
|
tyoshino (SeeGerritForStatus)
2015/01/23 08:24:20
can we see MOJO_RESULT_RESOURCE_EXHAUSTED on write
yhirano
2015/01/23 10:49:02
No. Removed.
|
| + UnexpectedError, |
| + }; |
| + |
| + // Client gets notification from the pipe. |
| + class Client { |
| + public: |
| + virtual ~Client() { } |
| + // The associated handle gets writable. |
| + virtual void didGetWritable() = 0; |
| + }; |
| + |
| + virtual ~WebDataProducerHandle() { } |
| + |
| + // Writes |data| up to |size| bytes. The actual written size will be |
| + // stored in |*writtenSize|. This function cannot be called when a two-phase |
| + // read is in progress. |
| + // Returns AlreadyClosed when the read end is already closed. |
| + virtual Result write(const void* data, size_t /* size */, Flags, size_t* writtenSize) { return UnexpectedError; } |
| + |
| + // Begins a two-phase write. On success, the function stores a pointer to |
| + // |*buffer| into which the caller can write data of length |*available|. |
| + // Returns AlreadyClosed when the read end is already closed. |
| + // On fail, you don't have to (and should not) call endWrite, because the |
| + // write session implicitly ends in that case. |
| + virtual Result beginWrite(void** buffer, Flags, size_t* available) { return UnexpectedError; } |
| + |
| + // Ends a two-phase write. |
| + // |writtenSize| indicates the actual written size. |
| + virtual Result endWrite(size_t writtenSize) { return UnexpectedError; } |
| + |
| + // Registers |client| to this handle. The client must not be null and must |
| + // 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 */) { } |
| + |
| + // Unregisters |client| from this handle. |
| + virtual void unregisterClient() { } |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // WebDataProducerHandle_h |