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 <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 NULL; |
jamesr
2015/09/02 23:29:31
s/NULL/nullptr/. Only use NULL in code that has t
Sean Klein
2015/09/02 23:35:35
Whoops! Sorry, a bit new to C++, and old habits di
| |
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 NULL; | |
329 } | |
330 if (!BlockingCopyHelper(source.Pass(), | |
331 base::Bind(&CopyToFileHelper, fp.get()))) { | |
332 LOG(ERROR) << "Could not copy source to temporary file"; | |
333 return NULL; | |
jamesr
2015/09/02 23:29:31
ditto
Sean Klein
2015/09/02 23:35:35
Done.
| |
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 |
OLD | NEW |