Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2145)

Unified Diff: content/network/net_adapters.h

Issue 2817453002: Bring back the URLLoader from the old Mandoline network service. (Closed)
Patch Set: fix checkdeps Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/network/README.md ('k') | content/network/net_adapters.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/network/net_adapters.h
diff --git a/content/network/net_adapters.h b/content/network/net_adapters.h
new file mode 100644
index 0000000000000000000000000000000000000000..e556cd0c4de10b96cbc564a116f121c8821ad9f4
--- /dev/null
+++ b/content/network/net_adapters.h
@@ -0,0 +1,71 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_NETWORK_NET_ADAPTERS_
+#define CONTENT_NETWORK_NET_ADAPTERS_
+
+#include <stdint.h>
+
+#include "base/macros.h"
+#include "mojo/public/cpp/system/data_pipe.h"
+#include "net/base/io_buffer.h"
+
+namespace content {
+
+// These adapters are used to transfer data between a Mojo pipe and the net
+// library.
+//
+// Mojo pipe Data flow Network library
+// ----------------------------------------------------------
+// NetToMojoPendingBuffer <--- NetToMojoIOBuffer
+//
+// While the operation is in progress, the Mojo-side objects keep ownership
+// of the Mojo pipe, which in turn is kept alive by the IOBuffer. This allows
+// the request to potentially outlive the object managing the translation.
+// Mojo side of a Net -> Mojo copy. The buffer is allocated by Mojo.
+class NetToMojoPendingBuffer
+ : public base::RefCountedThreadSafe<NetToMojoPendingBuffer> {
+ public:
+ // Begins a two-phase write to the data pipe.
+ //
+ // On success, MOJO_RESULT_OK will be returned. The ownership of the given
+ // producer handle will be transferred to the new NetToMojoPendingBuffer that
+ // will be placed into *pending, and the size of the buffer will be in
+ // *num_bytes.
+ //
+ // On failure or MOJO_RESULT_SHOULD_WAIT, there will be no change to the
+ // handle, and *pending and *num_bytes will be unused.
+ static MojoResult BeginWrite(mojo::ScopedDataPipeProducerHandle* handle,
+ scoped_refptr<NetToMojoPendingBuffer>* pending,
+ uint32_t* num_bytes);
+ // Called to indicate the buffer is done being written to. Passes ownership
+ // of the pipe back to the caller.
+ mojo::ScopedDataPipeProducerHandle Complete(uint32_t num_bytes);
+ char* buffer() { return static_cast<char*>(buffer_); }
+
+ private:
+ friend class base::RefCountedThreadSafe<NetToMojoPendingBuffer>;
+ // Takes ownership of the handle.
+ NetToMojoPendingBuffer(mojo::ScopedDataPipeProducerHandle handle,
+ void* buffer);
+ ~NetToMojoPendingBuffer();
+ mojo::ScopedDataPipeProducerHandle handle_;
+ void* buffer_;
+ DISALLOW_COPY_AND_ASSIGN(NetToMojoPendingBuffer);
+};
+
+// Net side of a Net -> Mojo copy. The data will be read from the network and
+// copied into the buffer associated with the pending mojo write.
+class NetToMojoIOBuffer : public net::WrappedIOBuffer {
+ public:
+ explicit NetToMojoIOBuffer(NetToMojoPendingBuffer* pending_buffer);
+
+ private:
+ ~NetToMojoIOBuffer() override;
+ scoped_refptr<NetToMojoPendingBuffer> pending_buffer_;
+};
+
+} // namespace content
+
+#endif // CONTENT_NETWORK_NET_ADAPTERS_
« no previous file with comments | « content/network/README.md ('k') | content/network/net_adapters.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698