summaryrefslogtreecommitdiffstats
path: root/components/filesystem/directory_impl.h
blob: 347c514806426cb06ca6a3b5809e9389d777029d (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright 2015 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_FILESYSTEM_DIRECTORY_IMPL_H_
#define COMPONENTS_FILESYSTEM_DIRECTORY_IMPL_H_

#include <stdint.h>

#include "base/files/file_path.h"
#include "base/files/scoped_file.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/filesystem/public/interfaces/directory.mojom.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h"

namespace base {
class ScopedTempDir;
}  // namespace base

namespace filesystem {

class LockTable;

class DirectoryImpl : public Directory {
 public:
  // Set |temp_dir| only if there's a temporary directory that should be deleted
  // when this object is destroyed.
  DirectoryImpl(mojo::InterfaceRequest<Directory> request,
                base::FilePath directory_path,
                scoped_ptr<base::ScopedTempDir> temp_dir,
                LockTable* lock_table);
  ~DirectoryImpl() override;

  void set_connection_error_handler(const mojo::Closure& error_handler) {
    binding_.set_connection_error_handler(error_handler);
  }

  // |Directory| implementation:
  void Read(const ReadCallback& callback) override;
  void OpenFile(const mojo::String& path,
                mojo::InterfaceRequest<File> file,
                uint32_t open_flags,
                const OpenFileCallback& callback) override;
  void OpenFileHandle(const mojo::String& path,
                      uint32_t open_flags,
                      const OpenFileHandleCallback& callback) override;
  void OpenDirectory(const mojo::String& path,
                     mojo::InterfaceRequest<Directory> directory,
                     uint32_t open_flags,
                     const OpenDirectoryCallback& callback) override;
  void Rename(const mojo::String& path,
              const mojo::String& new_path,
              const RenameCallback& callback) override;
  void Delete(const mojo::String& path,
              uint32_t delete_flags,
              const DeleteCallback& callback) override;
  void Exists(const mojo::String& path,
              const ExistsCallback& callback) override;
  void IsWritable(const mojo::String& path,
                  const IsWritableCallback& callback) override;
  void Flush(const FlushCallback& callback) override;
  void StatFile(const mojo::String& path,
                const StatFileCallback& callback) override;
  void ReadEntireFile(const mojo::String& path,
                      const ReadEntireFileCallback& callback) override;
  void WriteFile(const mojo::String& path,
                 mojo::Array<uint8_t> data,
                 const WriteFileCallback& callback) override;

 private:
  mojo::StrongBinding<Directory> binding_;
  base::FilePath directory_path_;
  scoped_ptr<base::ScopedTempDir> temp_dir_;
  LockTable* lock_table_;

  DISALLOW_COPY_AND_ASSIGN(DirectoryImpl);
};

}  // namespace filesystem

#endif  // COMPONENTS_FILESYSTEM_DIRECTORY_IMPL_H_