OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef MOJO_DATA_PIPE_UTILS_DATA_PIPE_UTILS_H_ |
| 6 #define MOJO_DATA_PIPE_UTILS_DATA_PIPE_UTILS_H_ |
| 7 |
| 8 #include <stdio.h> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback_forward.h" |
| 12 #include "base/files/scoped_file.h" |
| 13 #include "base/threading/platform_thread.h" |
| 14 #include "mojo/public/cpp/system/data_pipe.h" |
| 15 |
| 16 namespace base { |
| 17 class FilePath; |
| 18 class TaskRunner; |
| 19 } |
| 20 |
| 21 namespace mojo { |
| 22 namespace common { |
| 23 |
| 24 // Asynchronously copies data from source to the destination file. The given |
| 25 // |callback| is run upon completion. File writes will be scheduled to the |
| 26 // given |task_runner|. |
| 27 void CopyToFile(ScopedDataPipeConsumerHandle source, |
| 28 const base::FilePath& destination, |
| 29 base::TaskRunner* task_runner, |
| 30 const base::Callback<void(bool /*success*/)>& callback); |
| 31 |
| 32 void CopyFromFile(const base::FilePath& source, |
| 33 ScopedDataPipeProducerHandle destination, |
| 34 uint32_t skip, |
| 35 base::TaskRunner* task_runner, |
| 36 const base::Callback<void(bool /*success*/)>& callback); |
| 37 |
| 38 // Copies the data from |source| into |contents| and returns true on success and |
| 39 // false on error. In case of I/O error, |contents| holds the data that could |
| 40 // be read from source before the error occurred. |
| 41 bool BlockingCopyToString(ScopedDataPipeConsumerHandle source, |
| 42 std::string* contents); |
| 43 |
| 44 bool BlockingCopyFromString(const std::string& source, |
| 45 const ScopedDataPipeProducerHandle& destination); |
| 46 |
| 47 // Synchronously copies source data to a temporary file, returning a file |
| 48 // pointer on success and NULL on error. The temporary file is unlinked |
| 49 // immediately so that it is only accessible by file pointer (and removed once |
| 50 // closed or the creating process dies). |
| 51 base::ScopedFILE BlockingCopyToTempFile(ScopedDataPipeConsumerHandle source); |
| 52 |
| 53 // Similar to BlockingCopyToTempFile, but use a pre-defined file pointer |
| 54 // (rather than a newly created temp file) and do not unlink the file. |
| 55 // Returns true on success, false on failure. |
| 56 bool BlockingCopyToFile(ScopedDataPipeConsumerHandle source, FILE* fp); |
| 57 |
| 58 // Copies the string |contents| to a temporary data pipe and returns the |
| 59 // consumer handle. |
| 60 ScopedDataPipeConsumerHandle WriteStringToConsumerHandle( |
| 61 const std::string& source); |
| 62 |
| 63 } // namespace common |
| 64 } // namespace mojo |
| 65 |
| 66 #endif // MOJO_DATA_PIPE_UTILS_DATA_PIPE_UTILS_H_ |
OLD | NEW |