| Index: public/platform/WebDataProducerHandle.h
|
| diff --git a/public/platform/WebDataProducerHandle.h b/public/platform/WebDataProducerHandle.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7a6344e4e9f6482a289fa6c356f2a541d04ff7a4
|
| --- /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>
|
| +#include <stdint.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 = uint32_t;
|
| + static const Flags FlagNone = 0;
|
| +
|
| + enum Result {
|
| + Ok,
|
| + ShouldWait,
|
| + AlreadyClosed,
|
| + 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
|
|
|