Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SERVICES_FILES_DIRECTORY_IMPL_H_ |
| 6 | #define SERVICES_FILES_DIRECTORY_IMPL_H_ |
| 7 | |
| 8 | #include "base/files/scoped_file.h" |
| 9 | #include "base/macros.h" |
| 10 | #include "base/memory/scoped_ptr.h" |
| 11 | #include "mojo/public/cpp/bindings/interface_request.h" |
| 12 | #include "mojo/public/cpp/bindings/strong_binding.h" |
Viet-Trung Luu | 08e339a | 2015-10-10 01:03:09 -0700 | [diff] [blame] | 13 | #include "mojo/services/files/interfaces/directory.mojom.h" |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 14 | |
| 15 | namespace base { |
| 16 | class ScopedTempDir; |
| 17 | } // namespace base |
| 18 | |
| 19 | namespace mojo { |
| 20 | namespace files { |
| 21 | |
| 22 | class DirectoryImpl : public Directory { |
| 23 | public: |
| 24 | // Set |temp_dir| only if there's a temporary directory that should be deleted |
| 25 | // when this object is destroyed. |
| 26 | DirectoryImpl(InterfaceRequest<Directory> request, |
| 27 | base::ScopedFD dir_fd, |
| 28 | scoped_ptr<base::ScopedTempDir> temp_dir); |
| 29 | ~DirectoryImpl() override; |
| 30 | |
| 31 | // |Directory| implementation: |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 32 | void Read(const ReadCallback& callback) override; |
| 33 | void Stat(const StatCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 34 | void Touch(TimespecOrNowPtr atime, |
| 35 | TimespecOrNowPtr mtime, |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 36 | const TouchCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 37 | void OpenFile(const String& path, |
| 38 | InterfaceRequest<File> file, |
| 39 | uint32_t open_flags, |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 40 | const OpenFileCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 41 | void OpenDirectory(const String& path, |
| 42 | InterfaceRequest<Directory> directory, |
| 43 | uint32_t open_flags, |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 44 | const OpenDirectoryCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 45 | void Rename(const String& path, |
| 46 | const String& new_path, |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 47 | const RenameCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 48 | void Delete(const String& path, |
| 49 | uint32_t delete_flags, |
Viet-Trung Luu | 0580624 | 2015-04-03 10:17:37 -0700 | [diff] [blame] | 50 | const DeleteCallback& callback) override; |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | StrongBinding<Directory> binding_; |
| 54 | base::ScopedFD dir_fd_; |
| 55 | scoped_ptr<base::ScopedTempDir> temp_dir_; |
| 56 | |
| 57 | DISALLOW_COPY_AND_ASSIGN(DirectoryImpl); |
| 58 | }; |
| 59 | |
| 60 | } // namespace files |
| 61 | } // namespace mojo |
| 62 | |
| 63 | #endif // SERVICES_FILES_DIRECTORY_IMPL_H_ |