Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: webkit/fileapi/file_system_operation.cc

Issue 8499005: Retry: Merge FileUtilProxy and FileSystemFileUtilProxy using PostTaskAndReply: CreateOrOpen/Close (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 : proxy_(proxy), 64 : proxy_(proxy),
65 dispatcher_(dispatcher), 65 dispatcher_(dispatcher),
66 operation_context_(file_system_context, NULL), 66 operation_context_(file_system_context, NULL),
67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 67 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
68 #ifndef NDEBUG 68 #ifndef NDEBUG
69 pending_operation_ = kOperationNone; 69 pending_operation_ = kOperationNone;
70 #endif 70 #endif
71 } 71 }
72 72
73 FileSystemOperation::~FileSystemOperation() { 73 FileSystemOperation::~FileSystemOperation() {
74 if (file_writer_delegate_.get()) 74 if (file_writer_delegate_.get()) {
75 FileSystemFileUtilProxy::Close( 75 FileSystemOperationContext* c =
76 operation_context_, proxy_, file_writer_delegate_->file(), 76 new FileSystemOperationContext(operation_context_);
77 base::FileUtilProxy::RelayClose(
78 proxy_,
79 base::Bind(&FileSystemFileUtil::Close,
80 base::Unretained(c->src_file_util()),
81 base::Owned(c)),
82 file_writer_delegate_->file(),
77 FileSystemFileUtilProxy::StatusCallback()); 83 FileSystemFileUtilProxy::StatusCallback());
84 }
78 } 85 }
79 86
80 void FileSystemOperation::OpenFileSystem( 87 void FileSystemOperation::OpenFileSystem(
81 const GURL& origin_url, fileapi::FileSystemType type, bool create) { 88 const GURL& origin_url, fileapi::FileSystemType type, bool create) {
82 #ifndef NDEBUG 89 #ifndef NDEBUG
83 DCHECK(dispatcher_.get());
84 DCHECK(kOperationNone == pending_operation_); 90 DCHECK(kOperationNone == pending_operation_);
85 pending_operation_ = static_cast<FileSystemOperation::OperationType>( 91 pending_operation_ = static_cast<FileSystemOperation::OperationType>(
86 kOperationOpenFileSystem); 92 kOperationOpenFileSystem);
87 #endif 93 #endif
88 94
89 DCHECK(file_system_context()); 95 DCHECK(file_system_context());
90 operation_context_.set_src_origin_url(origin_url); 96 operation_context_.set_src_origin_url(origin_url);
91 operation_context_.set_src_type(type); 97 operation_context_.set_src_type(type);
92 // TODO(ericu): We don't really need to make this call if !create. 98 // TODO(ericu): We don't really need to make this call if !create.
93 // Also, in the future we won't need it either way, as long as we do all 99 // Also, in the future we won't need it either way, as long as we do all
94 // permission+quota checks beforehand. We only need it now because we have to 100 // permission+quota checks beforehand. We only need it now because we have to
95 // create an unpredictable directory name. Without that, we could lazily 101 // create an unpredictable directory name. Without that, we could lazily
96 // create the root later on the first filesystem write operation, and just 102 // create the root later on the first filesystem write operation, and just
97 // return GetFileSystemRootURI() here. 103 // return GetFileSystemRootURI() here.
98 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL( 104 file_system_context()->path_manager()->ValidateFileSystemRootAndGetURL(
99 origin_url, type, create, 105 origin_url, type, create,
100 base::Bind(&FileSystemOperation::DidGetRootPath, 106 base::Bind(&FileSystemOperation::DidGetRootPath,
101 weak_factory_.GetWeakPtr())); 107 weak_factory_.GetWeakPtr()));
102 } 108 }
103 109
104 void FileSystemOperation::CreateFile(const GURL& path, 110 void FileSystemOperation::CreateFile(const GURL& path,
105 bool exclusive) { 111 bool exclusive) {
106 #ifndef NDEBUG 112 #ifndef NDEBUG
107 DCHECK(dispatcher_.get());
108 DCHECK(kOperationNone == pending_operation_); 113 DCHECK(kOperationNone == pending_operation_);
109 pending_operation_ = kOperationCreateFile; 114 pending_operation_ = kOperationCreateFile;
110 #endif 115 #endif
111 if (!SetupSrcContextForWrite(path, true)) { 116 if (!SetupSrcContextForWrite(path, true)) {
112 delete this; 117 delete this;
113 return; 118 return;
114 } 119 }
115 exclusive_ = exclusive; 120 exclusive_ = exclusive;
116 121
117 GetUsageAndQuotaThenCallback( 122 GetUsageAndQuotaThenCallback(
(...skipping 18 matching lines...) Expand all
136 base::Bind( 141 base::Bind(
137 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive 142 exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive
138 : &FileSystemOperation::DidEnsureFileExistsNonExclusive, 143 : &FileSystemOperation::DidEnsureFileExistsNonExclusive,
139 weak_factory_.GetWeakPtr())); 144 weak_factory_.GetWeakPtr()));
140 } 145 }
141 146
142 void FileSystemOperation::CreateDirectory(const GURL& path, 147 void FileSystemOperation::CreateDirectory(const GURL& path,
143 bool exclusive, 148 bool exclusive,
144 bool recursive) { 149 bool recursive) {
145 #ifndef NDEBUG 150 #ifndef NDEBUG
146 DCHECK(dispatcher_.get());
147 DCHECK(kOperationNone == pending_operation_); 151 DCHECK(kOperationNone == pending_operation_);
148 pending_operation_ = kOperationCreateDirectory; 152 pending_operation_ = kOperationCreateDirectory;
149 #endif 153 #endif
150 if (!SetupSrcContextForWrite(path, true)) { 154 if (!SetupSrcContextForWrite(path, true)) {
151 delete this; 155 delete this;
152 return; 156 return;
153 } 157 }
154 exclusive_ = exclusive; 158 exclusive_ = exclusive;
155 recursive_ = recursive; 159 recursive_ = recursive;
156 160
(...skipping 15 matching lines...) Expand all
172 FileSystemFileUtilProxy::CreateDirectory( 176 FileSystemFileUtilProxy::CreateDirectory(
173 operation_context_, proxy_, src_virtual_path_, exclusive_, 177 operation_context_, proxy_, src_virtual_path_, exclusive_,
174 recursive_, 178 recursive_,
175 base::Bind(&FileSystemOperation::DidFinishFileOperation, 179 base::Bind(&FileSystemOperation::DidFinishFileOperation,
176 weak_factory_.GetWeakPtr())); 180 weak_factory_.GetWeakPtr()));
177 } 181 }
178 182
179 void FileSystemOperation::Copy(const GURL& src_path, 183 void FileSystemOperation::Copy(const GURL& src_path,
180 const GURL& dest_path) { 184 const GURL& dest_path) {
181 #ifndef NDEBUG 185 #ifndef NDEBUG
182 DCHECK(dispatcher_.get());
183 DCHECK(kOperationNone == pending_operation_); 186 DCHECK(kOperationNone == pending_operation_);
184 pending_operation_ = kOperationCopy; 187 pending_operation_ = kOperationCopy;
185 #endif 188 #endif
186 if (!SetupSrcContextForRead(src_path) || 189 if (!SetupSrcContextForRead(src_path) ||
187 !SetupDestContextForWrite(dest_path, true)) { 190 !SetupDestContextForWrite(dest_path, true)) {
188 delete this; 191 delete this;
189 return; 192 return;
190 } 193 }
191 194
192 GetUsageAndQuotaThenCallback( 195 GetUsageAndQuotaThenCallback(
(...skipping 14 matching lines...) Expand all
207 FileSystemFileUtilProxy::Copy( 210 FileSystemFileUtilProxy::Copy(
208 operation_context_, proxy_, src_virtual_path_, 211 operation_context_, proxy_, src_virtual_path_,
209 dest_virtual_path_, 212 dest_virtual_path_,
210 base::Bind(&FileSystemOperation::DidFinishFileOperation, 213 base::Bind(&FileSystemOperation::DidFinishFileOperation,
211 weak_factory_.GetWeakPtr())); 214 weak_factory_.GetWeakPtr()));
212 } 215 }
213 216
214 void FileSystemOperation::Move(const GURL& src_path, 217 void FileSystemOperation::Move(const GURL& src_path,
215 const GURL& dest_path) { 218 const GURL& dest_path) {
216 #ifndef NDEBUG 219 #ifndef NDEBUG
217 DCHECK(dispatcher_.get());
218 DCHECK(kOperationNone == pending_operation_); 220 DCHECK(kOperationNone == pending_operation_);
219 pending_operation_ = kOperationMove; 221 pending_operation_ = kOperationMove;
220 #endif 222 #endif
221 if (!SetupSrcContextForWrite(src_path, false) || 223 if (!SetupSrcContextForWrite(src_path, false) ||
222 !SetupDestContextForWrite(dest_path, true)) { 224 !SetupDestContextForWrite(dest_path, true)) {
223 delete this; 225 delete this;
224 return; 226 return;
225 } 227 }
226 228
227 GetUsageAndQuotaThenCallback( 229 GetUsageAndQuotaThenCallback(
(...skipping 13 matching lines...) Expand all
241 243
242 FileSystemFileUtilProxy::Move( 244 FileSystemFileUtilProxy::Move(
243 operation_context_, proxy_, src_virtual_path_, 245 operation_context_, proxy_, src_virtual_path_,
244 dest_virtual_path_, 246 dest_virtual_path_,
245 base::Bind(&FileSystemOperation::DidFinishFileOperation, 247 base::Bind(&FileSystemOperation::DidFinishFileOperation,
246 weak_factory_.GetWeakPtr())); 248 weak_factory_.GetWeakPtr()));
247 } 249 }
248 250
249 void FileSystemOperation::DirectoryExists(const GURL& path) { 251 void FileSystemOperation::DirectoryExists(const GURL& path) {
250 #ifndef NDEBUG 252 #ifndef NDEBUG
251 DCHECK(dispatcher_.get());
252 DCHECK(kOperationNone == pending_operation_); 253 DCHECK(kOperationNone == pending_operation_);
253 pending_operation_ = kOperationDirectoryExists; 254 pending_operation_ = kOperationDirectoryExists;
254 #endif 255 #endif
255 if (!SetupSrcContextForRead(path)) { 256 if (!SetupSrcContextForRead(path)) {
256 delete this; 257 delete this;
257 return; 258 return;
258 } 259 }
259 260
260 FileSystemFileUtilProxy::GetFileInfo( 261 FileSystemFileUtilProxy::GetFileInfo(
261 operation_context_, proxy_, src_virtual_path_, 262 operation_context_, proxy_, src_virtual_path_,
262 base::Bind(&FileSystemOperation::DidDirectoryExists, 263 base::Bind(&FileSystemOperation::DidDirectoryExists,
263 weak_factory_.GetWeakPtr())); 264 weak_factory_.GetWeakPtr()));
264 } 265 }
265 266
266 void FileSystemOperation::FileExists(const GURL& path) { 267 void FileSystemOperation::FileExists(const GURL& path) {
267 #ifndef NDEBUG 268 #ifndef NDEBUG
268 DCHECK(dispatcher_.get());
269 DCHECK(kOperationNone == pending_operation_); 269 DCHECK(kOperationNone == pending_operation_);
270 pending_operation_ = kOperationFileExists; 270 pending_operation_ = kOperationFileExists;
271 #endif 271 #endif
272 if (!SetupSrcContextForRead(path)) { 272 if (!SetupSrcContextForRead(path)) {
273 delete this; 273 delete this;
274 return; 274 return;
275 } 275 }
276 276
277 FileSystemFileUtilProxy::GetFileInfo( 277 FileSystemFileUtilProxy::GetFileInfo(
278 operation_context_, proxy_, src_virtual_path_, 278 operation_context_, proxy_, src_virtual_path_,
279 base::Bind(&FileSystemOperation::DidFileExists, 279 base::Bind(&FileSystemOperation::DidFileExists,
280 weak_factory_.GetWeakPtr())); 280 weak_factory_.GetWeakPtr()));
281 } 281 }
282 282
283 void FileSystemOperation::GetMetadata(const GURL& path) { 283 void FileSystemOperation::GetMetadata(const GURL& path) {
284 #ifndef NDEBUG 284 #ifndef NDEBUG
285 DCHECK(dispatcher_.get());
286 DCHECK(kOperationNone == pending_operation_); 285 DCHECK(kOperationNone == pending_operation_);
287 pending_operation_ = kOperationGetMetadata; 286 pending_operation_ = kOperationGetMetadata;
288 #endif 287 #endif
289 if (!SetupSrcContextForRead(path)) { 288 if (!SetupSrcContextForRead(path)) {
290 delete this; 289 delete this;
291 return; 290 return;
292 } 291 }
293 292
294 FileSystemFileUtilProxy::GetFileInfo( 293 FileSystemFileUtilProxy::GetFileInfo(
295 operation_context_, proxy_, src_virtual_path_, 294 operation_context_, proxy_, src_virtual_path_,
296 base::Bind(&FileSystemOperation::DidGetMetadata, 295 base::Bind(&FileSystemOperation::DidGetMetadata,
297 weak_factory_.GetWeakPtr())); 296 weak_factory_.GetWeakPtr()));
298 } 297 }
299 298
300 void FileSystemOperation::ReadDirectory(const GURL& path) { 299 void FileSystemOperation::ReadDirectory(const GURL& path) {
301 #ifndef NDEBUG 300 #ifndef NDEBUG
302 DCHECK(dispatcher_.get());
303 DCHECK(kOperationNone == pending_operation_); 301 DCHECK(kOperationNone == pending_operation_);
304 pending_operation_ = kOperationReadDirectory; 302 pending_operation_ = kOperationReadDirectory;
305 #endif 303 #endif
306 if (!SetupSrcContextForRead(path)) { 304 if (!SetupSrcContextForRead(path)) {
307 delete this; 305 delete this;
308 return; 306 return;
309 } 307 }
310 308
311 FileSystemFileUtilProxy::ReadDirectory( 309 FileSystemFileUtilProxy::ReadDirectory(
312 operation_context_, proxy_, src_virtual_path_, 310 operation_context_, proxy_, src_virtual_path_,
313 base::Bind(&FileSystemOperation::DidReadDirectory, 311 base::Bind(&FileSystemOperation::DidReadDirectory,
314 weak_factory_.GetWeakPtr())); 312 weak_factory_.GetWeakPtr()));
315 } 313 }
316 314
317 void FileSystemOperation::Remove(const GURL& path, bool recursive) { 315 void FileSystemOperation::Remove(const GURL& path, bool recursive) {
318 #ifndef NDEBUG 316 #ifndef NDEBUG
319 DCHECK(dispatcher_.get());
320 DCHECK(kOperationNone == pending_operation_); 317 DCHECK(kOperationNone == pending_operation_);
321 pending_operation_ = kOperationRemove; 318 pending_operation_ = kOperationRemove;
322 #endif 319 #endif
323 if (!SetupSrcContextForWrite(path, false)) { 320 if (!SetupSrcContextForWrite(path, false)) {
324 delete this; 321 delete this;
325 return; 322 return;
326 } 323 }
327 324
328 FileSystemFileUtilProxy::Delete( 325 FileSystemFileUtilProxy::Delete(
329 operation_context_, proxy_, src_virtual_path_, recursive, 326 operation_context_, proxy_, src_virtual_path_, recursive,
330 base::Bind(&FileSystemOperation::DidFinishFileOperation, 327 base::Bind(&FileSystemOperation::DidFinishFileOperation,
331 weak_factory_.GetWeakPtr())); 328 weak_factory_.GetWeakPtr()));
332 } 329 }
333 330
334 void FileSystemOperation::Write( 331 void FileSystemOperation::Write(
335 scoped_refptr<net::URLRequestContext> url_request_context, 332 scoped_refptr<net::URLRequestContext> url_request_context,
336 const GURL& path, 333 const GURL& path,
337 const GURL& blob_url, 334 const GURL& blob_url,
338 int64 offset) { 335 int64 offset) {
339 #ifndef NDEBUG 336 #ifndef NDEBUG
340 DCHECK(dispatcher_.get());
341 DCHECK(kOperationNone == pending_operation_); 337 DCHECK(kOperationNone == pending_operation_);
342 pending_operation_ = kOperationWrite; 338 pending_operation_ = kOperationWrite;
343 #endif 339 #endif
344 if (!SetupSrcContextForWrite(path, true)) { 340 if (!SetupSrcContextForWrite(path, true)) {
345 delete this; 341 delete this;
346 return; 342 return;
347 } 343 }
348 DCHECK(blob_url.is_valid()); 344 DCHECK(blob_url.is_valid());
349 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_)); 345 file_writer_delegate_.reset(new FileWriterDelegate(this, offset, proxy_));
350 blob_request_.reset( 346 blob_request_.reset(
351 new net::URLRequest(blob_url, file_writer_delegate_.get())); 347 new net::URLRequest(blob_url, file_writer_delegate_.get()));
352 blob_request_->set_context(url_request_context); 348 blob_request_->set_context(url_request_context);
353 349
354 GetUsageAndQuotaThenCallback( 350 GetUsageAndQuotaThenCallback(
355 operation_context_.src_origin_url(), 351 operation_context_.src_origin_url(),
356 base::Bind(&FileSystemOperation::DelayedWriteForQuota, 352 base::Bind(&FileSystemOperation::DelayedWriteForQuota,
357 weak_factory_.GetWeakPtr())); 353 weak_factory_.GetWeakPtr()));
358 } 354 }
359 355
360 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status, 356 void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
361 int64 usage, int64 quota) { 357 int64 usage, int64 quota) {
362 operation_context_.set_allowed_bytes_growth(quota - usage); 358 operation_context_.set_allowed_bytes_growth(quota - usage);
363 359
364 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 360 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
365 file_system_context(), 361 file_system_context(),
366 operation_context_.src_origin_url(), 362 operation_context_.src_origin_url(),
367 operation_context_.src_type())); 363 operation_context_.src_type()));
368 364
369 FileSystemFileUtilProxy::CreateOrOpen( 365 int file_flags = base::PLATFORM_FILE_OPEN |
370 operation_context_, 366 base::PLATFORM_FILE_WRITE |
367 base::PLATFORM_FILE_ASYNC;
368
369 base::FileUtilProxy::RelayCreateOrOpen(
371 proxy_, 370 proxy_,
372 src_virtual_path_, 371 base::Bind(&FileSystemFileUtil::CreateOrOpen,
373 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_WRITE | 372 base::Unretained(operation_context_.src_file_util()),
374 base::PLATFORM_FILE_ASYNC, 373 base::Unretained(&operation_context_),
374 src_virtual_path_, file_flags),
375 base::Bind(&FileSystemFileUtil::Close,
376 base::Unretained(operation_context_.src_file_util()),
377 base::Unretained(&operation_context_)),
375 base::Bind(&FileSystemOperation::OnFileOpenedForWrite, 378 base::Bind(&FileSystemOperation::OnFileOpenedForWrite,
376 weak_factory_.GetWeakPtr())); 379 weak_factory_.GetWeakPtr()));
377 } 380 }
378 381
379 void FileSystemOperation::Truncate(const GURL& path, int64 length) { 382 void FileSystemOperation::Truncate(const GURL& path, int64 length) {
380 #ifndef NDEBUG 383 #ifndef NDEBUG
381 DCHECK(dispatcher_.get());
382 DCHECK(kOperationNone == pending_operation_); 384 DCHECK(kOperationNone == pending_operation_);
383 pending_operation_ = kOperationTruncate; 385 pending_operation_ = kOperationTruncate;
384 #endif 386 #endif
385 if (!SetupSrcContextForWrite(path, false)) { 387 if (!SetupSrcContextForWrite(path, false)) {
386 delete this; 388 delete this;
387 return; 389 return;
388 } 390 }
389 length_ = length; 391 length_ = length;
390 392
391 GetUsageAndQuotaThenCallback( 393 GetUsageAndQuotaThenCallback(
(...skipping 14 matching lines...) Expand all
406 FileSystemFileUtilProxy::Truncate( 408 FileSystemFileUtilProxy::Truncate(
407 operation_context_, proxy_, src_virtual_path_, length_, 409 operation_context_, proxy_, src_virtual_path_, length_,
408 base::Bind(&FileSystemOperation::DidFinishFileOperation, 410 base::Bind(&FileSystemOperation::DidFinishFileOperation,
409 weak_factory_.GetWeakPtr())); 411 weak_factory_.GetWeakPtr()));
410 } 412 }
411 413
412 void FileSystemOperation::TouchFile(const GURL& path, 414 void FileSystemOperation::TouchFile(const GURL& path,
413 const base::Time& last_access_time, 415 const base::Time& last_access_time,
414 const base::Time& last_modified_time) { 416 const base::Time& last_modified_time) {
415 #ifndef NDEBUG 417 #ifndef NDEBUG
416 DCHECK(dispatcher_.get());
417 DCHECK(kOperationNone == pending_operation_); 418 DCHECK(kOperationNone == pending_operation_);
418 pending_operation_ = kOperationTouchFile; 419 pending_operation_ = kOperationTouchFile;
419 #endif 420 #endif
420 if (!SetupSrcContextForWrite(path, true)) { 421 if (!SetupSrcContextForWrite(path, true)) {
421 delete this; 422 delete this;
422 return; 423 return;
423 } 424 }
424 425
425 FileSystemFileUtilProxy::Touch( 426 FileSystemFileUtilProxy::Touch(
426 operation_context_, proxy_, src_virtual_path_, 427 operation_context_, proxy_, src_virtual_path_,
427 last_access_time, last_modified_time, 428 last_access_time, last_modified_time,
428 base::Bind(&FileSystemOperation::DidTouchFile, 429 base::Bind(&FileSystemOperation::DidTouchFile,
429 weak_factory_.GetWeakPtr())); 430 weak_factory_.GetWeakPtr()));
430 } 431 }
431 432
432 void FileSystemOperation::OpenFile(const GURL& path, 433 void FileSystemOperation::OpenFile(const GURL& path,
433 int file_flags, 434 int file_flags,
434 base::ProcessHandle peer_handle) { 435 base::ProcessHandle peer_handle) {
435 #ifndef NDEBUG 436 #ifndef NDEBUG
436 DCHECK(dispatcher_.get());
437 DCHECK(kOperationNone == pending_operation_); 437 DCHECK(kOperationNone == pending_operation_);
438 pending_operation_ = kOperationOpenFile; 438 pending_operation_ = kOperationOpenFile;
439 #endif 439 #endif
440 peer_handle_ = peer_handle; 440 peer_handle_ = peer_handle;
441 441
442 if (file_flags & ( 442 if (file_flags & (
443 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | 443 (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY |
444 base::PLATFORM_FILE_HIDDEN))) { 444 base::PLATFORM_FILE_HIDDEN))) {
445 delete this; 445 delete this;
446 return; 446 return;
(...skipping 24 matching lines...) Expand all
471 471
472 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status, 472 void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
473 int64 usage, int64 quota) { 473 int64 usage, int64 quota) {
474 operation_context_.set_allowed_bytes_growth(quota - usage); 474 operation_context_.set_allowed_bytes_growth(quota - usage);
475 475
476 quota_util_helper_.reset(new ScopedQuotaUtilHelper( 476 quota_util_helper_.reset(new ScopedQuotaUtilHelper(
477 file_system_context(), 477 file_system_context(),
478 operation_context_.src_origin_url(), 478 operation_context_.src_origin_url(),
479 operation_context_.src_type())); 479 operation_context_.src_type()));
480 480
481 FileSystemFileUtilProxy::CreateOrOpen( 481 base::FileUtilProxy::RelayCreateOrOpen(
482 operation_context_, proxy_, src_virtual_path_, file_flags_, 482 proxy_,
483 base::Bind(&FileSystemFileUtil::CreateOrOpen,
484 base::Unretained(operation_context_.src_file_util()),
485 base::Unretained(&operation_context_),
486 src_virtual_path_, file_flags_),
487 base::Bind(&FileSystemFileUtil::Close,
488 base::Unretained(operation_context_.src_file_util()),
489 base::Unretained(&operation_context_)),
483 base::Bind(&FileSystemOperation::DidOpenFile, 490 base::Bind(&FileSystemOperation::DidOpenFile,
484 weak_factory_.GetWeakPtr())); 491 weak_factory_.GetWeakPtr()));
485 } 492 }
486 493
487 void FileSystemOperation::SyncGetPlatformPath(const GURL& path, 494 void FileSystemOperation::SyncGetPlatformPath(const GURL& path,
488 FilePath* platform_path) { 495 FilePath* platform_path) {
489 #ifndef NDEBUG 496 #ifndef NDEBUG
490 DCHECK(kOperationNone == pending_operation_); 497 DCHECK(kOperationNone == pending_operation_);
491 pending_operation_ = kOperationGetLocalPath; 498 pending_operation_ = kOperationGetLocalPath;
492 #endif 499 #endif
(...skipping 18 matching lines...) Expand all
511 #endif 518 #endif
512 // Writes are done without proxying through FileUtilProxy after the initial 519 // Writes are done without proxying through FileUtilProxy after the initial
513 // opening of the PlatformFile. All state changes are done on this thread, 520 // opening of the PlatformFile. All state changes are done on this thread,
514 // so we're guaranteed to be able to shut down atomically. We do need to 521 // so we're guaranteed to be able to shut down atomically. We do need to
515 // check that the file has been opened [which means the blob_request_ has 522 // check that the file has been opened [which means the blob_request_ has
516 // been created], so we know how much we need to do. 523 // been created], so we know how much we need to do.
517 if (blob_request_.get()) 524 if (blob_request_.get())
518 // This halts any calls to file_writer_delegate_ from blob_request_. 525 // This halts any calls to file_writer_delegate_ from blob_request_.
519 blob_request_->Cancel(); 526 blob_request_->Cancel();
520 527
521 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 528 if (dispatcher_.get())
529 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
522 cancel_operation->dispatcher_->DidSucceed(); 530 cancel_operation->dispatcher_->DidSucceed();
523 delete this; 531 dispatcher_.reset();
524 } else { 532 } else {
525 #ifndef NDEBUG 533 #ifndef NDEBUG
526 DCHECK(kOperationTruncate == pending_operation_); 534 DCHECK(kOperationTruncate == pending_operation_);
527 #endif 535 #endif
528 // We're cancelling a truncate operation, but we can't actually stop it 536 // We're cancelling a truncate operation, but we can't actually stop it
529 // since it's been proxied to another thread. We need to save the 537 // since it's been proxied to another thread. We need to save the
530 // cancel_operation so that when the truncate returns, it can see that it's 538 // cancel_operation so that when the truncate returns, it can see that it's
531 // been cancelled, report it, and report that the cancel has succeeded. 539 // been cancelled, report it, and report that the cancel has succeeded.
532 DCHECK(!cancel_operation_.get()); 540 DCHECK(!cancel_operation_.get());
533 cancel_operation_.swap(cancel_operation); 541 cancel_operation_.swap(cancel_operation);
(...skipping 27 matching lines...) Expand all
561 const FilePath& path, const std::string& name) { 569 const FilePath& path, const std::string& name) {
562 DCHECK(success || path.empty()); 570 DCHECK(success || path.empty());
563 GURL result; 571 GURL result;
564 // We ignore the path, and return a URL instead. The point was just to verify 572 // We ignore the path, and return a URL instead. The point was just to verify
565 // that we could create/find the path. 573 // that we could create/find the path.
566 if (success) { 574 if (success) {
567 result = GetFileSystemRootURI( 575 result = GetFileSystemRootURI(
568 operation_context_.src_origin_url(), 576 operation_context_.src_origin_url(),
569 operation_context_.src_type()); 577 operation_context_.src_type());
570 } 578 }
571 dispatcher_->DidOpenFileSystem(name, result); 579 if (dispatcher_.get())
580 dispatcher_->DidOpenFileSystem(name, result);
572 delete this; 581 delete this;
573 } 582 }
574 583
575 void FileSystemOperation::DidEnsureFileExistsExclusive( 584 void FileSystemOperation::DidEnsureFileExistsExclusive(
576 base::PlatformFileError rv, bool created) { 585 base::PlatformFileError rv, bool created) {
577 if (rv == base::PLATFORM_FILE_OK && !created) { 586 if (rv == base::PLATFORM_FILE_OK && !created) {
578 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS); 587 if (dispatcher_.get())
588 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_EXISTS);
579 delete this; 589 delete this;
580 } else { 590 } else {
581 DidFinishFileOperation(rv); 591 DidFinishFileOperation(rv);
582 } 592 }
583 } 593 }
584 594
585 void FileSystemOperation::DidEnsureFileExistsNonExclusive( 595 void FileSystemOperation::DidEnsureFileExistsNonExclusive(
586 base::PlatformFileError rv, bool /* created */) { 596 base::PlatformFileError rv, bool /* created */) {
587 DidFinishFileOperation(rv); 597 DidFinishFileOperation(rv);
588 } 598 }
589 599
590 void FileSystemOperation::DidFinishFileOperation( 600 void FileSystemOperation::DidFinishFileOperation(
591 base::PlatformFileError rv) { 601 base::PlatformFileError rv) {
592 if (cancel_operation_.get()) { 602 if (cancel_operation_.get()) {
593 #ifndef NDEBUG 603 #ifndef NDEBUG
594 DCHECK(kOperationTruncate == pending_operation_); 604 DCHECK(kOperationTruncate == pending_operation_);
595 #endif 605 #endif
596 606
597 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT); 607 if (dispatcher_.get())
608 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_ABORT);
598 cancel_operation_->dispatcher_->DidSucceed(); 609 cancel_operation_->dispatcher_->DidSucceed();
599 } else if (rv == base::PLATFORM_FILE_OK) { 610 } else if (dispatcher_.get()) {
600 dispatcher_->DidSucceed(); 611 if (rv == base::PLATFORM_FILE_OK)
601 } else { 612 dispatcher_->DidSucceed();
602 dispatcher_->DidFail(rv); 613 else
614 dispatcher_->DidFail(rv);
603 } 615 }
604 delete this; 616 delete this;
605 } 617 }
606 618
607 void FileSystemOperation::DidDirectoryExists( 619 void FileSystemOperation::DidDirectoryExists(
608 base::PlatformFileError rv, 620 base::PlatformFileError rv,
609 const base::PlatformFileInfo& file_info, 621 const base::PlatformFileInfo& file_info,
610 const FilePath& unused) { 622 const FilePath& unused) {
623 if (!dispatcher_.get()) {
624 delete this;
625 return;
626 }
611 if (rv == base::PLATFORM_FILE_OK) { 627 if (rv == base::PLATFORM_FILE_OK) {
612 if (file_info.is_directory) 628 if (file_info.is_directory)
613 dispatcher_->DidSucceed(); 629 dispatcher_->DidSucceed();
614 else 630 else
615 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY); 631 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY);
616 } else { 632 } else {
617 dispatcher_->DidFail(rv); 633 dispatcher_->DidFail(rv);
618 } 634 }
619 delete this; 635 delete this;
620 } 636 }
621 637
622 void FileSystemOperation::DidFileExists( 638 void FileSystemOperation::DidFileExists(
623 base::PlatformFileError rv, 639 base::PlatformFileError rv,
624 const base::PlatformFileInfo& file_info, 640 const base::PlatformFileInfo& file_info,
625 const FilePath& unused) { 641 const FilePath& unused) {
642 if (!dispatcher_.get()) {
643 delete this;
644 return;
645 }
626 if (rv == base::PLATFORM_FILE_OK) { 646 if (rv == base::PLATFORM_FILE_OK) {
627 if (file_info.is_directory) 647 if (file_info.is_directory)
628 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE); 648 dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_NOT_A_FILE);
629 else 649 else
630 dispatcher_->DidSucceed(); 650 dispatcher_->DidSucceed();
631 } else { 651 } else {
632 dispatcher_->DidFail(rv); 652 dispatcher_->DidFail(rv);
633 } 653 }
634 delete this; 654 delete this;
635 } 655 }
636 656
637 void FileSystemOperation::DidGetMetadata( 657 void FileSystemOperation::DidGetMetadata(
638 base::PlatformFileError rv, 658 base::PlatformFileError rv,
639 const base::PlatformFileInfo& file_info, 659 const base::PlatformFileInfo& file_info,
640 const FilePath& platform_path) { 660 const FilePath& platform_path) {
661 if (!dispatcher_.get()) {
662 delete this;
663 return;
664 }
641 if (rv == base::PLATFORM_FILE_OK) 665 if (rv == base::PLATFORM_FILE_OK)
642 dispatcher_->DidReadMetadata(file_info, platform_path); 666 dispatcher_->DidReadMetadata(file_info, platform_path);
643 else 667 else
644 dispatcher_->DidFail(rv); 668 dispatcher_->DidFail(rv);
645 delete this; 669 delete this;
646 } 670 }
647 671
648 void FileSystemOperation::DidReadDirectory( 672 void FileSystemOperation::DidReadDirectory(
649 base::PlatformFileError rv, 673 base::PlatformFileError rv,
650 const std::vector<base::FileUtilProxy::Entry>& entries) { 674 const std::vector<base::FileUtilProxy::Entry>& entries) {
675 if (!dispatcher_.get()) {
676 delete this;
677 return;
678 }
651 679
652 if (rv == base::PLATFORM_FILE_OK) 680 if (rv == base::PLATFORM_FILE_OK)
653 dispatcher_->DidReadDirectory(entries, false /* has_more */); 681 dispatcher_->DidReadDirectory(entries, false /* has_more */);
654 else 682 else
655 dispatcher_->DidFail(rv); 683 dispatcher_->DidFail(rv);
656 delete this; 684 delete this;
657 } 685 }
658 686
659 void FileSystemOperation::DidWrite( 687 void FileSystemOperation::DidWrite(
660 base::PlatformFileError rv, 688 base::PlatformFileError rv,
661 int64 bytes, 689 int64 bytes,
662 bool complete) { 690 bool complete) {
691 if (!dispatcher_.get()) {
692 delete this;
693 return;
694 }
663 if (rv == base::PLATFORM_FILE_OK) 695 if (rv == base::PLATFORM_FILE_OK)
664 dispatcher_->DidWrite(bytes, complete); 696 dispatcher_->DidWrite(bytes, complete);
665 else 697 else
666 dispatcher_->DidFail(rv); 698 dispatcher_->DidFail(rv);
667 if (complete || rv != base::PLATFORM_FILE_OK) 699 if (complete || rv != base::PLATFORM_FILE_OK)
668 delete this; 700 delete this;
669 } 701 }
670 702
671 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { 703 void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) {
704 if (!dispatcher_.get()) {
705 delete this;
706 return;
707 }
672 if (rv == base::PLATFORM_FILE_OK) 708 if (rv == base::PLATFORM_FILE_OK)
673 dispatcher_->DidSucceed(); 709 dispatcher_->DidSucceed();
674 else 710 else
675 dispatcher_->DidFail(rv); 711 dispatcher_->DidFail(rv);
676 delete this; 712 delete this;
677 } 713 }
678 714
679 void FileSystemOperation::DidOpenFile( 715 void FileSystemOperation::DidOpenFile(
680 base::PlatformFileError rv, 716 base::PlatformFileError rv,
681 base::PassPlatformFile file, 717 base::PassPlatformFile file,
682 bool unused) { 718 bool unused) {
719 if (!dispatcher_.get()) {
720 delete this;
721 return;
722 }
683 if (rv == base::PLATFORM_FILE_OK) 723 if (rv == base::PLATFORM_FILE_OK)
684 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); 724 dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_);
685 else 725 else
686 dispatcher_->DidFail(rv); 726 dispatcher_->DidFail(rv);
687 delete this; 727 delete this;
688 } 728 }
689 729
690 void FileSystemOperation::OnFileOpenedForWrite( 730 void FileSystemOperation::OnFileOpenedForWrite(
691 base::PlatformFileError rv, 731 base::PlatformFileError rv,
692 base::PassPlatformFile file, 732 base::PassPlatformFile file,
693 bool created) { 733 bool created) {
734 if (!dispatcher_.get()) {
735 delete this;
736 return;
737 }
694 if (base::PLATFORM_FILE_OK != rv) { 738 if (base::PLATFORM_FILE_OK != rv) {
695 dispatcher_->DidFail(rv); 739 dispatcher_->DidFail(rv);
696 delete this; 740 delete this;
697 return; 741 return;
698 } 742 }
699 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); 743 file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get());
700 } 744 }
701 745
702 bool FileSystemOperation::VerifyFileSystemPathForRead( 746 bool FileSystemOperation::VerifyFileSystemPathForRead(
703 const GURL& path, GURL* origin_url, FileSystemType* type, 747 const GURL& path, GURL* origin_url, FileSystemType* type,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 bool result = VerifyFileSystemPathForWrite( 885 bool result = VerifyFileSystemPathForWrite(
842 path, create, &origin_url, &type, &dest_virtual_path_, &file_util); 886 path, create, &origin_url, &type, &dest_virtual_path_, &file_util);
843 operation_context_.set_dest_origin_url(origin_url); 887 operation_context_.set_dest_origin_url(origin_url);
844 operation_context_.set_dest_type(type); 888 operation_context_.set_dest_type(type);
845 if (!operation_context_.dest_file_util()) 889 if (!operation_context_.dest_file_util())
846 operation_context_.set_dest_file_util(file_util); 890 operation_context_.set_dest_file_util(file_util);
847 return result; 891 return result;
848 } 892 }
849 893
850 } // namespace fileapi 894 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698