Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 WebDataConsumerHandle_h | |
| 6 #define WebDataConsumerHandle_h | |
| 7 | |
| 8 #include <stdlib.h> | |
| 9 | |
| 10 namespace blink { | |
| 11 | |
| 12 // WebDataConsumerHandle represents the "consumer" side of a data pipe. A user | |
| 13 // can read data from it. | |
| 14 // This data type is basically a wrapper of mojo data pipe consumer handle. | |
| 15 // See mojo/public/c/system/data_pipe.h for details. | |
| 16 // | |
| 17 // Note: | |
| 18 // - If you register a client, all of read / beginRead / endRead / | |
| 19 // registerClient / unregisterClient must be called on the same thread. | |
| 20 // Client notification is called on the thread. | |
| 21 class WebDataConsumerHandle { | |
| 22 public: | |
| 23 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.
| |
| 24 static const Flags FlagNone = 0; | |
| 25 | |
| 26 enum Result { | |
| 27 Ok, | |
| 28 Done, | |
| 29 Busy, | |
| 30 ShouldWait, | |
| 31 ResourceExhausted, | |
| 32 UnexpectedError, | |
| 33 }; | |
| 34 | |
| 35 // Client gets notification from the pipe. | |
| 36 class Client { | |
| 37 public: | |
| 38 virtual ~Client() { } | |
| 39 // The associated handle gets readable. | |
| 40 virtual void didGetReadable() = 0; | |
| 41 }; | |
| 42 | |
| 43 virtual ~WebDataConsumerHandle() { } | |
| 44 | |
| 45 // Reads data into |data| upto |size| bytes. The actual read size will be | |
| 46 // stored in |*readSize|. This function cannot be called when a two-phase | |
| 47 // read is in progress. | |
| 48 // Returns Done when it reaches to the end of the data. | |
| 49 virtual Result read(void* data, size_t /* size */, Flags, size_t* readSize) = 0; | |
| 50 | |
| 51 // Begins a two-phase read. On success, the function stores a buffer that | |
| 52 // contains the read data of length |*available| into |*buffer|. | |
| 53 // Returns Done when it reaches to the end of the data. | |
| 54 // On fail, you don't have to (and should not) call endRead, because the | |
| 55 // read session implicitly ends in that case. | |
| 56 virtual Result beginRead(const void** buffer, Flags, size_t* available) = 0; | |
| 57 | |
| 58 // Ends a two-phase read. | |
| 59 // |readSize| indicates the actual read size. | |
| 60 virtual Result endRead(size_t readSize) = 0; | |
| 61 | |
| 62 // 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.
| |
| 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 */) = 0; | |
| 66 | |
| 67 // Unregister |client| from this handle. | |
|
tyoshino (SeeGerritForStatus)
2014/10/06 16:12:25
Unregisters
yhirano
2014/10/07 02:28:12
Done.
| |
| 68 virtual void unregisterClient() = 0; | |
| 69 }; | |
| 70 | |
| 71 } // namespace blink | |
| 72 | |
| 73 #endif // WebDataConsumerHandle_h | |
| OLD | NEW |