OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 CONTENT_NETWORK_NET_ADAPTERS_ | |
6 #define CONTENT_NETWORK_NET_ADAPTERS_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "mojo/public/cpp/system/data_pipe.h" | |
12 #include "net/base/io_buffer.h" | |
13 | |
14 namespace content { | |
15 | |
16 // These adapters are used to transfer data between a Mojo pipe and the net | |
17 // library. There are four adapters, one for each end in each direction: | |
18 // | |
19 // Mojo pipe Data flow Network library | |
20 // ---------------------------------------------------------- | |
21 // MojoToNetPendingBuffer ---> MojoToNetIOBuffer | |
yzshen1
2017/04/11 21:58:04
Please update the comment now that these two are r
jam
2017/04/11 22:58:19
Done.
| |
22 // NetToMojoPendingBuffer <--- NetToMojoIOBuffer | |
23 // | |
24 // While the operation is in progress, the Mojo-side objects keep ownership | |
25 // of the Mojo pipe, which in turn is kept alive by the IOBuffer. This allows | |
26 // the request to potentially outlive the object managing the translation. | |
27 // Mojo side of a Net -> Mojo copy. The buffer is allocated by Mojo. | |
28 class NetToMojoPendingBuffer | |
29 : public base::RefCountedThreadSafe<NetToMojoPendingBuffer> { | |
30 public: | |
31 // Begins a two-phase write to the data pipe. | |
32 // | |
33 // On success, MOJO_RESULT_OK will be returned. The ownership of the given | |
34 // producer handle will be transferred to the new NetToMojoPendingBuffer that | |
35 // will be placed into *pending, and the size of the buffer will be in | |
36 // *num_bytes. | |
37 // | |
38 // On failure or MOJO_RESULT_SHOULD_WAIT, there will be no change to the | |
39 // handle, and *pending and *num_bytes will be unused. | |
40 static MojoResult BeginWrite(mojo::ScopedDataPipeProducerHandle* handle, | |
41 scoped_refptr<NetToMojoPendingBuffer>* pending, | |
42 uint32_t* num_bytes); | |
43 // Called to indicate the buffer is done being written to. Passes ownership | |
44 // of the pipe back to the caller. | |
45 mojo::ScopedDataPipeProducerHandle Complete(uint32_t num_bytes); | |
46 char* buffer() { return static_cast<char*>(buffer_); } | |
47 | |
48 private: | |
49 friend class base::RefCountedThreadSafe<NetToMojoPendingBuffer>; | |
50 // Takes ownership of the handle. | |
51 NetToMojoPendingBuffer(mojo::ScopedDataPipeProducerHandle handle, | |
52 void* buffer); | |
53 ~NetToMojoPendingBuffer(); | |
54 mojo::ScopedDataPipeProducerHandle handle_; | |
55 void* buffer_; | |
56 DISALLOW_COPY_AND_ASSIGN(NetToMojoPendingBuffer); | |
57 }; | |
58 | |
59 // Net side of a Net -> Mojo copy. The data will be read from the network and | |
60 // copied into the buffer associated with the pending mojo write. | |
61 class NetToMojoIOBuffer : public net::WrappedIOBuffer { | |
62 public: | |
63 explicit NetToMojoIOBuffer(NetToMojoPendingBuffer* pending_buffer); | |
64 | |
65 private: | |
66 ~NetToMojoIOBuffer() override; | |
67 scoped_refptr<NetToMojoPendingBuffer> pending_buffer_; | |
68 }; | |
69 | |
70 } // namespace content | |
71 | |
72 #endif // CONTENT_NETWORK_NET_ADAPTERS_ | |
OLD | NEW |