cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / mojo / services / network / net_adapters.cc
blob551481d38810370c9968a546fdf5492b2896ab27
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.
5 #include "mojo/services/network/net_adapters.h"
7 #include "net/base/net_errors.h"
9 namespace mojo {
11 namespace {
13 const uint32_t kMaxBufSize = 64 * 1024;
15 } // namespace
17 NetToMojoPendingBuffer::NetToMojoPendingBuffer(
18 ScopedDataPipeProducerHandle handle,
19 void* buffer)
20 : handle_(handle.Pass()),
21 buffer_(buffer) {
24 NetToMojoPendingBuffer::~NetToMojoPendingBuffer() {
25 if (handle_.is_valid())
26 EndWriteDataRaw(handle_.get(), 0);
29 // static
30 MojoResult NetToMojoPendingBuffer::BeginWrite(
31 ScopedDataPipeProducerHandle* handle,
32 scoped_refptr<NetToMojoPendingBuffer>* pending,
33 uint32_t* num_bytes) {
34 void* buf;
35 *num_bytes = 0;
37 MojoResult result = BeginWriteDataRaw(handle->get(), &buf, num_bytes,
38 MOJO_WRITE_DATA_FLAG_NONE);
39 if (result == MOJO_RESULT_OK) {
40 if (*num_bytes > kMaxBufSize)
41 *num_bytes = kMaxBufSize;
42 *pending = new NetToMojoPendingBuffer(handle->Pass(), buf);
44 return result;
47 ScopedDataPipeProducerHandle NetToMojoPendingBuffer::Complete(
48 uint32_t num_bytes) {
49 EndWriteDataRaw(handle_.get(), num_bytes);
50 buffer_ = NULL;
51 return handle_.Pass();
54 // -----------------------------------------------------------------------------
56 NetToMojoIOBuffer::NetToMojoIOBuffer(
57 NetToMojoPendingBuffer* pending_buffer)
58 : net::WrappedIOBuffer(pending_buffer->buffer()),
59 pending_buffer_(pending_buffer) {
62 NetToMojoIOBuffer::~NetToMojoIOBuffer() {
65 // -----------------------------------------------------------------------------
67 MojoToNetPendingBuffer::MojoToNetPendingBuffer(
68 ScopedDataPipeConsumerHandle handle,
69 const void* buffer)
70 : handle_(handle.Pass()),
71 buffer_(buffer) {
74 MojoToNetPendingBuffer::~MojoToNetPendingBuffer() {
77 // static
78 MojoResult MojoToNetPendingBuffer::BeginRead(
79 ScopedDataPipeConsumerHandle* handle,
80 scoped_refptr<MojoToNetPendingBuffer>* pending,
81 uint32_t* num_bytes) {
82 const void* buffer = NULL;
83 *num_bytes = 0;
84 MojoResult result = BeginReadDataRaw(handle->get(), &buffer, num_bytes,
85 MOJO_READ_DATA_FLAG_NONE);
86 if (result == MOJO_RESULT_OK)
87 *pending = new MojoToNetPendingBuffer(handle->Pass(), buffer);
88 return result;
91 ScopedDataPipeConsumerHandle MojoToNetPendingBuffer::Complete(
92 uint32_t num_bytes) {
93 EndReadDataRaw(handle_.get(), num_bytes);
94 buffer_ = NULL;
95 return handle_.Pass();
98 // -----------------------------------------------------------------------------
100 MojoToNetIOBuffer::MojoToNetIOBuffer(MojoToNetPendingBuffer* pending_buffer)
101 : net::WrappedIOBuffer(pending_buffer->buffer()),
102 pending_buffer_(pending_buffer) {
105 MojoToNetIOBuffer::~MojoToNetIOBuffer() {
108 // -----------------------------------------------------------------------------
110 NetworkErrorPtr MakeNetworkError(int error_code) {
111 NetworkErrorPtr error = NetworkError::New();
112 error->code = error_code;
113 if (error_code <= 0)
114 error->description = net::ErrorToString(error_code);
115 return error.Pass();
118 } // namespace mojo