OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_FILESYSTEM_FILE_IMPL_H_ | 5 #ifndef COMPONENTS_FILESYSTEM_FILE_IMPL_H_ |
6 #define COMPONENTS_FILESYSTEM_FILE_IMPL_H_ | 6 #define COMPONENTS_FILESYSTEM_FILE_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "components/filesystem/public/interfaces/directory.mojom.h" | 13 #include "components/filesystem/public/interfaces/directory.mojom.h" |
14 #include "mojo/public/cpp/bindings/interface_request.h" | 14 #include "mojo/public/cpp/bindings/interface_request.h" |
15 #include "mojo/public/cpp/bindings/strong_binding.h" | 15 #include "mojo/public/cpp/bindings/strong_binding.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class FilePath; | 18 class FilePath; |
19 } | 19 } |
20 | 20 |
21 namespace filesystem { | 21 namespace filesystem { |
22 | 22 |
23 class LockTable; | 23 class LockTable; |
24 class SharedTempDir; | 24 class SharedTempDir; |
25 | 25 |
26 class FileImpl : public File { | 26 class FileImpl : public mojom::File { |
27 public: | 27 public: |
28 FileImpl(mojo::InterfaceRequest<File> request, | 28 FileImpl(mojo::InterfaceRequest<mojom::File> request, |
29 const base::FilePath& path, | 29 const base::FilePath& path, |
30 uint32_t flags, | 30 uint32_t flags, |
31 scoped_refptr<SharedTempDir> temp_dir, | 31 scoped_refptr<SharedTempDir> temp_dir, |
32 scoped_refptr<LockTable> lock_table); | 32 scoped_refptr<LockTable> lock_table); |
33 FileImpl(mojo::InterfaceRequest<File> request, | 33 FileImpl(mojo::InterfaceRequest<mojom::File> request, |
34 const base::FilePath& path, | 34 const base::FilePath& path, |
35 base::File file, | 35 base::File file, |
36 scoped_refptr<SharedTempDir> temp_dir, | 36 scoped_refptr<SharedTempDir> temp_dir, |
37 scoped_refptr<LockTable> lock_table); | 37 scoped_refptr<LockTable> lock_table); |
38 ~FileImpl() override; | 38 ~FileImpl() override; |
39 | 39 |
40 // Returns whether the underlying file handle is valid. | 40 // Returns whether the underlying file handle is valid. |
41 bool IsValid() const; | 41 bool IsValid() const; |
42 | 42 |
43 // Attempts to perform the native operating system's locking operations on | 43 // Attempts to perform the native operating system's locking operations on |
44 // the internal File handle | 44 // the internal mojom::File handle |
45 base::File::Error RawLockFile(); | 45 base::File::Error RawLockFile(); |
46 base::File::Error RawUnlockFile(); | 46 base::File::Error RawUnlockFile(); |
47 | 47 |
48 const base::FilePath& path() const { return path_; } | 48 const base::FilePath& path() const { return path_; } |
49 | 49 |
50 // |File| implementation: | 50 // |File| implementation: |
51 void Close(const CloseCallback& callback) override; | 51 void Close(const CloseCallback& callback) override; |
52 void Read(uint32_t num_bytes_to_read, | 52 void Read(uint32_t num_bytes_to_read, |
53 int64_t offset, | 53 int64_t offset, |
54 Whence whence, | 54 mojom::Whence whence, |
55 const ReadCallback& callback) override; | 55 const ReadCallback& callback) override; |
56 void Write(mojo::Array<uint8_t> bytes_to_write, | 56 void Write(mojo::Array<uint8_t> bytes_to_write, |
57 int64_t offset, | 57 int64_t offset, |
58 Whence whence, | 58 mojom::Whence whence, |
59 const WriteCallback& callback) override; | 59 const WriteCallback& callback) override; |
60 void Tell(const TellCallback& callback) override; | 60 void Tell(const TellCallback& callback) override; |
61 void Seek(int64_t offset, | 61 void Seek(int64_t offset, |
62 Whence whence, | 62 mojom::Whence whence, |
63 const SeekCallback& callback) override; | 63 const SeekCallback& callback) override; |
64 void Stat(const StatCallback& callback) override; | 64 void Stat(const StatCallback& callback) override; |
65 void Truncate(int64_t size, const TruncateCallback& callback) override; | 65 void Truncate(int64_t size, const TruncateCallback& callback) override; |
66 void Touch(TimespecOrNowPtr atime, | 66 void Touch(mojom::TimespecOrNowPtr atime, |
67 TimespecOrNowPtr mtime, | 67 mojom::TimespecOrNowPtr mtime, |
68 const TouchCallback& callback) override; | 68 const TouchCallback& callback) override; |
69 void Dup(mojo::InterfaceRequest<File> file, | 69 void Dup(mojo::InterfaceRequest<mojom::File> file, |
70 const DupCallback& callback) override; | 70 const DupCallback& callback) override; |
71 void Flush(const FlushCallback& callback) override; | 71 void Flush(const FlushCallback& callback) override; |
72 void Lock(const LockCallback& callback) override; | 72 void Lock(const LockCallback& callback) override; |
73 void Unlock(const UnlockCallback& callback) override; | 73 void Unlock(const UnlockCallback& callback) override; |
74 void AsHandle(const AsHandleCallback& callback) override; | 74 void AsHandle(const AsHandleCallback& callback) override; |
75 | 75 |
76 private: | 76 private: |
77 mojo::StrongBinding<File> binding_; | 77 mojo::StrongBinding<mojom::File> binding_; |
78 base::File file_; | 78 base::File file_; |
79 base::FilePath path_; | 79 base::FilePath path_; |
80 scoped_refptr<SharedTempDir> temp_dir_; | 80 scoped_refptr<SharedTempDir> temp_dir_; |
81 scoped_refptr<LockTable> lock_table_; | 81 scoped_refptr<LockTable> lock_table_; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(FileImpl); | 83 DISALLOW_COPY_AND_ASSIGN(FileImpl); |
84 }; | 84 }; |
85 | 85 |
86 } // namespace filesystem | 86 } // namespace filesystem |
87 | 87 |
88 #endif // COMPONENTS_FILESYSTEM_FILE_IMPL_H_ | 88 #endif // COMPONENTS_FILESYSTEM_FILE_IMPL_H_ |
OLD | NEW |