Chromium Code Reviews| 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 | |
| 10 namespace blink { | |
| 11 | |
| 12 // WebDataProducerHandle represents the "producer" side of a data pipe. A user | |
| 13 // can write data to it. Destroying a handle will close the associated pipe. | |
| 14 // This data type is basically a wrapper of mojo data pipe producer handle. | |
| 15 // See mojo/public/c/system/data_pipe.h for details. | |
| 16 // | |
| 17 // Note: | |
| 18 // - If you register a client, all of write / beginWrite / endWrite / | |
| 19 // registerClient / unregisterClient must be called on the same thread. | |
| 20 // Client notification is called on the thread. | |
| 21 class WebDataProducerHandle { | |
| 22 public: | |
| 23 // This corresponds to MojoWriteDataFlags. | |
| 24 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
| |
| 25 static const Flags FlagNone = 0; | |
| 26 | |
| 27 enum Result { | |
| 28 Ok, | |
| 29 ShouldWait, | |
| 30 AlreadyClosed, | |
| 31 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.
| |
| 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 |