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 #include "components/filesystem/directory_impl.h" | 5 #include "components/filesystem/directory_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "components/filesystem/file_impl.h" | 15 #include "components/filesystem/file_impl.h" |
16 #include "components/filesystem/lock_table.h" | 16 #include "components/filesystem/lock_table.h" |
17 #include "components/filesystem/util.h" | 17 #include "components/filesystem/util.h" |
18 #include "mojo/common/common_type_converters.h" | 18 #include "mojo/common/common_type_converters.h" |
19 #include "mojo/platform_handle/platform_handle_functions.h" | 19 #include "mojo/platform_handle/platform_handle_functions.h" |
20 | 20 |
21 using mojo::ScopedHandle; | 21 using mojo::ScopedHandle; |
22 | 22 |
23 namespace filesystem { | 23 namespace filesystem { |
24 | 24 |
25 DirectoryImpl::DirectoryImpl(mojo::InterfaceRequest<Directory> request, | 25 DirectoryImpl::DirectoryImpl(mojo::InterfaceRequest<Directory> request, |
26 base::FilePath directory_path, | 26 base::FilePath directory_path, |
27 std::unique_ptr<base::ScopedTempDir> temp_dir, | 27 scoped_refptr<SharedTempDir> temp_dir, |
28 scoped_refptr<LockTable> lock_table) | 28 scoped_refptr<LockTable> lock_table) |
29 : binding_(this, std::move(request)), | 29 : binding_(this, std::move(request)), |
30 directory_path_(directory_path), | 30 directory_path_(directory_path), |
31 temp_dir_(std::move(temp_dir)), | 31 temp_dir_(std::move(temp_dir)), |
32 lock_table_(std::move(lock_table)) {} | 32 lock_table_(std::move(lock_table)) {} |
33 | 33 |
34 DirectoryImpl::~DirectoryImpl() { | 34 DirectoryImpl::~DirectoryImpl() {} |
35 } | |
36 | 35 |
37 void DirectoryImpl::Read(const ReadCallback& callback) { | 36 void DirectoryImpl::Read(const ReadCallback& callback) { |
38 mojo::Array<DirectoryEntryPtr> entries; | 37 mojo::Array<DirectoryEntryPtr> entries; |
39 base::FileEnumerator directory_enumerator( | 38 base::FileEnumerator directory_enumerator( |
40 directory_path_, false, | 39 directory_path_, false, |
41 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); | 40 base::FileEnumerator::DIRECTORIES | base::FileEnumerator::FILES); |
42 for (base::FilePath name = directory_enumerator.Next(); !name.empty(); | 41 for (base::FilePath name = directory_enumerator.Next(); !name.empty(); |
43 name = directory_enumerator.Next()) { | 42 name = directory_enumerator.Next()) { |
44 base::FileEnumerator::FileInfo info = directory_enumerator.GetInfo(); | 43 base::FileEnumerator::FileInfo info = directory_enumerator.GetInfo(); |
45 DirectoryEntryPtr entry = DirectoryEntry::New(); | 44 DirectoryEntryPtr entry = DirectoryEntry::New(); |
(...skipping 30 matching lines...) Expand all Loading... |
76 return; | 75 return; |
77 } | 76 } |
78 | 77 |
79 base::File base_file(path, open_flags); | 78 base::File base_file(path, open_flags); |
80 if (!base_file.IsValid()) { | 79 if (!base_file.IsValid()) { |
81 callback.Run(GetError(base_file)); | 80 callback.Run(GetError(base_file)); |
82 return; | 81 return; |
83 } | 82 } |
84 | 83 |
85 if (file.is_pending()) { | 84 if (file.is_pending()) { |
86 new FileImpl(std::move(file), path, std::move(base_file), lock_table_); | 85 new FileImpl(std::move(file), path, std::move(base_file), temp_dir_, |
| 86 lock_table_); |
87 } | 87 } |
88 callback.Run(FileError::OK); | 88 callback.Run(FileError::OK); |
89 } | 89 } |
90 | 90 |
91 void DirectoryImpl::OpenFileHandle(const mojo::String& raw_path, | 91 void DirectoryImpl::OpenFileHandle(const mojo::String& raw_path, |
92 uint32_t open_flags, | 92 uint32_t open_flags, |
93 const OpenFileHandleCallback& callback) { | 93 const OpenFileHandleCallback& callback) { |
94 base::FilePath path; | 94 base::FilePath path; |
95 FileError error = ValidatePath(raw_path, directory_path_, &path); | 95 FileError error = ValidatePath(raw_path, directory_path_, &path); |
96 if (error != FileError::OK) { | 96 if (error != FileError::OK) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 base::File::Error error; | 150 base::File::Error error; |
151 if (!base::CreateDirectoryAndGetError(path, &error)) { | 151 if (!base::CreateDirectoryAndGetError(path, &error)) { |
152 callback.Run(static_cast<filesystem::FileError>(error)); | 152 callback.Run(static_cast<filesystem::FileError>(error)); |
153 return; | 153 return; |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 if (directory.is_pending()) | 157 if (directory.is_pending()) |
158 new DirectoryImpl(std::move(directory), path, nullptr, lock_table_); | 158 new DirectoryImpl(std::move(directory), path, temp_dir_, lock_table_); |
159 callback.Run(FileError::OK); | 159 callback.Run(FileError::OK); |
160 } | 160 } |
161 | 161 |
162 void DirectoryImpl::Rename(const mojo::String& raw_old_path, | 162 void DirectoryImpl::Rename(const mojo::String& raw_old_path, |
163 const mojo::String& raw_new_path, | 163 const mojo::String& raw_new_path, |
164 const RenameCallback& callback) { | 164 const RenameCallback& callback) { |
165 base::FilePath old_path; | 165 base::FilePath old_path; |
166 FileError error = ValidatePath(raw_old_path, directory_path_, &old_path); | 166 FileError error = ValidatePath(raw_old_path, directory_path_, &old_path); |
167 if (error != FileError::OK) { | 167 if (error != FileError::OK) { |
168 callback.Run(error); | 168 callback.Run(error); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 | 260 |
261 base::File::Info info; | 261 base::File::Info info; |
262 if (!base_file.GetInfo(&info)) { | 262 if (!base_file.GetInfo(&info)) { |
263 callback.Run(FileError::FAILED, nullptr); | 263 callback.Run(FileError::FAILED, nullptr); |
264 return; | 264 return; |
265 } | 265 } |
266 | 266 |
267 callback.Run(FileError::OK, MakeFileInformation(info)); | 267 callback.Run(FileError::OK, MakeFileInformation(info)); |
268 } | 268 } |
269 | 269 |
| 270 void DirectoryImpl::Clone(mojo::InterfaceRequest<Directory> directory) { |
| 271 if (directory.is_pending()) { |
| 272 new DirectoryImpl(std::move(directory), directory_path_, |
| 273 temp_dir_, lock_table_); |
| 274 } |
| 275 } |
| 276 |
270 void DirectoryImpl::ReadEntireFile(const mojo::String& raw_path, | 277 void DirectoryImpl::ReadEntireFile(const mojo::String& raw_path, |
271 const ReadEntireFileCallback& callback) { | 278 const ReadEntireFileCallback& callback) { |
272 base::FilePath path; | 279 base::FilePath path; |
273 FileError error = ValidatePath(raw_path, directory_path_, &path); | 280 FileError error = ValidatePath(raw_path, directory_path_, &path); |
274 if (error != FileError::OK) { | 281 if (error != FileError::OK) { |
275 callback.Run(error, mojo::Array<uint8_t>()); | 282 callback.Run(error, mojo::Array<uint8_t>()); |
276 return; | 283 return; |
277 } | 284 } |
278 | 285 |
279 if (base::DirectoryExists(path)) { | 286 if (base::DirectoryExists(path)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 data_size) == -1) { | 333 data_size) == -1) { |
327 callback.Run(GetError(base_file)); | 334 callback.Run(GetError(base_file)); |
328 return; | 335 return; |
329 } | 336 } |
330 } | 337 } |
331 | 338 |
332 callback.Run(FileError::OK); | 339 callback.Run(FileError::OK); |
333 } | 340 } |
334 | 341 |
335 } // namespace filesystem | 342 } // namespace filesystem |
OLD | NEW |