summaryrefslogtreecommitdiff
path: root/chromium/components/subresource_filter/core/browser/copying_file_stream.h
blob: 6df29e1ee3b734d5edc1a409f93d4f103a560153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_COPYING_FILE_STREAM_H_
#define COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_COPYING_FILE_STREAM_H_

#include "base/files/file.h"
#include "base/macros.h"
#include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h"

namespace url_pattern_index {

// Implements a CopyingInputStream that reads from a base::File. Can be used in
// combination with CopyingInputStreamAdaptor for reading from that file through
// the ZeroCopyInputStream interface.
class CopyingFileInputStream : public google::protobuf::io::CopyingInputStream {
 public:
  explicit CopyingFileInputStream(base::File file);
  ~CopyingFileInputStream() override;

  // google::protobuf::io::CopyingInputStream:
  int Read(void* buffer, int size) override;

 private:
  base::File file_;

  DISALLOW_COPY_AND_ASSIGN(CopyingFileInputStream);
};

// Implements a CopyingOutputStream that writes to a base::File. Can be used in
// combination with CopyingOutputStreamAdaptor for writing to that file through
// the ZeroCopyOutputStream interface.
class CopyingFileOutputStream
    : public google::protobuf::io::CopyingOutputStream {
 public:
  explicit CopyingFileOutputStream(base::File file);
  ~CopyingFileOutputStream() override;

  // google::protobuf::io::CopyingOutputStream:
  bool Write(const void* buffer, int size) override;

 private:
  base::File file_;

  DISALLOW_COPY_AND_ASSIGN(CopyingFileOutputStream);
};

}  // namespace url_pattern_index

#endif  // COMPONENTS_SUBRESOURCE_FILTER_CORE_BROWSER_COPYING_FILE_STREAM_H_