OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/file_system_operation_impl.h" | 5 #include "storage/browser/fileapi/file_system_operation_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 #include "net/url_request/url_request.h" | 12 #include "net/url_request/url_request.h" |
13 #include "webkit/browser/fileapi/async_file_util.h" | 13 #include "storage/browser/fileapi/async_file_util.h" |
14 #include "webkit/browser/fileapi/copy_or_move_operation_delegate.h" | 14 #include "storage/browser/fileapi/copy_or_move_operation_delegate.h" |
15 #include "webkit/browser/fileapi/file_observers.h" | 15 #include "storage/browser/fileapi/file_observers.h" |
16 #include "webkit/browser/fileapi/file_system_backend.h" | 16 #include "storage/browser/fileapi/file_system_backend.h" |
17 #include "webkit/browser/fileapi/file_system_context.h" | 17 #include "storage/browser/fileapi/file_system_context.h" |
18 #include "webkit/browser/fileapi/file_system_file_util.h" | 18 #include "storage/browser/fileapi/file_system_file_util.h" |
19 #include "webkit/browser/fileapi/file_system_operation_context.h" | 19 #include "storage/browser/fileapi/file_system_operation_context.h" |
20 #include "webkit/browser/fileapi/file_system_url.h" | 20 #include "storage/browser/fileapi/file_system_url.h" |
21 #include "webkit/browser/fileapi/file_writer_delegate.h" | 21 #include "storage/browser/fileapi/file_writer_delegate.h" |
22 #include "webkit/browser/fileapi/remove_operation_delegate.h" | 22 #include "storage/browser/fileapi/remove_operation_delegate.h" |
23 #include "webkit/browser/fileapi/sandbox_file_system_backend.h" | 23 #include "storage/browser/fileapi/sandbox_file_system_backend.h" |
24 #include "webkit/browser/quota/quota_manager_proxy.h" | 24 #include "storage/browser/quota/quota_manager_proxy.h" |
25 #include "webkit/common/blob/shareable_file_reference.h" | 25 #include "storage/common/blob/shareable_file_reference.h" |
26 #include "webkit/common/fileapi/file_system_types.h" | 26 #include "storage/common/fileapi/file_system_types.h" |
27 #include "webkit/common/fileapi/file_system_util.h" | 27 #include "storage/common/fileapi/file_system_util.h" |
28 #include "webkit/common/quota/quota_types.h" | 28 #include "storage/common/quota/quota_types.h" |
29 | 29 |
30 using webkit_blob::ScopedFile; | 30 using storage::ScopedFile; |
31 | 31 |
32 namespace fileapi { | 32 namespace storage { |
33 | 33 |
34 FileSystemOperation* FileSystemOperation::Create( | 34 FileSystemOperation* FileSystemOperation::Create( |
35 const FileSystemURL& url, | 35 const FileSystemURL& url, |
36 FileSystemContext* file_system_context, | 36 FileSystemContext* file_system_context, |
37 scoped_ptr<FileSystemOperationContext> operation_context) { | 37 scoped_ptr<FileSystemOperationContext> operation_context) { |
38 return new FileSystemOperationImpl(url, file_system_context, | 38 return new FileSystemOperationImpl( |
39 operation_context.Pass()); | 39 url, file_system_context, operation_context.Pass()); |
40 } | 40 } |
41 | 41 |
42 FileSystemOperationImpl::~FileSystemOperationImpl() { | 42 FileSystemOperationImpl::~FileSystemOperationImpl() { |
43 } | 43 } |
44 | 44 |
45 void FileSystemOperationImpl::CreateFile(const FileSystemURL& url, | 45 void FileSystemOperationImpl::CreateFile(const FileSystemURL& url, |
46 bool exclusive, | 46 bool exclusive, |
47 const StatusCallback& callback) { | 47 const StatusCallback& callback) { |
48 DCHECK(SetPendingOperationType(kOperationCreateFile)); | 48 DCHECK(SetPendingOperationType(kOperationCreateFile)); |
49 GetUsageAndQuotaThenRunTask( | 49 GetUsageAndQuotaThenRunTask( |
50 url, | 50 url, |
51 base::Bind(&FileSystemOperationImpl::DoCreateFile, | 51 base::Bind(&FileSystemOperationImpl::DoCreateFile, |
52 weak_factory_.GetWeakPtr(), url, callback, exclusive), | 52 weak_factory_.GetWeakPtr(), |
| 53 url, |
| 54 callback, |
| 55 exclusive), |
53 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 56 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
54 } | 57 } |
55 | 58 |
56 void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, | 59 void FileSystemOperationImpl::CreateDirectory(const FileSystemURL& url, |
57 bool exclusive, | 60 bool exclusive, |
58 bool recursive, | 61 bool recursive, |
59 const StatusCallback& callback) { | 62 const StatusCallback& callback) { |
60 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); | 63 DCHECK(SetPendingOperationType(kOperationCreateDirectory)); |
61 GetUsageAndQuotaThenRunTask( | 64 GetUsageAndQuotaThenRunTask( |
62 url, | 65 url, |
63 base::Bind(&FileSystemOperationImpl::DoCreateDirectory, | 66 base::Bind(&FileSystemOperationImpl::DoCreateDirectory, |
64 weak_factory_.GetWeakPtr(), url, callback, | 67 weak_factory_.GetWeakPtr(), |
65 exclusive, recursive), | 68 url, |
| 69 callback, |
| 70 exclusive, |
| 71 recursive), |
66 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 72 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
67 } | 73 } |
68 | 74 |
69 void FileSystemOperationImpl::Copy( | 75 void FileSystemOperationImpl::Copy( |
70 const FileSystemURL& src_url, | 76 const FileSystemURL& src_url, |
71 const FileSystemURL& dest_url, | 77 const FileSystemURL& dest_url, |
72 CopyOrMoveOption option, | 78 CopyOrMoveOption option, |
73 const CopyProgressCallback& progress_callback, | 79 const CopyProgressCallback& progress_callback, |
74 const StatusCallback& callback) { | 80 const StatusCallback& callback) { |
75 DCHECK(SetPendingOperationType(kOperationCopy)); | 81 DCHECK(SetPendingOperationType(kOperationCopy)); |
76 DCHECK(!recursive_operation_delegate_); | 82 DCHECK(!recursive_operation_delegate_); |
77 | 83 |
78 // TODO(hidehiko): Support |progress_callback|. (crbug.com/278038). | 84 // TODO(hidehiko): Support |progress_callback|. (crbug.com/278038). |
79 recursive_operation_delegate_.reset( | 85 recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate( |
80 new CopyOrMoveOperationDelegate( | 86 file_system_context(), |
81 file_system_context(), | 87 src_url, |
82 src_url, dest_url, | 88 dest_url, |
83 CopyOrMoveOperationDelegate::OPERATION_COPY, | 89 CopyOrMoveOperationDelegate::OPERATION_COPY, |
84 option, | 90 option, |
85 progress_callback, | 91 progress_callback, |
86 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 92 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
87 weak_factory_.GetWeakPtr(), callback))); | 93 weak_factory_.GetWeakPtr(), |
| 94 callback))); |
88 recursive_operation_delegate_->RunRecursively(); | 95 recursive_operation_delegate_->RunRecursively(); |
89 } | 96 } |
90 | 97 |
91 void FileSystemOperationImpl::Move(const FileSystemURL& src_url, | 98 void FileSystemOperationImpl::Move(const FileSystemURL& src_url, |
92 const FileSystemURL& dest_url, | 99 const FileSystemURL& dest_url, |
93 CopyOrMoveOption option, | 100 CopyOrMoveOption option, |
94 const StatusCallback& callback) { | 101 const StatusCallback& callback) { |
95 DCHECK(SetPendingOperationType(kOperationMove)); | 102 DCHECK(SetPendingOperationType(kOperationMove)); |
96 DCHECK(!recursive_operation_delegate_); | 103 DCHECK(!recursive_operation_delegate_); |
97 recursive_operation_delegate_.reset( | 104 recursive_operation_delegate_.reset(new CopyOrMoveOperationDelegate( |
98 new CopyOrMoveOperationDelegate( | 105 file_system_context(), |
99 file_system_context(), | 106 src_url, |
100 src_url, dest_url, | 107 dest_url, |
101 CopyOrMoveOperationDelegate::OPERATION_MOVE, | 108 CopyOrMoveOperationDelegate::OPERATION_MOVE, |
102 option, | 109 option, |
103 FileSystemOperation::CopyProgressCallback(), | 110 FileSystemOperation::CopyProgressCallback(), |
104 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 111 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
105 weak_factory_.GetWeakPtr(), callback))); | 112 weak_factory_.GetWeakPtr(), |
| 113 callback))); |
106 recursive_operation_delegate_->RunRecursively(); | 114 recursive_operation_delegate_->RunRecursively(); |
107 } | 115 } |
108 | 116 |
109 void FileSystemOperationImpl::DirectoryExists(const FileSystemURL& url, | 117 void FileSystemOperationImpl::DirectoryExists(const FileSystemURL& url, |
110 const StatusCallback& callback) { | 118 const StatusCallback& callback) { |
111 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); | 119 DCHECK(SetPendingOperationType(kOperationDirectoryExists)); |
112 async_file_util_->GetFileInfo( | 120 async_file_util_->GetFileInfo( |
113 operation_context_.Pass(), url, | 121 operation_context_.Pass(), |
| 122 url, |
114 base::Bind(&FileSystemOperationImpl::DidDirectoryExists, | 123 base::Bind(&FileSystemOperationImpl::DidDirectoryExists, |
115 weak_factory_.GetWeakPtr(), callback)); | 124 weak_factory_.GetWeakPtr(), |
| 125 callback)); |
116 } | 126 } |
117 | 127 |
118 void FileSystemOperationImpl::FileExists(const FileSystemURL& url, | 128 void FileSystemOperationImpl::FileExists(const FileSystemURL& url, |
119 const StatusCallback& callback) { | 129 const StatusCallback& callback) { |
120 DCHECK(SetPendingOperationType(kOperationFileExists)); | 130 DCHECK(SetPendingOperationType(kOperationFileExists)); |
121 async_file_util_->GetFileInfo( | 131 async_file_util_->GetFileInfo( |
122 operation_context_.Pass(), url, | 132 operation_context_.Pass(), |
| 133 url, |
123 base::Bind(&FileSystemOperationImpl::DidFileExists, | 134 base::Bind(&FileSystemOperationImpl::DidFileExists, |
124 weak_factory_.GetWeakPtr(), callback)); | 135 weak_factory_.GetWeakPtr(), |
| 136 callback)); |
125 } | 137 } |
126 | 138 |
127 void FileSystemOperationImpl::GetMetadata( | 139 void FileSystemOperationImpl::GetMetadata(const FileSystemURL& url, |
128 const FileSystemURL& url, const GetMetadataCallback& callback) { | 140 const GetMetadataCallback& callback) { |
129 DCHECK(SetPendingOperationType(kOperationGetMetadata)); | 141 DCHECK(SetPendingOperationType(kOperationGetMetadata)); |
130 async_file_util_->GetFileInfo(operation_context_.Pass(), url, callback); | 142 async_file_util_->GetFileInfo(operation_context_.Pass(), url, callback); |
131 } | 143 } |
132 | 144 |
133 void FileSystemOperationImpl::ReadDirectory( | 145 void FileSystemOperationImpl::ReadDirectory( |
134 const FileSystemURL& url, const ReadDirectoryCallback& callback) { | 146 const FileSystemURL& url, |
| 147 const ReadDirectoryCallback& callback) { |
135 DCHECK(SetPendingOperationType(kOperationReadDirectory)); | 148 DCHECK(SetPendingOperationType(kOperationReadDirectory)); |
136 async_file_util_->ReadDirectory( | 149 async_file_util_->ReadDirectory(operation_context_.Pass(), url, callback); |
137 operation_context_.Pass(), url, callback); | |
138 } | 150 } |
139 | 151 |
140 void FileSystemOperationImpl::Remove(const FileSystemURL& url, | 152 void FileSystemOperationImpl::Remove(const FileSystemURL& url, |
141 bool recursive, | 153 bool recursive, |
142 const StatusCallback& callback) { | 154 const StatusCallback& callback) { |
143 DCHECK(SetPendingOperationType(kOperationRemove)); | 155 DCHECK(SetPendingOperationType(kOperationRemove)); |
144 DCHECK(!recursive_operation_delegate_); | 156 DCHECK(!recursive_operation_delegate_); |
145 | 157 |
146 if (recursive) { | 158 if (recursive) { |
147 // For recursive removal, try to delegate the operation to AsyncFileUtil | 159 // For recursive removal, try to delegate the operation to AsyncFileUtil |
148 // first. If not supported, it is delegated to RemoveOperationDelegate | 160 // first. If not supported, it is delegated to RemoveOperationDelegate |
149 // in DidDeleteRecursively. | 161 // in DidDeleteRecursively. |
150 async_file_util_->DeleteRecursively( | 162 async_file_util_->DeleteRecursively( |
151 operation_context_.Pass(), url, | 163 operation_context_.Pass(), |
| 164 url, |
152 base::Bind(&FileSystemOperationImpl::DidDeleteRecursively, | 165 base::Bind(&FileSystemOperationImpl::DidDeleteRecursively, |
153 weak_factory_.GetWeakPtr(), url, callback)); | 166 weak_factory_.GetWeakPtr(), |
| 167 url, |
| 168 callback)); |
154 return; | 169 return; |
155 } | 170 } |
156 | 171 |
157 recursive_operation_delegate_.reset( | 172 recursive_operation_delegate_.reset(new RemoveOperationDelegate( |
158 new RemoveOperationDelegate( | 173 file_system_context(), |
159 file_system_context(), url, | 174 url, |
160 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 175 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
161 weak_factory_.GetWeakPtr(), callback))); | 176 weak_factory_.GetWeakPtr(), |
| 177 callback))); |
162 recursive_operation_delegate_->Run(); | 178 recursive_operation_delegate_->Run(); |
163 } | 179 } |
164 | 180 |
165 void FileSystemOperationImpl::Write( | 181 void FileSystemOperationImpl::Write( |
166 const FileSystemURL& url, | 182 const FileSystemURL& url, |
167 scoped_ptr<FileWriterDelegate> writer_delegate, | 183 scoped_ptr<FileWriterDelegate> writer_delegate, |
168 scoped_ptr<net::URLRequest> blob_request, | 184 scoped_ptr<net::URLRequest> blob_request, |
169 const WriteCallback& callback) { | 185 const WriteCallback& callback) { |
170 DCHECK(SetPendingOperationType(kOperationWrite)); | 186 DCHECK(SetPendingOperationType(kOperationWrite)); |
171 file_writer_delegate_ = writer_delegate.Pass(); | 187 file_writer_delegate_ = writer_delegate.Pass(); |
172 file_writer_delegate_->Start( | 188 file_writer_delegate_->Start(blob_request.Pass(), |
173 blob_request.Pass(), | 189 base::Bind(&FileSystemOperationImpl::DidWrite, |
174 base::Bind(&FileSystemOperationImpl::DidWrite, | 190 weak_factory_.GetWeakPtr(), |
175 weak_factory_.GetWeakPtr(), url, callback)); | 191 url, |
| 192 callback)); |
176 } | 193 } |
177 | 194 |
178 void FileSystemOperationImpl::Truncate(const FileSystemURL& url, int64 length, | 195 void FileSystemOperationImpl::Truncate(const FileSystemURL& url, |
| 196 int64 length, |
179 const StatusCallback& callback) { | 197 const StatusCallback& callback) { |
180 DCHECK(SetPendingOperationType(kOperationTruncate)); | 198 DCHECK(SetPendingOperationType(kOperationTruncate)); |
181 GetUsageAndQuotaThenRunTask( | 199 GetUsageAndQuotaThenRunTask( |
182 url, | 200 url, |
183 base::Bind(&FileSystemOperationImpl::DoTruncate, | 201 base::Bind(&FileSystemOperationImpl::DoTruncate, |
184 weak_factory_.GetWeakPtr(), url, callback, length), | 202 weak_factory_.GetWeakPtr(), |
| 203 url, |
| 204 callback, |
| 205 length), |
185 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 206 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
186 } | 207 } |
187 | 208 |
188 void FileSystemOperationImpl::TouchFile(const FileSystemURL& url, | 209 void FileSystemOperationImpl::TouchFile(const FileSystemURL& url, |
189 const base::Time& last_access_time, | 210 const base::Time& last_access_time, |
190 const base::Time& last_modified_time, | 211 const base::Time& last_modified_time, |
191 const StatusCallback& callback) { | 212 const StatusCallback& callback) { |
192 DCHECK(SetPendingOperationType(kOperationTouchFile)); | 213 DCHECK(SetPendingOperationType(kOperationTouchFile)); |
193 async_file_util_->Touch( | 214 async_file_util_->Touch( |
194 operation_context_.Pass(), url, | 215 operation_context_.Pass(), |
195 last_access_time, last_modified_time, | 216 url, |
| 217 last_access_time, |
| 218 last_modified_time, |
196 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 219 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
197 weak_factory_.GetWeakPtr(), callback)); | 220 weak_factory_.GetWeakPtr(), |
| 221 callback)); |
198 } | 222 } |
199 | 223 |
200 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, | 224 void FileSystemOperationImpl::OpenFile(const FileSystemURL& url, |
201 int file_flags, | 225 int file_flags, |
202 const OpenFileCallback& callback) { | 226 const OpenFileCallback& callback) { |
203 DCHECK(SetPendingOperationType(kOperationOpenFile)); | 227 DCHECK(SetPendingOperationType(kOperationOpenFile)); |
204 | 228 |
205 if (file_flags & | 229 if (file_flags & (base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN)) { |
206 (base::File::FLAG_TEMPORARY | base::File::FLAG_HIDDEN)) { | 230 callback.Run(base::File(base::File::FILE_ERROR_FAILED), base::Closure()); |
207 callback.Run(base::File(base::File::FILE_ERROR_FAILED), | |
208 base::Closure()); | |
209 return; | 231 return; |
210 } | 232 } |
211 GetUsageAndQuotaThenRunTask( | 233 GetUsageAndQuotaThenRunTask( |
212 url, | 234 url, |
213 base::Bind(&FileSystemOperationImpl::DoOpenFile, | 235 base::Bind(&FileSystemOperationImpl::DoOpenFile, |
214 weak_factory_.GetWeakPtr(), | 236 weak_factory_.GetWeakPtr(), |
215 url, callback, file_flags), | 237 url, |
216 base::Bind(callback, Passed(base::File(base::File::FILE_ERROR_FAILED)), | 238 callback, |
| 239 file_flags), |
| 240 base::Bind(callback, |
| 241 Passed(base::File(base::File::FILE_ERROR_FAILED)), |
217 base::Closure())); | 242 base::Closure())); |
218 } | 243 } |
219 | 244 |
220 // We can only get here on a write or truncate that's not yet completed. | 245 // We can only get here on a write or truncate that's not yet completed. |
221 // We don't support cancelling any other operation at this time. | 246 // We don't support cancelling any other operation at this time. |
222 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { | 247 void FileSystemOperationImpl::Cancel(const StatusCallback& cancel_callback) { |
223 DCHECK(cancel_callback_.is_null()); | 248 DCHECK(cancel_callback_.is_null()); |
224 cancel_callback_ = cancel_callback; | 249 cancel_callback_ = cancel_callback; |
225 | 250 |
226 if (file_writer_delegate_.get()) { | 251 if (file_writer_delegate_.get()) { |
(...skipping 19 matching lines...) Expand all Loading... |
246 } | 271 } |
247 | 272 |
248 void FileSystemOperationImpl::CopyInForeignFile( | 273 void FileSystemOperationImpl::CopyInForeignFile( |
249 const base::FilePath& src_local_disk_file_path, | 274 const base::FilePath& src_local_disk_file_path, |
250 const FileSystemURL& dest_url, | 275 const FileSystemURL& dest_url, |
251 const StatusCallback& callback) { | 276 const StatusCallback& callback) { |
252 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); | 277 DCHECK(SetPendingOperationType(kOperationCopyInForeignFile)); |
253 GetUsageAndQuotaThenRunTask( | 278 GetUsageAndQuotaThenRunTask( |
254 dest_url, | 279 dest_url, |
255 base::Bind(&FileSystemOperationImpl::DoCopyInForeignFile, | 280 base::Bind(&FileSystemOperationImpl::DoCopyInForeignFile, |
256 weak_factory_.GetWeakPtr(), src_local_disk_file_path, dest_url, | 281 weak_factory_.GetWeakPtr(), |
| 282 src_local_disk_file_path, |
| 283 dest_url, |
257 callback), | 284 callback), |
258 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 285 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
259 } | 286 } |
260 | 287 |
261 void FileSystemOperationImpl::RemoveFile( | 288 void FileSystemOperationImpl::RemoveFile(const FileSystemURL& url, |
262 const FileSystemURL& url, | 289 const StatusCallback& callback) { |
263 const StatusCallback& callback) { | |
264 DCHECK(SetPendingOperationType(kOperationRemove)); | 290 DCHECK(SetPendingOperationType(kOperationRemove)); |
265 async_file_util_->DeleteFile( | 291 async_file_util_->DeleteFile( |
266 operation_context_.Pass(), url, | 292 operation_context_.Pass(), |
| 293 url, |
267 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 294 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
268 weak_factory_.GetWeakPtr(), callback)); | 295 weak_factory_.GetWeakPtr(), |
| 296 callback)); |
269 } | 297 } |
270 | 298 |
271 void FileSystemOperationImpl::RemoveDirectory( | 299 void FileSystemOperationImpl::RemoveDirectory(const FileSystemURL& url, |
272 const FileSystemURL& url, | 300 const StatusCallback& callback) { |
273 const StatusCallback& callback) { | |
274 DCHECK(SetPendingOperationType(kOperationRemove)); | 301 DCHECK(SetPendingOperationType(kOperationRemove)); |
275 async_file_util_->DeleteDirectory( | 302 async_file_util_->DeleteDirectory( |
276 operation_context_.Pass(), url, | 303 operation_context_.Pass(), |
| 304 url, |
277 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 305 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
278 weak_factory_.GetWeakPtr(), callback)); | 306 weak_factory_.GetWeakPtr(), |
| 307 callback)); |
279 } | 308 } |
280 | 309 |
281 void FileSystemOperationImpl::CopyFileLocal( | 310 void FileSystemOperationImpl::CopyFileLocal( |
282 const FileSystemURL& src_url, | 311 const FileSystemURL& src_url, |
283 const FileSystemURL& dest_url, | 312 const FileSystemURL& dest_url, |
284 CopyOrMoveOption option, | 313 CopyOrMoveOption option, |
285 const CopyFileProgressCallback& progress_callback, | 314 const CopyFileProgressCallback& progress_callback, |
286 const StatusCallback& callback) { | 315 const StatusCallback& callback) { |
287 DCHECK(SetPendingOperationType(kOperationCopy)); | 316 DCHECK(SetPendingOperationType(kOperationCopy)); |
288 DCHECK(src_url.IsInSameFileSystem(dest_url)); | 317 DCHECK(src_url.IsInSameFileSystem(dest_url)); |
289 | 318 |
290 GetUsageAndQuotaThenRunTask( | 319 GetUsageAndQuotaThenRunTask( |
291 dest_url, | 320 dest_url, |
292 base::Bind(&FileSystemOperationImpl::DoCopyFileLocal, | 321 base::Bind(&FileSystemOperationImpl::DoCopyFileLocal, |
293 weak_factory_.GetWeakPtr(), src_url, dest_url, option, | 322 weak_factory_.GetWeakPtr(), |
294 progress_callback, callback), | 323 src_url, |
| 324 dest_url, |
| 325 option, |
| 326 progress_callback, |
| 327 callback), |
295 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 328 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
296 } | 329 } |
297 | 330 |
298 void FileSystemOperationImpl::MoveFileLocal( | 331 void FileSystemOperationImpl::MoveFileLocal(const FileSystemURL& src_url, |
299 const FileSystemURL& src_url, | 332 const FileSystemURL& dest_url, |
300 const FileSystemURL& dest_url, | 333 CopyOrMoveOption option, |
301 CopyOrMoveOption option, | 334 const StatusCallback& callback) { |
302 const StatusCallback& callback) { | |
303 DCHECK(SetPendingOperationType(kOperationMove)); | 335 DCHECK(SetPendingOperationType(kOperationMove)); |
304 DCHECK(src_url.IsInSameFileSystem(dest_url)); | 336 DCHECK(src_url.IsInSameFileSystem(dest_url)); |
305 GetUsageAndQuotaThenRunTask( | 337 GetUsageAndQuotaThenRunTask( |
306 dest_url, | 338 dest_url, |
307 base::Bind(&FileSystemOperationImpl::DoMoveFileLocal, | 339 base::Bind(&FileSystemOperationImpl::DoMoveFileLocal, |
308 weak_factory_.GetWeakPtr(), | 340 weak_factory_.GetWeakPtr(), |
309 src_url, dest_url, option, callback), | 341 src_url, |
| 342 dest_url, |
| 343 option, |
| 344 callback), |
310 base::Bind(callback, base::File::FILE_ERROR_FAILED)); | 345 base::Bind(callback, base::File::FILE_ERROR_FAILED)); |
311 } | 346 } |
312 | 347 |
313 base::File::Error FileSystemOperationImpl::SyncGetPlatformPath( | 348 base::File::Error FileSystemOperationImpl::SyncGetPlatformPath( |
314 const FileSystemURL& url, | 349 const FileSystemURL& url, |
315 base::FilePath* platform_path) { | 350 base::FilePath* platform_path) { |
316 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); | 351 DCHECK(SetPendingOperationType(kOperationGetLocalPath)); |
317 if (!file_system_context()->IsSandboxFileSystem(url.type())) | 352 if (!file_system_context()->IsSandboxFileSystem(url.type())) |
318 return base::File::FILE_ERROR_INVALID_OPERATION; | 353 return base::File::FILE_ERROR_INVALID_OPERATION; |
319 FileSystemFileUtil* file_util = | 354 FileSystemFileUtil* file_util = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 task.Run(); | 386 task.Run(); |
352 return; | 387 return; |
353 } | 388 } |
354 | 389 |
355 DCHECK(quota_manager_proxy); | 390 DCHECK(quota_manager_proxy); |
356 DCHECK(quota_manager_proxy->quota_manager()); | 391 DCHECK(quota_manager_proxy->quota_manager()); |
357 quota_manager_proxy->quota_manager()->GetUsageAndQuota( | 392 quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
358 url.origin(), | 393 url.origin(), |
359 FileSystemTypeToQuotaStorageType(url.type()), | 394 FileSystemTypeToQuotaStorageType(url.type()), |
360 base::Bind(&FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask, | 395 base::Bind(&FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask, |
361 weak_factory_.GetWeakPtr(), task, error_callback)); | 396 weak_factory_.GetWeakPtr(), |
| 397 task, |
| 398 error_callback)); |
362 } | 399 } |
363 | 400 |
364 void FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask( | 401 void FileSystemOperationImpl::DidGetUsageAndQuotaAndRunTask( |
365 const base::Closure& task, | 402 const base::Closure& task, |
366 const base::Closure& error_callback, | 403 const base::Closure& error_callback, |
367 quota::QuotaStatusCode status, | 404 quota::QuotaStatusCode status, |
368 int64 usage, int64 quota) { | 405 int64 usage, |
| 406 int64 quota) { |
369 if (status != quota::kQuotaStatusOk) { | 407 if (status != quota::kQuotaStatusOk) { |
370 LOG(WARNING) << "Got unexpected quota error : " << status; | 408 LOG(WARNING) << "Got unexpected quota error : " << status; |
371 error_callback.Run(); | 409 error_callback.Run(); |
372 return; | 410 return; |
373 } | 411 } |
374 | 412 |
375 operation_context_->set_allowed_bytes_growth(quota - usage); | 413 operation_context_->set_allowed_bytes_growth(quota - usage); |
376 task.Run(); | 414 task.Run(); |
377 } | 415 } |
378 | 416 |
379 void FileSystemOperationImpl::DoCreateFile( | 417 void FileSystemOperationImpl::DoCreateFile(const FileSystemURL& url, |
380 const FileSystemURL& url, | 418 const StatusCallback& callback, |
381 const StatusCallback& callback, | 419 bool exclusive) { |
382 bool exclusive) { | |
383 async_file_util_->EnsureFileExists( | 420 async_file_util_->EnsureFileExists( |
384 operation_context_.Pass(), url, | 421 operation_context_.Pass(), |
| 422 url, |
385 base::Bind( | 423 base::Bind( |
386 exclusive ? | 424 exclusive ? &FileSystemOperationImpl::DidEnsureFileExistsExclusive |
387 &FileSystemOperationImpl::DidEnsureFileExistsExclusive : | 425 : &FileSystemOperationImpl::DidEnsureFileExistsNonExclusive, |
388 &FileSystemOperationImpl::DidEnsureFileExistsNonExclusive, | 426 weak_factory_.GetWeakPtr(), |
389 weak_factory_.GetWeakPtr(), callback)); | 427 callback)); |
390 } | 428 } |
391 | 429 |
392 void FileSystemOperationImpl::DoCreateDirectory( | 430 void FileSystemOperationImpl::DoCreateDirectory(const FileSystemURL& url, |
393 const FileSystemURL& url, | 431 const StatusCallback& callback, |
394 const StatusCallback& callback, | 432 bool exclusive, |
395 bool exclusive, bool recursive) { | 433 bool recursive) { |
396 async_file_util_->CreateDirectory( | 434 async_file_util_->CreateDirectory( |
397 operation_context_.Pass(), | 435 operation_context_.Pass(), |
398 url, exclusive, recursive, | 436 url, |
| 437 exclusive, |
| 438 recursive, |
399 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 439 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
400 weak_factory_.GetWeakPtr(), callback)); | 440 weak_factory_.GetWeakPtr(), |
| 441 callback)); |
401 } | 442 } |
402 | 443 |
403 void FileSystemOperationImpl::DoCopyFileLocal( | 444 void FileSystemOperationImpl::DoCopyFileLocal( |
404 const FileSystemURL& src_url, | 445 const FileSystemURL& src_url, |
405 const FileSystemURL& dest_url, | 446 const FileSystemURL& dest_url, |
406 CopyOrMoveOption option, | 447 CopyOrMoveOption option, |
407 const CopyFileProgressCallback& progress_callback, | 448 const CopyFileProgressCallback& progress_callback, |
408 const StatusCallback& callback) { | 449 const StatusCallback& callback) { |
409 async_file_util_->CopyFileLocal( | 450 async_file_util_->CopyFileLocal( |
410 operation_context_.Pass(), src_url, dest_url, option, progress_callback, | 451 operation_context_.Pass(), |
| 452 src_url, |
| 453 dest_url, |
| 454 option, |
| 455 progress_callback, |
411 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 456 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
412 weak_factory_.GetWeakPtr(), callback)); | 457 weak_factory_.GetWeakPtr(), |
| 458 callback)); |
413 } | 459 } |
414 | 460 |
415 void FileSystemOperationImpl::DoMoveFileLocal( | 461 void FileSystemOperationImpl::DoMoveFileLocal(const FileSystemURL& src_url, |
416 const FileSystemURL& src_url, | 462 const FileSystemURL& dest_url, |
417 const FileSystemURL& dest_url, | 463 CopyOrMoveOption option, |
418 CopyOrMoveOption option, | 464 const StatusCallback& callback) { |
419 const StatusCallback& callback) { | |
420 async_file_util_->MoveFileLocal( | 465 async_file_util_->MoveFileLocal( |
421 operation_context_.Pass(), src_url, dest_url, option, | 466 operation_context_.Pass(), |
| 467 src_url, |
| 468 dest_url, |
| 469 option, |
422 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 470 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
423 weak_factory_.GetWeakPtr(), callback)); | 471 weak_factory_.GetWeakPtr(), |
| 472 callback)); |
424 } | 473 } |
425 | 474 |
426 void FileSystemOperationImpl::DoCopyInForeignFile( | 475 void FileSystemOperationImpl::DoCopyInForeignFile( |
427 const base::FilePath& src_local_disk_file_path, | 476 const base::FilePath& src_local_disk_file_path, |
428 const FileSystemURL& dest_url, | 477 const FileSystemURL& dest_url, |
429 const StatusCallback& callback) { | 478 const StatusCallback& callback) { |
430 async_file_util_->CopyInForeignFile( | 479 async_file_util_->CopyInForeignFile( |
431 operation_context_.Pass(), | 480 operation_context_.Pass(), |
432 src_local_disk_file_path, dest_url, | 481 src_local_disk_file_path, |
| 482 dest_url, |
433 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 483 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
434 weak_factory_.GetWeakPtr(), callback)); | 484 weak_factory_.GetWeakPtr(), |
| 485 callback)); |
435 } | 486 } |
436 | 487 |
437 void FileSystemOperationImpl::DoTruncate(const FileSystemURL& url, | 488 void FileSystemOperationImpl::DoTruncate(const FileSystemURL& url, |
438 const StatusCallback& callback, | 489 const StatusCallback& callback, |
439 int64 length) { | 490 int64 length) { |
440 async_file_util_->Truncate( | 491 async_file_util_->Truncate( |
441 operation_context_.Pass(), url, length, | 492 operation_context_.Pass(), |
| 493 url, |
| 494 length, |
442 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 495 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
443 weak_factory_.GetWeakPtr(), callback)); | 496 weak_factory_.GetWeakPtr(), |
| 497 callback)); |
444 } | 498 } |
445 | 499 |
446 void FileSystemOperationImpl::DoOpenFile(const FileSystemURL& url, | 500 void FileSystemOperationImpl::DoOpenFile(const FileSystemURL& url, |
447 const OpenFileCallback& callback, | 501 const OpenFileCallback& callback, |
448 int file_flags) { | 502 int file_flags) { |
449 async_file_util_->CreateOrOpen( | 503 async_file_util_->CreateOrOpen( |
450 operation_context_.Pass(), url, file_flags, | 504 operation_context_.Pass(), |
| 505 url, |
| 506 file_flags, |
451 base::Bind(&FileSystemOperationImpl::DidOpenFile, | 507 base::Bind(&FileSystemOperationImpl::DidOpenFile, |
452 weak_factory_.GetWeakPtr(), callback)); | 508 weak_factory_.GetWeakPtr(), |
| 509 callback)); |
453 } | 510 } |
454 | 511 |
455 void FileSystemOperationImpl::DidEnsureFileExistsExclusive( | 512 void FileSystemOperationImpl::DidEnsureFileExistsExclusive( |
456 const StatusCallback& callback, | 513 const StatusCallback& callback, |
457 base::File::Error rv, bool created) { | 514 base::File::Error rv, |
| 515 bool created) { |
458 if (rv == base::File::FILE_OK && !created) { | 516 if (rv == base::File::FILE_OK && !created) { |
459 callback.Run(base::File::FILE_ERROR_EXISTS); | 517 callback.Run(base::File::FILE_ERROR_EXISTS); |
460 } else { | 518 } else { |
461 DidFinishOperation(callback, rv); | 519 DidFinishOperation(callback, rv); |
462 } | 520 } |
463 } | 521 } |
464 | 522 |
465 void FileSystemOperationImpl::DidEnsureFileExistsNonExclusive( | 523 void FileSystemOperationImpl::DidEnsureFileExistsNonExclusive( |
466 const StatusCallback& callback, | 524 const StatusCallback& callback, |
467 base::File::Error rv, bool /* created */) { | 525 base::File::Error rv, |
| 526 bool /* created */) { |
468 DidFinishOperation(callback, rv); | 527 DidFinishOperation(callback, rv); |
469 } | 528 } |
470 | 529 |
471 void FileSystemOperationImpl::DidFinishOperation( | 530 void FileSystemOperationImpl::DidFinishOperation(const StatusCallback& callback, |
472 const StatusCallback& callback, | 531 base::File::Error rv) { |
473 base::File::Error rv) { | |
474 if (!cancel_callback_.is_null()) { | 532 if (!cancel_callback_.is_null()) { |
475 StatusCallback cancel_callback = cancel_callback_; | 533 StatusCallback cancel_callback = cancel_callback_; |
476 callback.Run(rv); | 534 callback.Run(rv); |
477 | 535 |
478 // Return OK only if we succeeded to stop the operation. | 536 // Return OK only if we succeeded to stop the operation. |
479 cancel_callback.Run(rv == base::File::FILE_ERROR_ABORT ? | 537 cancel_callback.Run(rv == base::File::FILE_ERROR_ABORT |
480 base::File::FILE_OK : | 538 ? base::File::FILE_OK |
481 base::File::FILE_ERROR_INVALID_OPERATION); | 539 : base::File::FILE_ERROR_INVALID_OPERATION); |
482 } else { | 540 } else { |
483 callback.Run(rv); | 541 callback.Run(rv); |
484 } | 542 } |
485 } | 543 } |
486 | 544 |
487 void FileSystemOperationImpl::DidDirectoryExists( | 545 void FileSystemOperationImpl::DidDirectoryExists( |
488 const StatusCallback& callback, | 546 const StatusCallback& callback, |
489 base::File::Error rv, | 547 base::File::Error rv, |
490 const base::File::Info& file_info) { | 548 const base::File::Info& file_info) { |
491 if (rv == base::File::FILE_OK && !file_info.is_directory) | 549 if (rv == base::File::FILE_OK && !file_info.is_directory) |
492 rv = base::File::FILE_ERROR_NOT_A_DIRECTORY; | 550 rv = base::File::FILE_ERROR_NOT_A_DIRECTORY; |
493 callback.Run(rv); | 551 callback.Run(rv); |
494 } | 552 } |
495 | 553 |
496 void FileSystemOperationImpl::DidFileExists( | 554 void FileSystemOperationImpl::DidFileExists(const StatusCallback& callback, |
497 const StatusCallback& callback, | 555 base::File::Error rv, |
498 base::File::Error rv, | 556 const base::File::Info& file_info) { |
499 const base::File::Info& file_info) { | |
500 if (rv == base::File::FILE_OK && file_info.is_directory) | 557 if (rv == base::File::FILE_OK && file_info.is_directory) |
501 rv = base::File::FILE_ERROR_NOT_A_FILE; | 558 rv = base::File::FILE_ERROR_NOT_A_FILE; |
502 callback.Run(rv); | 559 callback.Run(rv); |
503 } | 560 } |
504 | 561 |
505 void FileSystemOperationImpl::DidDeleteRecursively( | 562 void FileSystemOperationImpl::DidDeleteRecursively( |
506 const FileSystemURL& url, | 563 const FileSystemURL& url, |
507 const StatusCallback& callback, | 564 const StatusCallback& callback, |
508 base::File::Error rv) { | 565 base::File::Error rv) { |
509 if (rv == base::File::FILE_ERROR_INVALID_OPERATION) { | 566 if (rv == base::File::FILE_ERROR_INVALID_OPERATION) { |
510 // Recursive removal is not supported on this platform. | 567 // Recursive removal is not supported on this platform. |
511 DCHECK(!recursive_operation_delegate_); | 568 DCHECK(!recursive_operation_delegate_); |
512 recursive_operation_delegate_.reset( | 569 recursive_operation_delegate_.reset(new RemoveOperationDelegate( |
513 new RemoveOperationDelegate( | 570 file_system_context(), |
514 file_system_context(), url, | 571 url, |
515 base::Bind(&FileSystemOperationImpl::DidFinishOperation, | 572 base::Bind(&FileSystemOperationImpl::DidFinishOperation, |
516 weak_factory_.GetWeakPtr(), callback))); | 573 weak_factory_.GetWeakPtr(), |
| 574 callback))); |
517 recursive_operation_delegate_->RunRecursively(); | 575 recursive_operation_delegate_->RunRecursively(); |
518 return; | 576 return; |
519 } | 577 } |
520 | 578 |
521 callback.Run(rv); | 579 callback.Run(rv); |
522 } | 580 } |
523 | 581 |
524 void FileSystemOperationImpl::DidWrite( | 582 void FileSystemOperationImpl::DidWrite( |
525 const FileSystemURL& url, | 583 const FileSystemURL& url, |
526 const WriteCallback& write_callback, | 584 const WriteCallback& write_callback, |
527 base::File::Error rv, | 585 base::File::Error rv, |
528 int64 bytes, | 586 int64 bytes, |
529 FileWriterDelegate::WriteProgressStatus write_status) { | 587 FileWriterDelegate::WriteProgressStatus write_status) { |
530 const bool complete = ( | 588 const bool complete = |
531 write_status != FileWriterDelegate::SUCCESS_IO_PENDING); | 589 (write_status != FileWriterDelegate::SUCCESS_IO_PENDING); |
532 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { | 590 if (complete && write_status != FileWriterDelegate::ERROR_WRITE_NOT_STARTED) { |
533 DCHECK(operation_context_); | 591 DCHECK(operation_context_); |
534 operation_context_->change_observers()->Notify( | 592 operation_context_->change_observers()->Notify( |
535 &FileChangeObserver::OnModifyFile, MakeTuple(url)); | 593 &FileChangeObserver::OnModifyFile, MakeTuple(url)); |
536 } | 594 } |
537 | 595 |
538 StatusCallback cancel_callback = cancel_callback_; | 596 StatusCallback cancel_callback = cancel_callback_; |
539 write_callback.Run(rv, bytes, complete); | 597 write_callback.Run(rv, bytes, complete); |
540 if (!cancel_callback.is_null()) | 598 if (!cancel_callback.is_null()) |
541 cancel_callback.Run(base::File::FILE_OK); | 599 cancel_callback.Run(base::File::FILE_OK); |
542 } | 600 } |
543 | 601 |
544 void FileSystemOperationImpl::DidOpenFile( | 602 void FileSystemOperationImpl::DidOpenFile( |
545 const OpenFileCallback& callback, | 603 const OpenFileCallback& callback, |
546 base::File file, | 604 base::File file, |
547 const base::Closure& on_close_callback) { | 605 const base::Closure& on_close_callback) { |
548 callback.Run(file.Pass(), on_close_callback); | 606 callback.Run(file.Pass(), on_close_callback); |
549 } | 607 } |
550 | 608 |
551 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { | 609 bool FileSystemOperationImpl::SetPendingOperationType(OperationType type) { |
552 if (pending_operation_ != kOperationNone) | 610 if (pending_operation_ != kOperationNone) |
553 return false; | 611 return false; |
554 pending_operation_ = type; | 612 pending_operation_ = type; |
555 return true; | 613 return true; |
556 } | 614 } |
557 | 615 |
558 } // namespace fileapi | 616 } // namespace storage |
OLD | NEW |