OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "webkit/browser/fileapi/async_file_util_adapter.h" | 5 #include "webkit/browser/fileapi/async_file_util_adapter.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
11 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
12 #include "webkit/browser/fileapi/file_system_context.h" | 12 #include "webkit/browser/fileapi/file_system_context.h" |
13 #include "webkit/browser/fileapi/file_system_file_util.h" | 13 #include "webkit/browser/fileapi/file_system_file_util.h" |
14 #include "webkit/browser/fileapi/file_system_operation_context.h" | 14 #include "webkit/browser/fileapi/file_system_operation_context.h" |
15 #include "webkit/browser/fileapi/file_system_url.h" | 15 #include "webkit/browser/fileapi/file_system_url.h" |
16 #include "webkit/common/blob/shareable_file_reference.h" | 16 #include "webkit/common/blob/shareable_file_reference.h" |
17 #include "webkit/common/fileapi/file_system_util.h" | 17 #include "webkit/common/fileapi/file_system_util.h" |
18 | 18 |
19 using base::Bind; | 19 using base::Bind; |
20 using base::Callback; | 20 using base::Callback; |
21 using base::Owned; | 21 using base::Owned; |
22 using base::PlatformFileError; | |
23 using base::Unretained; | 22 using base::Unretained; |
24 using webkit_blob::ShareableFileReference; | 23 using webkit_blob::ShareableFileReference; |
25 | 24 |
26 namespace fileapi { | 25 namespace fileapi { |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 class EnsureFileExistsHelper { | 29 class EnsureFileExistsHelper { |
31 public: | 30 public: |
32 EnsureFileExistsHelper() : error_(base::PLATFORM_FILE_OK), created_(false) {} | 31 EnsureFileExistsHelper() : error_(base::File::FILE_OK), created_(false) {} |
33 | 32 |
34 void RunWork(FileSystemFileUtil* file_util, | 33 void RunWork(FileSystemFileUtil* file_util, |
35 FileSystemOperationContext* context, | 34 FileSystemOperationContext* context, |
36 const FileSystemURL& url) { | 35 const FileSystemURL& url) { |
37 error_ = file_util->EnsureFileExists(context, url, &created_); | 36 error_ = file_util->EnsureFileExists(context, url, &created_); |
38 } | 37 } |
39 | 38 |
40 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) { | 39 void Reply(const AsyncFileUtil::EnsureFileExistsCallback& callback) { |
41 callback.Run(error_, created_); | 40 callback.Run(error_, created_); |
42 } | 41 } |
43 | 42 |
44 private: | 43 private: |
45 base::PlatformFileError error_; | 44 base::File::Error error_; |
46 bool created_; | 45 bool created_; |
47 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); | 46 DISALLOW_COPY_AND_ASSIGN(EnsureFileExistsHelper); |
48 }; | 47 }; |
49 | 48 |
50 class GetFileInfoHelper { | 49 class GetFileInfoHelper { |
51 public: | 50 public: |
52 GetFileInfoHelper() | 51 GetFileInfoHelper() |
53 : error_(base::PLATFORM_FILE_OK) {} | 52 : error_(base::File::FILE_OK) {} |
54 | 53 |
55 void GetFileInfo(FileSystemFileUtil* file_util, | 54 void GetFileInfo(FileSystemFileUtil* file_util, |
56 FileSystemOperationContext* context, | 55 FileSystemOperationContext* context, |
57 const FileSystemURL& url) { | 56 const FileSystemURL& url) { |
58 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); | 57 error_ = file_util->GetFileInfo(context, url, &file_info_, &platform_path_); |
59 } | 58 } |
60 | 59 |
61 void CreateSnapshotFile(FileSystemFileUtil* file_util, | 60 void CreateSnapshotFile(FileSystemFileUtil* file_util, |
62 FileSystemOperationContext* context, | 61 FileSystemOperationContext* context, |
63 const FileSystemURL& url) { | 62 const FileSystemURL& url) { |
64 scoped_file_ = file_util->CreateSnapshotFile( | 63 scoped_file_ = file_util->CreateSnapshotFile( |
65 context, url, &error_, &file_info_, &platform_path_); | 64 context, url, &error_, &file_info_, &platform_path_); |
66 } | 65 } |
67 | 66 |
68 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) { | 67 void ReplyFileInfo(const AsyncFileUtil::GetFileInfoCallback& callback) { |
69 callback.Run(error_, file_info_); | 68 callback.Run(error_, file_info_); |
70 } | 69 } |
71 | 70 |
72 void ReplySnapshotFile( | 71 void ReplySnapshotFile( |
73 const AsyncFileUtil::CreateSnapshotFileCallback& callback) { | 72 const AsyncFileUtil::CreateSnapshotFileCallback& callback) { |
74 callback.Run(error_, file_info_, platform_path_, | 73 callback.Run(error_, file_info_, platform_path_, |
75 ShareableFileReference::GetOrCreate(scoped_file_.Pass())); | 74 ShareableFileReference::GetOrCreate(scoped_file_.Pass())); |
76 } | 75 } |
77 | 76 |
78 private: | 77 private: |
79 base::PlatformFileError error_; | 78 base::File::Error error_; |
80 base::PlatformFileInfo file_info_; | 79 base::File::Info file_info_; |
81 base::FilePath platform_path_; | 80 base::FilePath platform_path_; |
82 webkit_blob::ScopedFile scoped_file_; | 81 webkit_blob::ScopedFile scoped_file_; |
83 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); | 82 DISALLOW_COPY_AND_ASSIGN(GetFileInfoHelper); |
84 }; | 83 }; |
85 | 84 |
86 class ReadDirectoryHelper { | 85 class ReadDirectoryHelper { |
87 public: | 86 public: |
88 ReadDirectoryHelper() : error_(base::PLATFORM_FILE_OK) {} | 87 ReadDirectoryHelper() : error_(base::File::FILE_OK) {} |
89 | 88 |
90 void RunWork(FileSystemFileUtil* file_util, | 89 void RunWork(FileSystemFileUtil* file_util, |
91 FileSystemOperationContext* context, | 90 FileSystemOperationContext* context, |
92 const FileSystemURL& url) { | 91 const FileSystemURL& url) { |
93 base::PlatformFileInfo file_info; | 92 base::File::Info file_info; |
94 base::FilePath platform_path; | 93 base::FilePath platform_path; |
95 PlatformFileError error = file_util->GetFileInfo( | 94 base::File::Error error = file_util->GetFileInfo( |
96 context, url, &file_info, &platform_path); | 95 context, url, &file_info, &platform_path); |
97 if (error != base::PLATFORM_FILE_OK) { | 96 if (error != base::File::FILE_OK) { |
98 error_ = error; | 97 error_ = error; |
99 return; | 98 return; |
100 } | 99 } |
101 if (!file_info.is_directory) { | 100 if (!file_info.is_directory) { |
102 error_ = base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 101 error_ = base::File::FILE_ERROR_NOT_A_DIRECTORY; |
103 return; | 102 return; |
104 } | 103 } |
105 | 104 |
106 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( | 105 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> file_enum( |
107 file_util->CreateFileEnumerator(context, url)); | 106 file_util->CreateFileEnumerator(context, url)); |
108 | 107 |
109 base::FilePath current; | 108 base::FilePath current; |
110 while (!(current = file_enum->Next()).empty()) { | 109 while (!(current = file_enum->Next()).empty()) { |
111 DirectoryEntry entry; | 110 DirectoryEntry entry; |
112 entry.is_directory = file_enum->IsDirectory(); | 111 entry.is_directory = file_enum->IsDirectory(); |
113 entry.name = VirtualPath::BaseName(current).value(); | 112 entry.name = VirtualPath::BaseName(current).value(); |
114 entry.size = file_enum->Size(); | 113 entry.size = file_enum->Size(); |
115 entry.last_modified_time = file_enum->LastModifiedTime(); | 114 entry.last_modified_time = file_enum->LastModifiedTime(); |
116 entries_.push_back(entry); | 115 entries_.push_back(entry); |
117 } | 116 } |
118 error_ = base::PLATFORM_FILE_OK; | 117 error_ = base::File::FILE_OK; |
119 } | 118 } |
120 | 119 |
121 void Reply(const AsyncFileUtil::ReadDirectoryCallback& callback) { | 120 void Reply(const AsyncFileUtil::ReadDirectoryCallback& callback) { |
122 callback.Run(error_, entries_, false /* has_more */); | 121 callback.Run(error_, entries_, false /* has_more */); |
123 } | 122 } |
124 | 123 |
125 private: | 124 private: |
126 base::PlatformFileError error_; | 125 base::File::Error error_; |
127 std::vector<DirectoryEntry> entries_; | 126 std::vector<DirectoryEntry> entries_; |
128 DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper); | 127 DISALLOW_COPY_AND_ASSIGN(ReadDirectoryHelper); |
129 }; | 128 }; |
130 | 129 |
131 void RunCreateOrOpenCallback( | 130 void RunCreateOrOpenCallback( |
132 const AsyncFileUtil::CreateOrOpenCallback& callback, | 131 const AsyncFileUtil::CreateOrOpenCallback& callback, |
133 base::PlatformFileError result, | 132 base::File::Error result, |
134 base::PassPlatformFile file, | 133 base::PassPlatformFile file, |
135 bool created) { | 134 bool created) { |
136 callback.Run(result, file, base::Closure()); | 135 callback.Run(result, file, base::Closure()); |
137 } | 136 } |
138 | 137 |
139 } // namespace | 138 } // namespace |
140 | 139 |
141 AsyncFileUtilAdapter::AsyncFileUtilAdapter( | 140 AsyncFileUtilAdapter::AsyncFileUtilAdapter( |
142 FileSystemFileUtil* sync_file_util) | 141 FileSystemFileUtil* sync_file_util) |
143 : sync_file_util_(sync_file_util) { | 142 : sync_file_util_(sync_file_util) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 Unretained(sync_file_util_.get()), | 324 Unretained(sync_file_util_.get()), |
326 base::Owned(context_ptr), url), | 325 base::Owned(context_ptr), url), |
327 callback); | 326 callback); |
328 DCHECK(success); | 327 DCHECK(success); |
329 } | 328 } |
330 | 329 |
331 void AsyncFileUtilAdapter::DeleteRecursively( | 330 void AsyncFileUtilAdapter::DeleteRecursively( |
332 scoped_ptr<FileSystemOperationContext> context, | 331 scoped_ptr<FileSystemOperationContext> context, |
333 const FileSystemURL& url, | 332 const FileSystemURL& url, |
334 const StatusCallback& callback) { | 333 const StatusCallback& callback) { |
335 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 334 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
336 } | 335 } |
337 | 336 |
338 void AsyncFileUtilAdapter::CreateSnapshotFile( | 337 void AsyncFileUtilAdapter::CreateSnapshotFile( |
339 scoped_ptr<FileSystemOperationContext> context, | 338 scoped_ptr<FileSystemOperationContext> context, |
340 const FileSystemURL& url, | 339 const FileSystemURL& url, |
341 const CreateSnapshotFileCallback& callback) { | 340 const CreateSnapshotFileCallback& callback) { |
342 FileSystemOperationContext* context_ptr = context.release(); | 341 FileSystemOperationContext* context_ptr = context.release(); |
343 GetFileInfoHelper* helper = new GetFileInfoHelper; | 342 GetFileInfoHelper* helper = new GetFileInfoHelper; |
344 const bool success = context_ptr->task_runner()->PostTaskAndReply( | 343 const bool success = context_ptr->task_runner()->PostTaskAndReply( |
345 FROM_HERE, | 344 FROM_HERE, |
346 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), | 345 Bind(&GetFileInfoHelper::CreateSnapshotFile, Unretained(helper), |
347 sync_file_util_.get(), base::Owned(context_ptr), url), | 346 sync_file_util_.get(), base::Owned(context_ptr), url), |
348 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); | 347 Bind(&GetFileInfoHelper::ReplySnapshotFile, Owned(helper), callback)); |
349 DCHECK(success); | 348 DCHECK(success); |
350 } | 349 } |
351 | 350 |
352 } // namespace fileapi | 351 } // namespace fileapi |
OLD | NEW |