blob: 8ad9193777bbb4ba4d72f1dd5dfb2b2a12aaa2ec [file] [log] [blame]
erg0aa9eec2015-05-20 21:23:261// Copyright 2015 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
Elliot Glaysherf660e832015-05-21 22:46:425#ifndef COMPONENTS_FILESYSTEM_FILE_IMPL_H_
6#define COMPONENTS_FILESYSTEM_FILE_IMPL_H_
erg0aa9eec2015-05-20 21:23:267
avibc5337b2015-12-25 23:16:338#include <stdint.h>
9
erg6c6729f2015-05-29 17:05:4110#include "base/files/file.h"
erg0aa9eec2015-05-20 21:23:2611#include "base/files/scoped_file.h"
12#include "base/macros.h"
13#include "components/filesystem/public/interfaces/directory.mojom.h"
rockot85dce0862015-11-13 01:33:5914#include "mojo/public/cpp/bindings/interface_request.h"
erg0aa9eec2015-05-20 21:23:2615
erg6c6729f2015-05-29 17:05:4116namespace base {
17class FilePath;
18}
19
Elliot Glaysher6ea999282015-05-21 19:29:0720namespace filesystem {
erg0aa9eec2015-05-20 21:23:2621
ergb22301f2016-02-17 19:37:5422class LockTable;
erga95c3cd92016-05-02 20:13:3523class SharedTempDir;
ergb22301f2016-02-17 19:37:5424
leon.han99744852016-05-10 03:48:1325class FileImpl : public mojom::File {
erg0aa9eec2015-05-20 21:23:2626 public:
rockot8e66a08d2016-09-13 00:48:2127 FileImpl(const base::FilePath& path,
ergb22301f2016-02-17 19:37:5428 uint32_t flags,
erga95c3cd92016-05-02 20:13:3529 scoped_refptr<SharedTempDir> temp_dir,
ergc1127942016-03-21 18:55:1930 scoped_refptr<LockTable> lock_table);
rockot8e66a08d2016-09-13 00:48:2131 FileImpl(const base::FilePath& path,
ergb22301f2016-02-17 19:37:5432 base::File file,
erga95c3cd92016-05-02 20:13:3533 scoped_refptr<SharedTempDir> temp_dir,
ergc1127942016-03-21 18:55:1934 scoped_refptr<LockTable> lock_table);
Elliot Glaysherf660e832015-05-21 22:46:4235 ~FileImpl() override;
erg0aa9eec2015-05-20 21:23:2636
ergb22301f2016-02-17 19:37:5437 // Returns whether the underlying file handle is valid.
38 bool IsValid() const;
39
40 // Attempts to perform the native operating system's locking operations on
leon.han99744852016-05-10 03:48:1341 // the internal mojom::File handle
ergb22301f2016-02-17 19:37:5442 base::File::Error RawLockFile();
43 base::File::Error RawUnlockFile();
44
45 const base::FilePath& path() const { return path_; }
46
erg0aa9eec2015-05-20 21:23:2647 // |File| implementation:
48 void Close(const CloseCallback& callback) override;
49 void Read(uint32_t num_bytes_to_read,
50 int64_t offset,
leon.han99744852016-05-10 03:48:1351 mojom::Whence whence,
erg0aa9eec2015-05-20 21:23:2652 const ReadCallback& callback) override;
Elliot Glaysher6ea999282015-05-21 19:29:0753 void Write(mojo::Array<uint8_t> bytes_to_write,
erg0aa9eec2015-05-20 21:23:2654 int64_t offset,
leon.han99744852016-05-10 03:48:1355 mojom::Whence whence,
erg0aa9eec2015-05-20 21:23:2656 const WriteCallback& callback) override;
erg0aa9eec2015-05-20 21:23:2657 void Tell(const TellCallback& callback) override;
58 void Seek(int64_t offset,
leon.han99744852016-05-10 03:48:1359 mojom::Whence whence,
erg0aa9eec2015-05-20 21:23:2660 const SeekCallback& callback) override;
61 void Stat(const StatCallback& callback) override;
62 void Truncate(int64_t size, const TruncateCallback& callback) override;
leon.han99744852016-05-10 03:48:1363 void Touch(mojom::TimespecOrNowPtr atime,
64 mojom::TimespecOrNowPtr mtime,
erg0aa9eec2015-05-20 21:23:2665 const TouchCallback& callback) override;
rockot8e66a08d2016-09-13 00:48:2166 void Dup(mojom::FileRequest file, const DupCallback& callback) override;
erg102ceb412015-06-20 01:38:1367 void Flush(const FlushCallback& callback) override;
ergb22301f2016-02-17 19:37:5468 void Lock(const LockCallback& callback) override;
69 void Unlock(const UnlockCallback& callback) override;
ergb9cc835b2015-05-29 19:22:3470 void AsHandle(const AsHandleCallback& callback) override;
erg0aa9eec2015-05-20 21:23:2671
72 private:
erg6c6729f2015-05-29 17:05:4173 base::File file_;
ergb22301f2016-02-17 19:37:5474 base::FilePath path_;
erga95c3cd92016-05-02 20:13:3575 scoped_refptr<SharedTempDir> temp_dir_;
ergc1127942016-03-21 18:55:1976 scoped_refptr<LockTable> lock_table_;
erg0aa9eec2015-05-20 21:23:2677
Elliot Glaysherf660e832015-05-21 22:46:4278 DISALLOW_COPY_AND_ASSIGN(FileImpl);
erg0aa9eec2015-05-20 21:23:2679};
80
Elliot Glaysher6ea999282015-05-21 19:29:0781} // namespace filesystem
erg0aa9eec2015-05-20 21:23:2682
Elliot Glaysherf660e832015-05-21 22:46:4283#endif // COMPONENTS_FILESYSTEM_FILE_IMPL_H_