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> | |
tkent
2014/10/17 02:23:07
nit: I guess you add stdlib.h for size_t. If so,
yhirano
2014/10/17 03:40:07
Done.
| |
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 // This corresponds to MojoReadDataFlags. | |
24 using Flags = unsigned; | |
25 static const Flags FlagNone = 0; | |
26 | |
27 enum Result { | |
28 Ok, | |
29 Done, | |
30 Busy, | |
31 ShouldWait, | |
32 ResourceExhausted, | |
33 UnexpectedError, | |
34 }; | |
35 | |
36 // Client gets notification from the pipe. | |
37 class Client { | |
38 public: | |
39 virtual ~Client() { } | |
40 // The associated handle gets readable. | |
41 virtual void didGetReadable() = 0; | |
42 }; | |
43 | |
44 virtual ~WebDataConsumerHandle() { } | |
45 | |
46 // Reads data into |data| up to |size| bytes. The actual read size will be | |
47 // stored in |*readSize|. This function cannot be called when a two-phase | |
48 // read is in progress. | |
49 // Returns Done when it reaches to the end of the data. | |
50 virtual Result read(void* data, size_t /* size */, Flags, size_t* readSize) = 0; | |
51 | |
52 // Begins a two-phase read. On success, the function stores a buffer that | |
53 // contains the read data of length |*available| into |*buffer|. | |
54 // Returns Done when it reaches to the end of the data. | |
55 // On fail, you don't have to (and should not) call endRead, because the | |
56 // read session implicitly ends in that case. | |
57 virtual Result beginRead(const void** buffer, Flags, size_t* available) = 0; | |
58 | |
59 // Ends a two-phase read. | |
60 // |readSize| indicates the actual read size. | |
61 virtual Result endRead(size_t readSize) = 0; | |
62 | |
63 // Registers |client| to this handle. The client must not be null and must | |
64 // be valid until it is unregistered (or the handle is destructed). | |
65 // Only one registration can be made for a handle at a time. | |
66 virtual void registerClient(Client* /* client */) = 0; | |
67 | |
68 // Unregisters |client| from this handle. | |
69 virtual void unregisterClient() = 0; | |
70 }; | |
71 | |
72 } // namespace blink | |
73 | |
74 #endif // WebDataConsumerHandle_h | |
OLD | NEW |