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

Unified Diff: mojo/common/data_pipe_utils.cc

Issue 1049993002: Get mojo_shell building inside chromium checkout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix presubmit Created 5 years, 9 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 | « mojo/common/data_pipe_utils.h ('k') | mojo/common/trace_controller_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/data_pipe_utils.cc
diff --git a/mojo/common/data_pipe_utils.cc b/mojo/common/data_pipe_utils.cc
index c99c6668ba46a1d112724e3246821913cdff0377..a280dad5e4b97a290a41b0a057a0711fb0ee8404 100644
--- a/mojo/common/data_pipe_utils.cc
+++ b/mojo/common/data_pipe_utils.cc
@@ -71,6 +71,37 @@ bool BlockingCopyToString(ScopedDataPipeConsumerHandle source,
source.Pass(), base::Bind(&CopyToStringHelper, result));
}
+bool MOJO_COMMON_EXPORT BlockingCopyFromString(
+ const std::string& source,
+ const ScopedDataPipeProducerHandle& destination) {
+ auto it = source.begin();
+ for (;;) {
+ void* buffer = nullptr;
+ uint32_t buffer_num_bytes = 0;
+ MojoResult result =
+ BeginWriteDataRaw(destination.get(), &buffer, &buffer_num_bytes,
+ MOJO_WRITE_DATA_FLAG_NONE);
+ if (result == MOJO_RESULT_OK) {
+ char* char_buffer = static_cast<char*>(buffer);
+ uint32_t byte_index = 0;
+ while (it != source.end() && byte_index < buffer_num_bytes) {
+ char_buffer[byte_index++] = *it++;
+ }
+ EndWriteDataRaw(destination.get(), byte_index);
+ } else if (result == MOJO_RESULT_SHOULD_WAIT) {
+ result = Wait(destination.get(), MOJO_HANDLE_SIGNAL_WRITABLE,
+ MOJO_DEADLINE_INDEFINITE, nullptr);
+ if (result != MOJO_RESULT_OK) {
+ // If the consumer handle was closed, then treat as EOF.
+ return result == MOJO_RESULT_FAILED_PRECONDITION;
+ }
+ } else {
+ // If the consumer handle was closed, then treat as EOF.
+ return result == MOJO_RESULT_FAILED_PRECONDITION;
+ }
+ }
+}
+
bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source,
const base::FilePath& destination) {
base::ScopedFILE fp(base::OpenFile(destination, "wb"));
« no previous file with comments | « mojo/common/data_pipe_utils.h ('k') | mojo/common/trace_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698