OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef WebDataProducerHandle_h |
| 6 #define WebDataProducerHandle_h |
| 7 |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
| 10 |
| 11 namespace blink { |
| 12 |
| 13 // WebDataProducerHandle represents the "producer" side of a data pipe. A user |
| 14 // can write data to it. Destroying a handle will close the associated pipe. |
| 15 // This data type is basically a wrapper of mojo data pipe producer handle. |
| 16 // See mojo/public/c/system/data_pipe.h for details. |
| 17 // |
| 18 // Note: |
| 19 // - If you register a client, all of write / beginWrite / endWrite / |
| 20 // registerClient / unregisterClient must be called on the same thread. |
| 21 // Client notification is called on the thread. |
| 22 class WebDataProducerHandle { |
| 23 public: |
| 24 // This corresponds to MojoWriteDataFlags. |
| 25 using Flags = uint32_t; |
| 26 static const Flags FlagNone = 0; |
| 27 |
| 28 enum Result { |
| 29 Ok, |
| 30 ShouldWait, |
| 31 AlreadyClosed, |
| 32 UnexpectedError, |
| 33 }; |
| 34 |
| 35 // Client gets notification from the pipe. |
| 36 class Client { |
| 37 public: |
| 38 virtual ~Client() { } |
| 39 // The associated handle gets writable. |
| 40 virtual void didGetWritable() = 0; |
| 41 }; |
| 42 |
| 43 virtual ~WebDataProducerHandle() { } |
| 44 |
| 45 // Writes |data| up to |size| bytes. The actual written size will be |
| 46 // stored in |*writtenSize|. This function cannot be called when a two-phase |
| 47 // read is in progress. |
| 48 // Returns AlreadyClosed when the read end is already closed. |
| 49 virtual Result write(const void* data, size_t /* size */, Flags, size_t* wri
ttenSize) { return UnexpectedError; } |
| 50 |
| 51 // Begins a two-phase write. On success, the function stores a pointer to |
| 52 // |*buffer| into which the caller can write data of length |*available|. |
| 53 // Returns AlreadyClosed when the read end is already closed. |
| 54 // On fail, you don't have to (and should not) call endWrite, because the |
| 55 // write session implicitly ends in that case. |
| 56 virtual Result beginWrite(void** buffer, Flags, size_t* available) { return
UnexpectedError; } |
| 57 |
| 58 // Ends a two-phase write. |
| 59 // |writtenSize| indicates the actual written size. |
| 60 virtual Result endWrite(size_t writtenSize) { return UnexpectedError; } |
| 61 |
| 62 // Registers |client| to this handle. The client must not be null and must |
| 63 // be valid until it is unregistered (or the handle is destructed). |
| 64 // Only one registration can be made for a handle at a time. |
| 65 virtual void registerClient(Client* /* client */) { } |
| 66 |
| 67 // Unregisters |client| from this handle. |
| 68 virtual void unregisterClient() { } |
| 69 }; |
| 70 |
| 71 } // namespace blink |
| 72 |
| 73 #endif // WebDataProducerHandle_h |
OLD | NEW |