OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/fileapi/file_system_operation.h" | 5 #include "webkit/fileapi/file_system_operation.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 FileSystemOperation::~FileSystemOperation() { | 73 FileSystemOperation::~FileSystemOperation() { |
74 if (file_writer_delegate_.get()) | 74 if (file_writer_delegate_.get()) |
75 FileSystemFileUtilProxy::Close( | 75 FileSystemFileUtilProxy::Close( |
76 operation_context_, proxy_, file_writer_delegate_->file(), | 76 operation_context_, proxy_, file_writer_delegate_->file(), |
77 FileSystemFileUtilProxy::StatusCallback()); | 77 FileSystemFileUtilProxy::StatusCallback()); |
78 } | 78 } |
79 | 79 |
80 void FileSystemOperation::OpenFileSystem( | 80 void FileSystemOperation::OpenFileSystem( |
81 const GURL& origin_url, fileapi::FileSystemType type, bool create) { | 81 const GURL& origin_url, fileapi::FileSystemType type, bool create) { |
82 #ifndef NDEBUG | 82 #ifndef NDEBUG |
83 DCHECK(dispatcher); | |
kinuko
2011/10/26 12:09:26
s/dispatcher/dispatcher_/ here and everywhere?
Oleg Eterevsky
2011/10/26 12:19:24
Sorry, my bad. I've send the CL before waiting for
| |
83 DCHECK(kOperationNone == pending_operation_); | 84 DCHECK(kOperationNone == pending_operation_); |
84 pending_operation_ = static_cast<FileSystemOperation::OperationType>( | 85 pending_operation_ = static_cast<FileSystemOperation::OperationType>( |
85 kOperationOpenFileSystem); | 86 kOperationOpenFileSystem); |
86 #endif | 87 #endif |
87 | 88 |
88 DCHECK(file_system_context()); | 89 DCHECK(file_system_context()); |
89 operation_context_.set_src_origin_url(origin_url); | 90 operation_context_.set_src_origin_url(origin_url); |
90 operation_context_.set_src_type(type); | 91 operation_context_.set_src_type(type); |
91 // TODO(ericu): We don't really need to make this call if !create. | 92 // TODO(ericu): We don't really need to make this call if !create. |
92 // Also, in the future we won't need it either way, as long as we do all | 93 // Also, in the future we won't need it either way, as long as we do all |
93 // permission+quota checks beforehand. We only need it now because we have to | 94 // permission+quota checks beforehand. We only need it now because we have to |
94 // create an unpredictable directory name. Without that, we could lazily | 95 // create an unpredictable directory name. Without that, we could lazily |
95 // create the root later on the first filesystem write operation, and just | 96 // create the root later on the first filesystem write operation, and just |
96 // return GetFileSystemRootURI() here. | 97 // return GetFileSystemRootURI() here. |
97 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( | 98 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( |
98 origin_url, type, create, | 99 origin_url, type, create, |
99 base::Bind(&FileSystemOperation::DidGetRootPath, | 100 base::Bind(&FileSystemOperation::DidGetRootPath, |
100 weak_factory_.GetWeakPtr())); | 101 weak_factory_.GetWeakPtr())); |
101 } | 102 } |
102 | 103 |
103 void FileSystemOperation::CreateFile(const GURL& path, | 104 void FileSystemOperation::CreateFile(const GURL& path, |
104 bool exclusive) { | 105 bool exclusive) { |
105 #ifndef NDEBUG | 106 #ifndef NDEBUG |
107 DCHECK(dispatcher); | |
106 DCHECK(kOperationNone == pending_operation_); | 108 DCHECK(kOperationNone == pending_operation_); |
107 pending_operation_ = kOperationCreateFile; | 109 pending_operation_ = kOperationCreateFile; |
108 #endif | 110 #endif |
109 if (!SetupSrcContextForWrite(path, true)) { | 111 if (!SetupSrcContextForWrite(path, true)) { |
110 delete this; | 112 delete this; |
111 return; | 113 return; |
112 } | 114 } |
113 exclusive_ = exclusive; | 115 exclusive_ = exclusive; |
114 | 116 |
115 GetUsageAndQuotaThenCallback( | 117 GetUsageAndQuotaThenCallback( |
(...skipping 18 matching lines...) Expand all Loading... | |
134 base::Bind( | 136 base::Bind( |
135 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive | 137 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive |
136 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, | 138 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, |
137 weak_factory_.GetWeakPtr())); | 139 weak_factory_.GetWeakPtr())); |
138 } | 140 } |
139 | 141 |
140 void FileSystemOperation::CreateDirectory(const GURL& path, | 142 void FileSystemOperation::CreateDirectory(const GURL& path, |
141 bool exclusive, | 143 bool exclusive, |
142 bool recursive) { | 144 bool recursive) { |
143 #ifndef NDEBUG | 145 #ifndef NDEBUG |
146 DCHECK(dispatcher); | |
144 DCHECK(kOperationNone == pending_operation_); | 147 DCHECK(kOperationNone == pending_operation_); |
145 pending_operation_ = kOperationCreateDirectory; | 148 pending_operation_ = kOperationCreateDirectory; |
146 #endif | 149 #endif |
147 if (!SetupSrcContextForWrite(path, true)) { | 150 if (!SetupSrcContextForWrite(path, true)) { |
148 delete this; | 151 delete this; |
149 return; | 152 return; |
150 } | 153 } |
151 exclusive_ = exclusive; | 154 exclusive_ = exclusive; |
152 recursive_ = recursive; | 155 recursive_ = recursive; |
153 | 156 |
(...skipping 15 matching lines...) Expand all Loading... | |
169 FileSystemFileUtilProxy::CreateDirectory( | 172 FileSystemFileUtilProxy::CreateDirectory( |
170 operation_context_, proxy_, src_virtual_path_, exclusive_, | 173 operation_context_, proxy_, src_virtual_path_, exclusive_, |
171 recursive_, | 174 recursive_, |
172 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 175 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
173 weak_factory_.GetWeakPtr())); | 176 weak_factory_.GetWeakPtr())); |
174 } | 177 } |
175 | 178 |
176 void FileSystemOperation::Copy(const GURL& src_path, | 179 void FileSystemOperation::Copy(const GURL& src_path, |
177 const GURL& dest_path) { | 180 const GURL& dest_path) { |
178 #ifndef NDEBUG | 181 #ifndef NDEBUG |
182 DCHECK(dispatcher); | |
179 DCHECK(kOperationNone == pending_operation_); | 183 DCHECK(kOperationNone == pending_operation_); |
180 pending_operation_ = kOperationCopy; | 184 pending_operation_ = kOperationCopy; |
181 #endif | 185 #endif |
182 if (!SetupSrcContextForRead(src_path) || | 186 if (!SetupSrcContextForRead(src_path) || |
183 !SetupDestContextForWrite(dest_path, true)) { | 187 !SetupDestContextForWrite(dest_path, true)) { |
184 delete this; | 188 delete this; |
185 return; | 189 return; |
186 } | 190 } |
187 | 191 |
188 GetUsageAndQuotaThenCallback( | 192 GetUsageAndQuotaThenCallback( |
(...skipping 14 matching lines...) Expand all Loading... | |
203 FileSystemFileUtilProxy::Copy( | 207 FileSystemFileUtilProxy::Copy( |
204 operation_context_, proxy_, src_virtual_path_, | 208 operation_context_, proxy_, src_virtual_path_, |
205 dest_virtual_path_, | 209 dest_virtual_path_, |
206 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 210 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
207 weak_factory_.GetWeakPtr())); | 211 weak_factory_.GetWeakPtr())); |
208 } | 212 } |
209 | 213 |
210 void FileSystemOperation::Move(const GURL& src_path, | 214 void FileSystemOperation::Move(const GURL& src_path, |
211 const GURL& dest_path) { | 215 const GURL& dest_path) { |
212 #ifndef NDEBUG | 216 #ifndef NDEBUG |
217 DCHECK(dispatcher); | |
213 DCHECK(kOperationNone == pending_operation_); | 218 DCHECK(kOperationNone == pending_operation_); |
214 pending_operation_ = kOperationMove; | 219 pending_operation_ = kOperationMove; |
215 #endif | 220 #endif |
216 if (!SetupSrcContextForWrite(src_path, false) || | 221 if (!SetupSrcContextForWrite(src_path, false) || |
217 !SetupDestContextForWrite(dest_path, true)) { | 222 !SetupDestContextForWrite(dest_path, true)) { |
218 delete this; | 223 delete this; |
219 return; | 224 return; |
220 } | 225 } |
221 | 226 |
222 GetUsageAndQuotaThenCallback( | 227 GetUsageAndQuotaThenCallback( |
(...skipping 13 matching lines...) Expand all Loading... | |
236 | 241 |
237 FileSystemFileUtilProxy::Move( | 242 FileSystemFileUtilProxy::Move( |
238 operation_context_, proxy_, src_virtual_path_, | 243 operation_context_, proxy_, src_virtual_path_, |
239 dest_virtual_path_, | 244 dest_virtual_path_, |
240 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 245 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
241 weak_factory_.GetWeakPtr())); | 246 weak_factory_.GetWeakPtr())); |
242 } | 247 } |
243 | 248 |
244 void FileSystemOperation::DirectoryExists(const GURL& path) { | 249 void FileSystemOperation::DirectoryExists(const GURL& path) { |
245 #ifndef NDEBUG | 250 #ifndef NDEBUG |
251 DCHECK(dispatcher); | |
246 DCHECK(kOperationNone == pending_operation_); | 252 DCHECK(kOperationNone == pending_operation_); |
247 pending_operation_ = kOperationDirectoryExists; | 253 pending_operation_ = kOperationDirectoryExists; |
248 #endif | 254 #endif |
249 if (!SetupSrcContextForRead(path)) { | 255 if (!SetupSrcContextForRead(path)) { |
250 delete this; | 256 delete this; |
251 return; | 257 return; |
252 } | 258 } |
253 | 259 |
254 FileSystemFileUtilProxy::GetFileInfo( | 260 FileSystemFileUtilProxy::GetFileInfo( |
255 operation_context_, proxy_, src_virtual_path_, | 261 operation_context_, proxy_, src_virtual_path_, |
256 base::Bind(&FileSystemOperation::DidDirectoryExists, | 262 base::Bind(&FileSystemOperation::DidDirectoryExists, |
257 weak_factory_.GetWeakPtr())); | 263 weak_factory_.GetWeakPtr())); |
258 } | 264 } |
259 | 265 |
260 void FileSystemOperation::FileExists(const GURL& path) { | 266 void FileSystemOperation::FileExists(const GURL& path) { |
261 #ifndef NDEBUG | 267 #ifndef NDEBUG |
268 DCHECK(dispatcher); | |
262 DCHECK(kOperationNone == pending_operation_); | 269 DCHECK(kOperationNone == pending_operation_); |
263 pending_operation_ = kOperationFileExists; | 270 pending_operation_ = kOperationFileExists; |
264 #endif | 271 #endif |
265 if (!SetupSrcContextForRead(path)) { | 272 if (!SetupSrcContextForRead(path)) { |
266 delete this; | 273 delete this; |
267 return; | 274 return; |
268 } | 275 } |
269 | 276 |
270 FileSystemFileUtilProxy::GetFileInfo( | 277 FileSystemFileUtilProxy::GetFileInfo( |
271 operation_context_, proxy_, src_virtual_path_, | 278 operation_context_, proxy_, src_virtual_path_, |
272 base::Bind(&FileSystemOperation::DidFileExists, | 279 base::Bind(&FileSystemOperation::DidFileExists, |
273 weak_factory_.GetWeakPtr())); | 280 weak_factory_.GetWeakPtr())); |
274 } | 281 } |
275 | 282 |
276 void FileSystemOperation::GetMetadata(const GURL& path) { | 283 void FileSystemOperation::GetMetadata(const GURL& path) { |
277 #ifndef NDEBUG | 284 #ifndef NDEBUG |
285 DCHECK(dispatcher); | |
278 DCHECK(kOperationNone == pending_operation_); | 286 DCHECK(kOperationNone == pending_operation_); |
279 pending_operation_ = kOperationGetMetadata; | 287 pending_operation_ = kOperationGetMetadata; |
280 #endif | 288 #endif |
281 if (!SetupSrcContextForRead(path)) { | 289 if (!SetupSrcContextForRead(path)) { |
282 delete this; | 290 delete this; |
283 return; | 291 return; |
284 } | 292 } |
285 | 293 |
286 FileSystemFileUtilProxy::GetFileInfo( | 294 FileSystemFileUtilProxy::GetFileInfo( |
287 operation_context_, proxy_, src_virtual_path_, | 295 operation_context_, proxy_, src_virtual_path_, |
288 base::Bind(&FileSystemOperation::DidGetMetadata, | 296 base::Bind(&FileSystemOperation::DidGetMetadata, |
289 weak_factory_.GetWeakPtr())); | 297 weak_factory_.GetWeakPtr())); |
290 } | 298 } |
291 | 299 |
292 void FileSystemOperation::ReadDirectory(const GURL& path) { | 300 void FileSystemOperation::ReadDirectory(const GURL& path) { |
293 #ifndef NDEBUG | 301 #ifndef NDEBUG |
302 DCHECK(dispatcher); | |
294 DCHECK(kOperationNone == pending_operation_); | 303 DCHECK(kOperationNone == pending_operation_); |
295 pending_operation_ = kOperationReadDirectory; | 304 pending_operation_ = kOperationReadDirectory; |
296 #endif | 305 #endif |
297 if (!SetupSrcContextForRead(path)) { | 306 if (!SetupSrcContextForRead(path)) { |
298 delete this; | 307 delete this; |
299 return; | 308 return; |
300 } | 309 } |
301 | 310 |
302 FileSystemFileUtilProxy::ReadDirectory( | 311 FileSystemFileUtilProxy::ReadDirectory( |
303 operation_context_, proxy_, src_virtual_path_, | 312 operation_context_, proxy_, src_virtual_path_, |
304 base::Bind(&FileSystemOperation::DidReadDirectory, | 313 base::Bind(&FileSystemOperation::DidReadDirectory, |
305 weak_factory_.GetWeakPtr())); | 314 weak_factory_.GetWeakPtr())); |
306 } | 315 } |
307 | 316 |
308 void FileSystemOperation::Remove(const GURL& path, bool recursive) { | 317 void FileSystemOperation::Remove(const GURL& path, bool recursive) { |
309 #ifndef NDEBUG | 318 #ifndef NDEBUG |
319 DCHECK(dispatcher); | |
310 DCHECK(kOperationNone == pending_operation_); | 320 DCHECK(kOperationNone == pending_operation_); |
311 pending_operation_ = kOperationRemove; | 321 pending_operation_ = kOperationRemove; |
312 #endif | 322 #endif |
313 if (!SetupSrcContextForWrite(path, false)) { | 323 if (!SetupSrcContextForWrite(path, false)) { |
314 delete this; | 324 delete this; |
315 return; | 325 return; |
316 } | 326 } |
317 | 327 |
318 FileSystemFileUtilProxy::Delete( | 328 FileSystemFileUtilProxy::Delete( |
319 operation_context_, proxy_, src_virtual_path_, recursive, | 329 operation_context_, proxy_, src_virtual_path_, recursive, |
320 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 330 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
321 weak_factory_.GetWeakPtr())); | 331 weak_factory_.GetWeakPtr())); |
322 } | 332 } |
323 | 333 |
324 void FileSystemOperation::Write( | 334 void FileSystemOperation::Write( |
325 scoped_refptr<net::URLRequestContext> url_request_context, | 335 scoped_refptr<net::URLRequestContext> url_request_context, |
326 const GURL& path, | 336 const GURL& path, |
327 const GURL& blob_url, | 337 const GURL& blob_url, |
328 int64 offset) { | 338 int64 offset) { |
329 #ifndef NDEBUG | 339 #ifndef NDEBUG |
340 DCHECK(dispatcher); | |
330 DCHECK(kOperationNone == pending_operation_); | 341 DCHECK(kOperationNone == pending_operation_); |
331 pending_operation_ = kOperationWrite; | 342 pending_operation_ = kOperationWrite; |
332 #endif | 343 #endif |
333 if (!SetupSrcContextForWrite(path, true)) { | 344 if (!SetupSrcContextForWrite(path, true)) { |
334 delete this; | 345 delete this; |
335 return; | 346 return; |
336 } | 347 } |
337 DCHECK(blob_url.is_valid()); | 348 DCHECK(blob_url.is_valid()); |
338 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); | 349 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); |
339 blob_request_.reset( | 350 blob_request_.reset( |
(...skipping 20 matching lines...) Expand all Loading... | |
360 proxy_, | 371 proxy_, |
361 src_virtual_path_, | 372 src_virtual_path_, |
362 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | | 373 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | |
363 base::PLATFORM_FILE_ASYNC, | 374 base::PLATFORM_FILE_ASYNC, |
364 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, | 375 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, |
365 weak_factory_.GetWeakPtr())); | 376 weak_factory_.GetWeakPtr())); |
366 } | 377 } |
367 | 378 |
368 void FileSystemOperation::Truncate(const GURL& path, int64 length) { | 379 void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
369 #ifndef NDEBUG | 380 #ifndef NDEBUG |
381 DCHECK(dispatcher); | |
370 DCHECK(kOperationNone == pending_operation_); | 382 DCHECK(kOperationNone == pending_operation_); |
371 pending_operation_ = kOperationTruncate; | 383 pending_operation_ = kOperationTruncate; |
372 #endif | 384 #endif |
373 if (!SetupSrcContextForWrite(path, false)) { | 385 if (!SetupSrcContextForWrite(path, false)) { |
374 delete this; | 386 delete this; |
375 return; | 387 return; |
376 } | 388 } |
377 length_ = length; | 389 length_ = length; |
378 | 390 |
379 GetUsageAndQuotaThenCallback( | 391 GetUsageAndQuotaThenCallback( |
(...skipping 14 matching lines...) Expand all Loading... | |
394 FileSystemFileUtilProxy::Truncate( | 406 FileSystemFileUtilProxy::Truncate( |
395 operation_context_, proxy_, src_virtual_path_, length_, | 407 operation_context_, proxy_, src_virtual_path_, length_, |
396 base::Bind(&FileSystemOperation::DidFinishFileOperation, | 408 base::Bind(&FileSystemOperation::DidFinishFileOperation, |
397 weak_factory_.GetWeakPtr())); | 409 weak_factory_.GetWeakPtr())); |
398 } | 410 } |
399 | 411 |
400 void FileSystemOperation::TouchFile(const GURL& path, | 412 void FileSystemOperation::TouchFile(const GURL& path, |
401 const base::Time& last_access_time, | 413 const base::Time& last_access_time, |
402 const base::Time& last_modified_time) { | 414 const base::Time& last_modified_time) { |
403 #ifndef NDEBUG | 415 #ifndef NDEBUG |
416 DCHECK(dispatcher); | |
404 DCHECK(kOperationNone == pending_operation_); | 417 DCHECK(kOperationNone == pending_operation_); |
405 pending_operation_ = kOperationTouchFile; | 418 pending_operation_ = kOperationTouchFile; |
406 #endif | 419 #endif |
407 if (!SetupSrcContextForWrite(path, true)) { | 420 if (!SetupSrcContextForWrite(path, true)) { |
408 delete this; | 421 delete this; |
409 return; | 422 return; |
410 } | 423 } |
411 | 424 |
412 FileSystemFileUtilProxy::Touch( | 425 FileSystemFileUtilProxy::Touch( |
413 operation_context_, proxy_, src_virtual_path_, | 426 operation_context_, proxy_, src_virtual_path_, |
414 last_access_time, last_modified_time, | 427 last_access_time, last_modified_time, |
415 base::Bind(&FileSystemOperation::DidTouchFile, | 428 base::Bind(&FileSystemOperation::DidTouchFile, |
416 weak_factory_.GetWeakPtr())); | 429 weak_factory_.GetWeakPtr())); |
417 } | 430 } |
418 | 431 |
419 void FileSystemOperation::OpenFile(const GURL& path, | 432 void FileSystemOperation::OpenFile(const GURL& path, |
420 int file_flags, | 433 int file_flags, |
421 base::ProcessHandle peer_handle) { | 434 base::ProcessHandle peer_handle) { |
422 #ifndef NDEBUG | 435 #ifndef NDEBUG |
436 DCHECK(dispatcher); | |
423 DCHECK(kOperationNone == pending_operation_); | 437 DCHECK(kOperationNone == pending_operation_); |
424 pending_operation_ = kOperationOpenFile; | 438 pending_operation_ = kOperationOpenFile; |
425 #endif | 439 #endif |
426 peer_handle_ = peer_handle; | 440 peer_handle_ = peer_handle; |
427 | 441 |
428 if (file_flags & ( | 442 if (file_flags & ( |
429 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | | 443 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
430 base::PLATFORM_FILE_HIDDEN))) { | 444 base::PLATFORM_FILE_HIDDEN))) { |
431 delete this; | 445 delete this; |
432 return; | 446 return; |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 bool result = VerifyFileSystemPathForWrite( | 841 bool result = VerifyFileSystemPathForWrite( |
828 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); | 842 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); |
829 operation_context_.set_dest_origin_url(origin_url); | 843 operation_context_.set_dest_origin_url(origin_url); |
830 operation_context_.set_dest_type(type); | 844 operation_context_.set_dest_type(type); |
831 if (!operation_context_.dest_file_util()) | 845 if (!operation_context_.dest_file_util()) |
832 operation_context_.set_dest_file_util(file_util); | 846 operation_context_.set_dest_file_util(file_util); |
833 return result; | 847 return result; |
834 } | 848 } |
835 | 849 |
836 } // namespace fileapi | 850 } // namespace fileapi |
OLD | NEW |