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

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

Issue 1303343007: Created a blocking copy to temporary file function. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | mojo/data_pipe_utils/data_pipe_utils.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/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 <limits> 9 #include <limits>
10 10
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 base::ScopedFILE fp(base::OpenFile(destination, "wb")); 322 base::ScopedFILE fp(base::OpenFile(destination, "wb"));
323 if (!fp) { 323 if (!fp) {
324 LOG(ERROR) << "OpenFile('" << destination.value() 324 LOG(ERROR) << "OpenFile('" << destination.value()
325 << "'failed in BlockingCopyToFile"; 325 << "'failed in BlockingCopyToFile";
326 return false; 326 return false;
327 } 327 }
328 return BlockingCopyHelper(source.Pass(), 328 return BlockingCopyHelper(source.Pass(),
329 base::Bind(&CopyToFileHelper, fp.get())); 329 base::Bind(&CopyToFileHelper, fp.get()));
330 } 330 }
331 331
332 bool BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source,
333 FILE** fpp) {
viettrungluu 2015/09/01 23:36:25 Possibly this should be a base::ScopedFILE*. Or y
Sean Klein 2015/09/01 23:57:52 Out of curiosity, what is the difference between a
jamesr 2015/09/02 00:06:39 base::ScopedFILE's destructor calls fclose()
334 base::FilePath path;
335 *fpp = (base::CreateAndOpenTemporaryFile(&path));
336 if (!*fpp) {
337 LOG(ERROR) << "CreateAndOpenTemporaryFile failed in"
338 << "BlockingCopyToTempFile";
339 return false;
340 }
341 if (unlink(path.value().c_str())) {
342 LOG(ERROR) << "Failed to unlink temporary file\n";
viettrungluu 2015/09/01 23:36:25 Also: no \n needed here. More importantly, it's pe
Sean Klein 2015/09/01 23:57:52 Done.
343 return false;
344 }
345 return BlockingCopyHelper(source.Pass(),
346 base::Bind(&CopyToFileHelper, *fpp));
347 }
348
332 void CopyToFile(ScopedDataPipeConsumerHandle source, 349 void CopyToFile(ScopedDataPipeConsumerHandle source,
333 const base::FilePath& destination, 350 const base::FilePath& destination,
334 base::TaskRunner* task_runner, 351 base::TaskRunner* task_runner,
335 const base::Callback<void(bool)>& callback) { 352 const base::Callback<void(bool)>& callback) {
336 new CopyToFileHandler(source.Pass(), destination, task_runner, callback); 353 new CopyToFileHandler(source.Pass(), destination, task_runner, callback);
337 } 354 }
338 355
339 void CopyFromFile(const base::FilePath& source, 356 void CopyFromFile(const base::FilePath& source,
340 ScopedDataPipeProducerHandle destination, 357 ScopedDataPipeProducerHandle destination,
341 uint32_t skip, 358 uint32_t skip,
342 base::TaskRunner* task_runner, 359 base::TaskRunner* task_runner,
343 const base::Callback<void(bool)>& callback) { 360 const base::Callback<void(bool)>& callback) {
344 new CopyFromFileHandler(source, destination.Pass(), skip, task_runner, 361 new CopyFromFileHandler(source, destination.Pass(), skip, task_runner,
345 callback); 362 callback);
346 } 363 }
347 364
348 } // namespace common 365 } // namespace common
349 } // namespace mojo 366 } // namespace mojo
OLDNEW
« no previous file with comments | « no previous file | mojo/data_pipe_utils/data_pipe_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698