blob: 426912c95b46cb7996dac46fa784ee8aafe330b7 [file] [log] [blame]
Luis Hector Chavez645501c2016-12-28 10:56:26 -08001// 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
Luis Hector Chavez21a249e2017-07-26 17:38:05 +00005#ifndef MOJO_SHELL_DATA_PIPE_UTILS_H_
6#define MOJO_SHELL_DATA_PIPE_UTILS_H_
Luis Hector Chavez645501c2016-12-28 10:56:26 -08007
8#include <stdint.h>
9
10#include <string>
11
Luis Hector Chavez21a249e2017-07-26 17:38:05 +000012#include "base/callback_forward.h"
Luis Hector Chavez645501c2016-12-28 10:56:26 -080013#include "mojo/common/mojo_common_export.h"
Luis Hector Chavez21a249e2017-07-26 17:38:05 +000014#include "mojo/public/cpp/system/core.h"
15
16namespace base {
17class FilePath;
18class TaskRunner;
19}
Luis Hector Chavez645501c2016-12-28 10:56:26 -080020
21namespace mojo {
22namespace common {
23
Luis Hector Chavez21a249e2017-07-26 17:38:05 +000024// 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|.
27void 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
33void MOJO_COMMON_EXPORT
34CopyFromFile(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
Luis Hector Chavez645501c2016-12-28 10:56:26 -080040// 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.
43bool MOJO_COMMON_EXPORT BlockingCopyToString(
44 ScopedDataPipeConsumerHandle source,
45 std::string* contents);
46
47bool MOJO_COMMON_EXPORT BlockingCopyFromString(
48 const std::string& source,
49 const ScopedDataPipeProducerHandle& destination);
50
Luis Hector Chavez21a249e2017-07-26 17:38:05 +000051// 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.
54bool MOJO_COMMON_EXPORT BlockingCopyToFile(ScopedDataPipeConsumerHandle source,
55 const base::FilePath& destination);
56
Luis Hector Chavez645501c2016-12-28 10:56:26 -080057} // namespace common
58} // namespace mojo
59
Luis Hector Chavez21a249e2017-07-26 17:38:05 +000060#endif // MOJO_SHELL_DATA_PIPE_UTILS_H_