OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/data_pipe_utils/data_pipe_utils.h" | 5 #include "mojo/data_pipe_utils/data_pipe_utils.h" |
6 | 6 |
7 #include <stdio.h> | 7 #include <stdio.h> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/task_runner_util.h" | 10 #include "base/task_runner_util.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 // If the consumer handle was closed, then treat as EOF. | 105 // If the consumer handle was closed, then treat as EOF. |
106 return result == MOJO_RESULT_FAILED_PRECONDITION; | 106 return result == MOJO_RESULT_FAILED_PRECONDITION; |
107 } | 107 } |
108 } else { | 108 } else { |
109 // If the consumer handle was closed, then treat as EOF. | 109 // If the consumer handle was closed, then treat as EOF. |
110 return result == MOJO_RESULT_FAILED_PRECONDITION; | 110 return result == MOJO_RESULT_FAILED_PRECONDITION; |
111 } | 111 } |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
| 115 ScopedDataPipeConsumerHandle WriteStringToConsumerHandle( |
| 116 const std::string& source) { |
| 117 TRACE_EVENT0("data_pipe_utils", "WriteStringToConsumerHandle"); |
| 118 static const size_t max_buffer_size = 2 * 1024 * 1024; // 2MB |
| 119 CHECK_LE(static_cast<uint32_t>(source.size()), max_buffer_size); |
| 120 MojoCreateDataPipeOptions options = {sizeof(MojoCreateDataPipeOptions), |
| 121 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, |
| 122 1, source.size()}; |
| 123 DataPipe pipe(options); |
| 124 BlockingCopyFromString(source, pipe.producer_handle.Pass()); |
| 125 return pipe.consumer_handle.Pass(); |
| 126 } |
| 127 |
115 } // namespace common | 128 } // namespace common |
116 } // namespace mojo | 129 } // namespace mojo |
OLD | NEW |