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

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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 base::Bind(&CopyFromFileHandler::OnHandleReady, 308 base::Bind(&CopyFromFileHandler::OnHandleReady,
309 base::Unretained(this), result)); 309 base::Unretained(this), result));
310 } 310 }
311 311
312 size_t CopyToFileHelper(FILE* fp, const void* buffer, uint32_t num_bytes) { 312 size_t CopyToFileHelper(FILE* fp, const void* buffer, uint32_t num_bytes) {
313 return fwrite(buffer, 1, num_bytes, fp); 313 return fwrite(buffer, 1, num_bytes, fp);
314 } 314 }
315 315
316 } // namespace 316 } // namespace
317 317
318 bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source, 318 base::ScopedFILE BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source) {
319 const base::FilePath& destination) { 319 base::FilePath path;
320 TRACE_EVENT1("data_pipe_utils", "BlockingCopyToFile", "dest", 320 base::ScopedFILE fp(CreateAndOpenTemporaryFile(&path));
321 destination.MaybeAsASCII());
322 base::ScopedFILE fp(base::OpenFile(destination, "wb"));
323 if (!fp) { 321 if (!fp) {
324 LOG(ERROR) << "OpenFile('" << destination.value() 322 LOG(ERROR) << "CreateAndOpenTemporaryFile failed in"
325 << "'failed in BlockingCopyToFile"; 323 << "BlockingCopyToTempFile";
326 return false; 324 return nullptr;
327 } 325 }
328 return BlockingCopyHelper(source.Pass(), 326 if (unlink(path.value().c_str())) {
329 base::Bind(&CopyToFileHelper, fp.get())); 327 LOG(ERROR) << "Failed to unlink temporary file";
328 return nullptr;
329 }
330 if (!BlockingCopyHelper(source.Pass(),
331 base::Bind(&CopyToFileHelper, fp.get()))) {
332 LOG(ERROR) << "Could not copy source to temporary file";
333 return nullptr;
334 }
335 return fp;
330 } 336 }
331 337
332 void CopyToFile(ScopedDataPipeConsumerHandle source, 338 void CopyToFile(ScopedDataPipeConsumerHandle source,
333 const base::FilePath& destination, 339 const base::FilePath& destination,
334 base::TaskRunner* task_runner, 340 base::TaskRunner* task_runner,
335 const base::Callback<void(bool)>& callback) { 341 const base::Callback<void(bool)>& callback) {
336 new CopyToFileHandler(source.Pass(), destination, task_runner, callback); 342 new CopyToFileHandler(source.Pass(), destination, task_runner, callback);
337 } 343 }
338 344
339 void CopyFromFile(const base::FilePath& source, 345 void CopyFromFile(const base::FilePath& source,
340 ScopedDataPipeProducerHandle destination, 346 ScopedDataPipeProducerHandle destination,
341 uint32_t skip, 347 uint32_t skip,
342 base::TaskRunner* task_runner, 348 base::TaskRunner* task_runner,
343 const base::Callback<void(bool)>& callback) { 349 const base::Callback<void(bool)>& callback) {
344 new CopyFromFileHandler(source, destination.Pass(), skip, task_runner, 350 new CopyFromFileHandler(source, destination.Pass(), skip, task_runner,
345 callback); 351 callback);
346 } 352 }
347 353
348 } // namespace common 354 } // namespace common
349 } // namespace mojo 355 } // 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