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

Side by Side Diff: mojo/common/data_pipe_utils.cc

Issue 1538823002: Convert Pass()→std::move() in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 unified diff | Download patch
« no previous file with comments | « mojo/common/data_pipe_drainer.cc ('k') | mojo/common/weak_binding_set.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/data_pipe_utils.h" 5 #include "mojo/common/data_pipe_utils.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <utility>
8 9
9 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
11 #include "base/files/scoped_file.h" 12 #include "base/files/scoped_file.h"
12 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
13 #include "base/task_runner_util.h" 14 #include "base/task_runner_util.h"
14 15
15 namespace mojo { 16 namespace mojo {
16 namespace common { 17 namespace common {
17 namespace { 18 namespace {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 61 }
61 62
62 } // namespace 63 } // namespace
63 64
64 65
65 // TODO(hansmuller): Add a max_size parameter. 66 // TODO(hansmuller): Add a max_size parameter.
66 bool BlockingCopyToString(ScopedDataPipeConsumerHandle source, 67 bool BlockingCopyToString(ScopedDataPipeConsumerHandle source,
67 std::string* result) { 68 std::string* result) {
68 CHECK(result); 69 CHECK(result);
69 result->clear(); 70 result->clear();
70 return BlockingCopyHelper( 71 return BlockingCopyHelper(std::move(source),
71 source.Pass(), base::Bind(&CopyToStringHelper, result)); 72 base::Bind(&CopyToStringHelper, result));
72 } 73 }
73 74
74 bool MOJO_COMMON_EXPORT BlockingCopyFromString( 75 bool MOJO_COMMON_EXPORT BlockingCopyFromString(
75 const std::string& source, 76 const std::string& source,
76 const ScopedDataPipeProducerHandle& destination) { 77 const ScopedDataPipeProducerHandle& destination) {
77 auto it = source.begin(); 78 auto it = source.begin();
78 for (;;) { 79 for (;;) {
79 void* buffer = nullptr; 80 void* buffer = nullptr;
80 uint32_t buffer_num_bytes = 0; 81 uint32_t buffer_num_bytes = 0;
81 MojoResult result = 82 MojoResult result =
(...skipping 20 matching lines...) Expand all
102 return result == MOJO_RESULT_FAILED_PRECONDITION; 103 return result == MOJO_RESULT_FAILED_PRECONDITION;
103 } 104 }
104 } 105 }
105 } 106 }
106 107
107 bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source, 108 bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source,
108 const base::FilePath& destination) { 109 const base::FilePath& destination) {
109 base::ScopedFILE fp(base::OpenFile(destination, "wb")); 110 base::ScopedFILE fp(base::OpenFile(destination, "wb"));
110 if (!fp) 111 if (!fp)
111 return false; 112 return false;
112 return BlockingCopyHelper( 113 return BlockingCopyHelper(std::move(source),
113 source.Pass(), base::Bind(&CopyToFileHelper, fp.get())); 114 base::Bind(&CopyToFileHelper, fp.get()));
114 } 115 }
115 116
116 void CopyToFile(ScopedDataPipeConsumerHandle source, 117 void CopyToFile(ScopedDataPipeConsumerHandle source,
117 const base::FilePath& destination, 118 const base::FilePath& destination,
118 base::TaskRunner* task_runner, 119 base::TaskRunner* task_runner,
119 const base::Callback<void(bool)>& callback) { 120 const base::Callback<void(bool)>& callback) {
120 base::PostTaskAndReplyWithResult( 121 base::PostTaskAndReplyWithResult(
121 task_runner, 122 task_runner,
122 FROM_HERE, 123 FROM_HERE,
123 base::Bind(&BlockingCopyToFile, base::Passed(&source), destination), 124 base::Bind(&BlockingCopyToFile, base::Passed(&source), destination),
124 callback); 125 callback);
125 } 126 }
126 127
127 } // namespace common 128 } // namespace common
128 } // namespace mojo 129 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/data_pipe_drainer.cc ('k') | mojo/common/weak_binding_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698