• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SHELL_DATA_PIPE_UTILS_H_
6 #define MOJO_SHELL_DATA_PIPE_UTILS_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 
12 #include "base/callback_forward.h"
13 #include "mojo/common/mojo_common_export.h"
14 #include "mojo/public/cpp/system/core.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 MOJO_COMMON_EXPORT CopyToFile(
28     ScopedDataPipeConsumerHandle source,
29     const base::FilePath& destination,
30     base::TaskRunner* task_runner,
31     const base::Callback<void(bool /*success*/)>& callback);
32 
33 void MOJO_COMMON_EXPORT
34 CopyFromFile(const base::FilePath& source,
35              ScopedDataPipeProducerHandle destination,
36              uint32_t skip,
37              base::TaskRunner* task_runner,
38              const base::Callback<void(bool /*success*/)>& callback);
39 
40 // Copies the data from |source| into |contents| and returns true on success and
41 // false on error.  In case of I/O error, |contents| holds the data that could
42 // be read from source before the error occurred.
43 bool MOJO_COMMON_EXPORT BlockingCopyToString(
44     ScopedDataPipeConsumerHandle source,
45     std::string* contents);
46 
47 bool MOJO_COMMON_EXPORT BlockingCopyFromString(
48     const std::string& source,
49     const ScopedDataPipeProducerHandle& destination);
50 
51 // Synchronously copies data from source to the destination file returning true
52 // on success and false on error.  In case of an error, |destination| holds the
53 // data that could be read from the source before the error occured.
54 bool MOJO_COMMON_EXPORT BlockingCopyToFile(ScopedDataPipeConsumerHandle source,
55                                            const base::FilePath& destination);
56 
57 }  // namespace common
58 }  // namespace mojo
59 
60 #endif  // MOJO_SHELL_DATA_PIPE_UTILS_H_
61