Chromium Code Reviews| 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 "content/child/fileapi/webfilesystem_impl.h" | 5 #include "content/child/fileapi/webfilesystem_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 35 | 35 |
| 36 namespace content { | 36 namespace content { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky | 40 base::LazyInstance<base::ThreadLocalPointer<WebFileSystemImpl> >::Leaky |
| 41 g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; | 41 g_webfilesystem_tls = LAZY_INSTANCE_INITIALIZER; |
| 42 | 42 |
| 43 class WaitableCallbackResults { | 43 class WaitableCallbackResults { |
| 44 public: | 44 public: |
| 45 static WaitableCallbackResults* MaybeCreate( | 45 static scoped_ptr<WaitableCallbackResults> MaybeCreate( |
| 46 const WebFileSystemCallbacks& callbacks) { | 46 const WebFileSystemCallbacks& callbacks) { |
| 47 if (callbacks.shouldBlockUntilCompletion()) | 47 if (callbacks.shouldBlockUntilCompletion()) |
| 48 return new WaitableCallbackResults; | 48 return make_scoped_ptr(new WaitableCallbackResults); |
| 49 return NULL; | 49 return scoped_ptr<WaitableCallbackResults>(); |
| 50 } | 50 } |
| 51 ~WaitableCallbackResults() {} | 51 ~WaitableCallbackResults() {} |
| 52 | 52 |
| 53 void SetResultsAndSignal(const base::Closure& results_closure) { | 53 void SetResultsAndSignal(const base::Closure& results_closure) { |
| 54 results_closure_ = results_closure; | 54 results_closure_ = results_closure; |
| 55 event_->Signal(); | 55 event_.Signal(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void WaitAndRun() { | 58 void WaitAndRun() { |
| 59 { | 59 { |
| 60 blink::WebHeap::SafePointScope safe_point; | 60 blink::WebHeap::SafePointScope safe_point; |
| 61 event_->Wait(); | 61 event_.Wait(); |
| 62 } | 62 } |
| 63 DCHECK(!results_closure_.is_null()); | 63 DCHECK(!results_closure_.is_null()); |
| 64 results_closure_.Run(); | 64 results_closure_.Run(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 WaitableCallbackResults() : event_(new base::WaitableEvent(true, false)) {} | 68 WaitableCallbackResults() : event_(true, false) {} |
|
kinuko
2014/03/05 15:23:32
oops.
| |
| 69 | 69 |
| 70 base::WaitableEvent* event_; | 70 base::WaitableEvent event_; |
| 71 base::Closure results_closure_; | 71 base::Closure results_closure_; |
| 72 DISALLOW_COPY_AND_ASSIGN(WaitableCallbackResults); | 72 DISALLOW_COPY_AND_ASSIGN(WaitableCallbackResults); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 void DidReceiveSnapshotFile(int request_id) { | 75 void DidReceiveSnapshotFile(int request_id) { |
| 76 if (ChildThread::current()) | 76 if (ChildThread::current()) |
| 77 ChildThread::current()->Send( | 77 ChildThread::current()->Send( |
| 78 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); | 78 new FileSystemHostMsg_DidReceiveSnapshotFile(request_id)); |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 | 325 |
| 326 void WebFileSystemImpl::OnWorkerRunLoopStopped() { | 326 void WebFileSystemImpl::OnWorkerRunLoopStopped() { |
| 327 delete this; | 327 delete this; |
| 328 } | 328 } |
| 329 | 329 |
| 330 void WebFileSystemImpl::openFileSystem( | 330 void WebFileSystemImpl::openFileSystem( |
| 331 const blink::WebURL& storage_partition, | 331 const blink::WebURL& storage_partition, |
| 332 blink::WebFileSystemType type, | 332 blink::WebFileSystemType type, |
| 333 WebFileSystemCallbacks callbacks) { | 333 WebFileSystemCallbacks callbacks) { |
| 334 int callbacks_id = RegisterCallbacks(callbacks); | 334 int callbacks_id = RegisterCallbacks(callbacks); |
| 335 WaitableCallbackResults* waitable_results = | 335 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 336 WaitableCallbackResults::MaybeCreate(callbacks); | 336 WaitableCallbackResults::MaybeCreate(callbacks); |
| 337 CallDispatcherOnMainThread( | 337 CallDispatcherOnMainThread( |
| 338 main_thread_loop_.get(), | 338 main_thread_loop_.get(), |
| 339 &FileSystemDispatcher::OpenFileSystem, | 339 &FileSystemDispatcher::OpenFileSystem, |
| 340 MakeTuple(GURL(storage_partition), | 340 MakeTuple(GURL(storage_partition), |
| 341 static_cast<fileapi::FileSystemType>(type), | 341 static_cast<fileapi::FileSystemType>(type), |
| 342 base::Bind(&OpenFileSystemCallbackAdapter, | 342 base::Bind(&OpenFileSystemCallbackAdapter, |
| 343 CurrentWorkerId(), callbacks_id, | 343 CurrentWorkerId(), callbacks_id, |
| 344 base::Unretained(waitable_results)), | 344 waitable_results.get()), |
| 345 base::Bind(&StatusCallbackAdapter, | 345 base::Bind(&StatusCallbackAdapter, |
| 346 CurrentWorkerId(), callbacks_id, | 346 CurrentWorkerId(), callbacks_id, |
| 347 base::Unretained(waitable_results))), | 347 waitable_results.get())), |
| 348 make_scoped_ptr(waitable_results)); | 348 waitable_results.Pass()); |
|
nhiroki
2014/03/05 15:16:08
Hmm... |waitable_results| can be passed before cal
kinuko
2014/03/05 15:23:32
Was about to comment about it. You could keep a ra
| |
| 349 } | 349 } |
| 350 | 350 |
| 351 void WebFileSystemImpl::resolveURL( | 351 void WebFileSystemImpl::resolveURL( |
| 352 const blink::WebURL& filesystem_url, | 352 const blink::WebURL& filesystem_url, |
| 353 WebFileSystemCallbacks callbacks) { | 353 WebFileSystemCallbacks callbacks) { |
| 354 int callbacks_id = RegisterCallbacks(callbacks); | 354 int callbacks_id = RegisterCallbacks(callbacks); |
| 355 WaitableCallbackResults* waitable_results = | 355 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 356 WaitableCallbackResults::MaybeCreate(callbacks); | 356 WaitableCallbackResults::MaybeCreate(callbacks); |
| 357 CallDispatcherOnMainThread( | 357 CallDispatcherOnMainThread( |
| 358 main_thread_loop_.get(), | 358 main_thread_loop_.get(), |
| 359 &FileSystemDispatcher::ResolveURL, | 359 &FileSystemDispatcher::ResolveURL, |
| 360 MakeTuple(GURL(filesystem_url), | 360 MakeTuple(GURL(filesystem_url), |
| 361 base::Bind(&ResolveURLCallbackAdapter, | 361 base::Bind(&ResolveURLCallbackAdapter, |
| 362 CurrentWorkerId(), callbacks_id, | 362 CurrentWorkerId(), callbacks_id, |
| 363 base::Unretained(waitable_results)), | 363 waitable_results.get()), |
| 364 base::Bind(&StatusCallbackAdapter, | 364 base::Bind(&StatusCallbackAdapter, |
| 365 CurrentWorkerId(), callbacks_id, | 365 CurrentWorkerId(), callbacks_id, |
| 366 base::Unretained(waitable_results))), | 366 waitable_results.get())), |
| 367 make_scoped_ptr(waitable_results)); | 367 waitable_results.Pass()); |
| 368 } | 368 } |
| 369 | 369 |
| 370 void WebFileSystemImpl::deleteFileSystem( | 370 void WebFileSystemImpl::deleteFileSystem( |
| 371 const blink::WebURL& storage_partition, | 371 const blink::WebURL& storage_partition, |
| 372 blink::WebFileSystemType type, | 372 blink::WebFileSystemType type, |
| 373 WebFileSystemCallbacks callbacks) { | 373 WebFileSystemCallbacks callbacks) { |
| 374 int callbacks_id = RegisterCallbacks(callbacks); | 374 int callbacks_id = RegisterCallbacks(callbacks); |
| 375 WaitableCallbackResults* waitable_results = | 375 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 376 WaitableCallbackResults::MaybeCreate(callbacks); | 376 WaitableCallbackResults::MaybeCreate(callbacks); |
| 377 CallDispatcherOnMainThread( | 377 CallDispatcherOnMainThread( |
| 378 main_thread_loop_.get(), | 378 main_thread_loop_.get(), |
| 379 &FileSystemDispatcher::DeleteFileSystem, | 379 &FileSystemDispatcher::DeleteFileSystem, |
| 380 MakeTuple(GURL(storage_partition), | 380 MakeTuple(GURL(storage_partition), |
| 381 static_cast<fileapi::FileSystemType>(type), | 381 static_cast<fileapi::FileSystemType>(type), |
| 382 base::Bind(&StatusCallbackAdapter, | 382 base::Bind(&StatusCallbackAdapter, |
| 383 CurrentWorkerId(), callbacks_id, | 383 CurrentWorkerId(), callbacks_id, |
| 384 base::Unretained(waitable_results))), | 384 waitable_results.get())), |
| 385 make_scoped_ptr(waitable_results)); | 385 waitable_results.Pass()); |
| 386 } | 386 } |
| 387 | 387 |
| 388 void WebFileSystemImpl::move( | 388 void WebFileSystemImpl::move( |
| 389 const blink::WebURL& src_path, | 389 const blink::WebURL& src_path, |
| 390 const blink::WebURL& dest_path, | 390 const blink::WebURL& dest_path, |
| 391 WebFileSystemCallbacks callbacks) { | 391 WebFileSystemCallbacks callbacks) { |
| 392 int callbacks_id = RegisterCallbacks(callbacks); | 392 int callbacks_id = RegisterCallbacks(callbacks); |
| 393 WaitableCallbackResults* waitable_results = | 393 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 394 WaitableCallbackResults::MaybeCreate(callbacks); | 394 WaitableCallbackResults::MaybeCreate(callbacks); |
| 395 CallDispatcherOnMainThread( | 395 CallDispatcherOnMainThread( |
| 396 main_thread_loop_.get(), | 396 main_thread_loop_.get(), |
| 397 &FileSystemDispatcher::Move, | 397 &FileSystemDispatcher::Move, |
| 398 MakeTuple(GURL(src_path), GURL(dest_path), | 398 MakeTuple(GURL(src_path), GURL(dest_path), |
| 399 base::Bind(&StatusCallbackAdapter, | 399 base::Bind(&StatusCallbackAdapter, |
| 400 CurrentWorkerId(), callbacks_id, | 400 CurrentWorkerId(), callbacks_id, |
| 401 base::Unretained(waitable_results))), | 401 waitable_results.get())), |
| 402 make_scoped_ptr(waitable_results)); | 402 waitable_results.Pass()); |
| 403 } | 403 } |
| 404 | 404 |
| 405 void WebFileSystemImpl::copy( | 405 void WebFileSystemImpl::copy( |
| 406 const blink::WebURL& src_path, | 406 const blink::WebURL& src_path, |
| 407 const blink::WebURL& dest_path, | 407 const blink::WebURL& dest_path, |
| 408 WebFileSystemCallbacks callbacks) { | 408 WebFileSystemCallbacks callbacks) { |
| 409 int callbacks_id = RegisterCallbacks(callbacks); | 409 int callbacks_id = RegisterCallbacks(callbacks); |
| 410 WaitableCallbackResults* waitable_results = | 410 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 411 WaitableCallbackResults::MaybeCreate(callbacks); | 411 WaitableCallbackResults::MaybeCreate(callbacks); |
| 412 CallDispatcherOnMainThread( | 412 CallDispatcherOnMainThread( |
| 413 main_thread_loop_.get(), | 413 main_thread_loop_.get(), |
| 414 &FileSystemDispatcher::Copy, | 414 &FileSystemDispatcher::Copy, |
| 415 MakeTuple(GURL(src_path), GURL(dest_path), | 415 MakeTuple(GURL(src_path), GURL(dest_path), |
| 416 base::Bind(&StatusCallbackAdapter, | 416 base::Bind(&StatusCallbackAdapter, |
| 417 CurrentWorkerId(), callbacks_id, | 417 CurrentWorkerId(), callbacks_id, |
| 418 base::Unretained(waitable_results))), | 418 waitable_results.get())), |
| 419 make_scoped_ptr(waitable_results)); | 419 waitable_results.Pass()); |
| 420 } | 420 } |
| 421 | 421 |
| 422 void WebFileSystemImpl::remove( | 422 void WebFileSystemImpl::remove( |
| 423 const blink::WebURL& path, | 423 const blink::WebURL& path, |
| 424 WebFileSystemCallbacks callbacks) { | 424 WebFileSystemCallbacks callbacks) { |
| 425 int callbacks_id = RegisterCallbacks(callbacks); | 425 int callbacks_id = RegisterCallbacks(callbacks); |
| 426 WaitableCallbackResults* waitable_results = | 426 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 427 WaitableCallbackResults::MaybeCreate(callbacks); | 427 WaitableCallbackResults::MaybeCreate(callbacks); |
| 428 CallDispatcherOnMainThread( | 428 CallDispatcherOnMainThread( |
| 429 main_thread_loop_.get(), | 429 main_thread_loop_.get(), |
| 430 &FileSystemDispatcher::Remove, | 430 &FileSystemDispatcher::Remove, |
| 431 MakeTuple(GURL(path), false /* recursive */, | 431 MakeTuple(GURL(path), false /* recursive */, |
| 432 base::Bind(&StatusCallbackAdapter, | 432 base::Bind(&StatusCallbackAdapter, |
| 433 CurrentWorkerId(), callbacks_id, | 433 CurrentWorkerId(), callbacks_id, |
| 434 base::Unretained(waitable_results))), | 434 waitable_results.get())), |
| 435 make_scoped_ptr(waitable_results)); | 435 waitable_results.Pass()); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void WebFileSystemImpl::removeRecursively( | 438 void WebFileSystemImpl::removeRecursively( |
| 439 const blink::WebURL& path, | 439 const blink::WebURL& path, |
| 440 WebFileSystemCallbacks callbacks) { | 440 WebFileSystemCallbacks callbacks) { |
| 441 int callbacks_id = RegisterCallbacks(callbacks); | 441 int callbacks_id = RegisterCallbacks(callbacks); |
| 442 WaitableCallbackResults* waitable_results = | 442 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 443 WaitableCallbackResults::MaybeCreate(callbacks); | 443 WaitableCallbackResults::MaybeCreate(callbacks); |
| 444 CallDispatcherOnMainThread( | 444 CallDispatcherOnMainThread( |
| 445 main_thread_loop_.get(), | 445 main_thread_loop_.get(), |
| 446 &FileSystemDispatcher::Remove, | 446 &FileSystemDispatcher::Remove, |
| 447 MakeTuple(GURL(path), true /* recursive */, | 447 MakeTuple(GURL(path), true /* recursive */, |
| 448 base::Bind(&StatusCallbackAdapter, | 448 base::Bind(&StatusCallbackAdapter, |
| 449 CurrentWorkerId(), callbacks_id, | 449 CurrentWorkerId(), callbacks_id, |
| 450 base::Unretained(waitable_results))), | 450 waitable_results.get())), |
| 451 make_scoped_ptr(waitable_results)); | 451 waitable_results.Pass()); |
| 452 } | 452 } |
| 453 | 453 |
| 454 void WebFileSystemImpl::readMetadata( | 454 void WebFileSystemImpl::readMetadata( |
| 455 const blink::WebURL& path, | 455 const blink::WebURL& path, |
| 456 WebFileSystemCallbacks callbacks) { | 456 WebFileSystemCallbacks callbacks) { |
| 457 int callbacks_id = RegisterCallbacks(callbacks); | 457 int callbacks_id = RegisterCallbacks(callbacks); |
| 458 WaitableCallbackResults* waitable_results = | 458 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 459 WaitableCallbackResults::MaybeCreate(callbacks); | 459 WaitableCallbackResults::MaybeCreate(callbacks); |
| 460 CallDispatcherOnMainThread( | 460 CallDispatcherOnMainThread( |
| 461 main_thread_loop_.get(), | 461 main_thread_loop_.get(), |
| 462 &FileSystemDispatcher::ReadMetadata, | 462 &FileSystemDispatcher::ReadMetadata, |
| 463 MakeTuple(GURL(path), | 463 MakeTuple(GURL(path), |
| 464 base::Bind(&ReadMetadataCallbackAdapter, | 464 base::Bind(&ReadMetadataCallbackAdapter, |
| 465 CurrentWorkerId(), callbacks_id, | 465 CurrentWorkerId(), callbacks_id, |
| 466 base::Unretained(waitable_results)), | 466 waitable_results.get()), |
| 467 base::Bind(&StatusCallbackAdapter, | 467 base::Bind(&StatusCallbackAdapter, |
| 468 CurrentWorkerId(), callbacks_id, | 468 CurrentWorkerId(), callbacks_id, |
| 469 base::Unretained(waitable_results))), | 469 waitable_results.get())), |
| 470 make_scoped_ptr(waitable_results)); | 470 waitable_results.Pass()); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void WebFileSystemImpl::createFile( | 473 void WebFileSystemImpl::createFile( |
| 474 const blink::WebURL& path, | 474 const blink::WebURL& path, |
| 475 bool exclusive, | 475 bool exclusive, |
| 476 WebFileSystemCallbacks callbacks) { | 476 WebFileSystemCallbacks callbacks) { |
| 477 int callbacks_id = RegisterCallbacks(callbacks); | 477 int callbacks_id = RegisterCallbacks(callbacks); |
| 478 WaitableCallbackResults* waitable_results = | 478 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 479 WaitableCallbackResults::MaybeCreate(callbacks); | 479 WaitableCallbackResults::MaybeCreate(callbacks); |
| 480 CallDispatcherOnMainThread( | 480 CallDispatcherOnMainThread( |
| 481 main_thread_loop_.get(), | 481 main_thread_loop_.get(), |
| 482 &FileSystemDispatcher::CreateFile, | 482 &FileSystemDispatcher::CreateFile, |
| 483 MakeTuple(GURL(path), exclusive, | 483 MakeTuple(GURL(path), exclusive, |
| 484 base::Bind(&StatusCallbackAdapter, | 484 base::Bind(&StatusCallbackAdapter, |
| 485 CurrentWorkerId(), callbacks_id, | 485 CurrentWorkerId(), callbacks_id, |
| 486 base::Unretained(waitable_results))), | 486 waitable_results.get())), |
| 487 make_scoped_ptr(waitable_results)); | 487 waitable_results.Pass()); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void WebFileSystemImpl::createDirectory( | 490 void WebFileSystemImpl::createDirectory( |
| 491 const blink::WebURL& path, | 491 const blink::WebURL& path, |
| 492 bool exclusive, | 492 bool exclusive, |
| 493 WebFileSystemCallbacks callbacks) { | 493 WebFileSystemCallbacks callbacks) { |
| 494 int callbacks_id = RegisterCallbacks(callbacks); | 494 int callbacks_id = RegisterCallbacks(callbacks); |
| 495 WaitableCallbackResults* waitable_results = | 495 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 496 WaitableCallbackResults::MaybeCreate(callbacks); | 496 WaitableCallbackResults::MaybeCreate(callbacks); |
| 497 CallDispatcherOnMainThread( | 497 CallDispatcherOnMainThread( |
| 498 main_thread_loop_.get(), | 498 main_thread_loop_.get(), |
| 499 &FileSystemDispatcher::CreateDirectory, | 499 &FileSystemDispatcher::CreateDirectory, |
| 500 MakeTuple(GURL(path), exclusive, false /* recursive */, | 500 MakeTuple(GURL(path), exclusive, false /* recursive */, |
| 501 base::Bind(&StatusCallbackAdapter, | 501 base::Bind(&StatusCallbackAdapter, |
| 502 CurrentWorkerId(), callbacks_id, | 502 CurrentWorkerId(), callbacks_id, |
| 503 base::Unretained(waitable_results))), | 503 waitable_results.get())), |
| 504 make_scoped_ptr(waitable_results)); | 504 waitable_results.Pass()); |
| 505 } | 505 } |
| 506 | 506 |
| 507 void WebFileSystemImpl::fileExists( | 507 void WebFileSystemImpl::fileExists( |
| 508 const blink::WebURL& path, | 508 const blink::WebURL& path, |
| 509 WebFileSystemCallbacks callbacks) { | 509 WebFileSystemCallbacks callbacks) { |
| 510 int callbacks_id = RegisterCallbacks(callbacks); | 510 int callbacks_id = RegisterCallbacks(callbacks); |
| 511 WaitableCallbackResults* waitable_results = | 511 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 512 WaitableCallbackResults::MaybeCreate(callbacks); | 512 WaitableCallbackResults::MaybeCreate(callbacks); |
| 513 CallDispatcherOnMainThread( | 513 CallDispatcherOnMainThread( |
| 514 main_thread_loop_.get(), | 514 main_thread_loop_.get(), |
| 515 &FileSystemDispatcher::Exists, | 515 &FileSystemDispatcher::Exists, |
| 516 MakeTuple(GURL(path), false /* directory */, | 516 MakeTuple(GURL(path), false /* directory */, |
| 517 base::Bind(&StatusCallbackAdapter, | 517 base::Bind(&StatusCallbackAdapter, |
| 518 CurrentWorkerId(), callbacks_id, | 518 CurrentWorkerId(), callbacks_id, |
| 519 base::Unretained(waitable_results))), | 519 waitable_results.get())), |
| 520 make_scoped_ptr(waitable_results)); | 520 waitable_results.Pass()); |
| 521 } | 521 } |
| 522 | 522 |
| 523 void WebFileSystemImpl::directoryExists( | 523 void WebFileSystemImpl::directoryExists( |
| 524 const blink::WebURL& path, | 524 const blink::WebURL& path, |
| 525 WebFileSystemCallbacks callbacks) { | 525 WebFileSystemCallbacks callbacks) { |
| 526 int callbacks_id = RegisterCallbacks(callbacks); | 526 int callbacks_id = RegisterCallbacks(callbacks); |
| 527 WaitableCallbackResults* waitable_results = | 527 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 528 WaitableCallbackResults::MaybeCreate(callbacks); | 528 WaitableCallbackResults::MaybeCreate(callbacks); |
| 529 CallDispatcherOnMainThread( | 529 CallDispatcherOnMainThread( |
| 530 main_thread_loop_.get(), | 530 main_thread_loop_.get(), |
| 531 &FileSystemDispatcher::Exists, | 531 &FileSystemDispatcher::Exists, |
| 532 MakeTuple(GURL(path), true /* directory */, | 532 MakeTuple(GURL(path), true /* directory */, |
| 533 base::Bind(&StatusCallbackAdapter, | 533 base::Bind(&StatusCallbackAdapter, |
| 534 CurrentWorkerId(), callbacks_id, | 534 CurrentWorkerId(), callbacks_id, |
| 535 base::Unretained(waitable_results))), | 535 waitable_results.get())), |
| 536 make_scoped_ptr(waitable_results)); | 536 waitable_results.Pass()); |
| 537 } | 537 } |
| 538 | 538 |
| 539 void WebFileSystemImpl::readDirectory( | 539 void WebFileSystemImpl::readDirectory( |
| 540 const blink::WebURL& path, | 540 const blink::WebURL& path, |
| 541 WebFileSystemCallbacks callbacks) { | 541 WebFileSystemCallbacks callbacks) { |
| 542 int callbacks_id = RegisterCallbacks(callbacks); | 542 int callbacks_id = RegisterCallbacks(callbacks); |
| 543 WaitableCallbackResults* waitable_results = | 543 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 544 WaitableCallbackResults::MaybeCreate(callbacks); | 544 WaitableCallbackResults::MaybeCreate(callbacks); |
| 545 CallDispatcherOnMainThread( | 545 CallDispatcherOnMainThread( |
| 546 main_thread_loop_.get(), | 546 main_thread_loop_.get(), |
| 547 &FileSystemDispatcher::ReadDirectory, | 547 &FileSystemDispatcher::ReadDirectory, |
| 548 MakeTuple(GURL(path), | 548 MakeTuple(GURL(path), |
| 549 base::Bind(&ReadDirectoryCallbackAdapater, | 549 base::Bind(&ReadDirectoryCallbackAdapater, |
| 550 CurrentWorkerId(), callbacks_id, | 550 CurrentWorkerId(), callbacks_id, |
| 551 base::Unretained(waitable_results)), | 551 waitable_results.get()), |
| 552 base::Bind(&StatusCallbackAdapter, | 552 base::Bind(&StatusCallbackAdapter, |
| 553 CurrentWorkerId(), callbacks_id, | 553 CurrentWorkerId(), callbacks_id, |
| 554 base::Unretained(waitable_results))), | 554 waitable_results.get())), |
| 555 make_scoped_ptr(waitable_results)); | 555 waitable_results.Pass()); |
| 556 } | 556 } |
| 557 | 557 |
| 558 void WebFileSystemImpl::createFileWriter( | 558 void WebFileSystemImpl::createFileWriter( |
| 559 const WebURL& path, | 559 const WebURL& path, |
| 560 blink::WebFileWriterClient* client, | 560 blink::WebFileWriterClient* client, |
| 561 WebFileSystemCallbacks callbacks) { | 561 WebFileSystemCallbacks callbacks) { |
| 562 int callbacks_id = RegisterCallbacks(callbacks); | 562 int callbacks_id = RegisterCallbacks(callbacks); |
| 563 WaitableCallbackResults* waitable_results = | 563 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 564 WaitableCallbackResults::MaybeCreate(callbacks); | 564 WaitableCallbackResults::MaybeCreate(callbacks); |
| 565 CallDispatcherOnMainThread( | 565 CallDispatcherOnMainThread( |
| 566 main_thread_loop_.get(), | 566 main_thread_loop_.get(), |
| 567 &FileSystemDispatcher::ReadMetadata, | 567 &FileSystemDispatcher::ReadMetadata, |
| 568 MakeTuple(GURL(path), | 568 MakeTuple(GURL(path), |
| 569 base::Bind(&CreateFileWriterCallbackAdapter, | 569 base::Bind(&CreateFileWriterCallbackAdapter, |
| 570 CurrentWorkerId(), callbacks_id, | 570 CurrentWorkerId(), callbacks_id, |
| 571 base::Unretained(waitable_results), | 571 waitable_results.get(), |
| 572 main_thread_loop_, GURL(path), client), | 572 main_thread_loop_, GURL(path), client), |
| 573 base::Bind(&StatusCallbackAdapter, | 573 base::Bind(&StatusCallbackAdapter, |
| 574 CurrentWorkerId(), callbacks_id, | 574 CurrentWorkerId(), callbacks_id, |
| 575 base::Unretained(waitable_results))), | 575 waitable_results.get())), |
| 576 make_scoped_ptr(waitable_results)); | 576 waitable_results.Pass()); |
| 577 } | 577 } |
| 578 | 578 |
| 579 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( | 579 void WebFileSystemImpl::createSnapshotFileAndReadMetadata( |
| 580 const blink::WebURL& path, | 580 const blink::WebURL& path, |
| 581 WebFileSystemCallbacks callbacks) { | 581 WebFileSystemCallbacks callbacks) { |
| 582 int callbacks_id = RegisterCallbacks(callbacks); | 582 int callbacks_id = RegisterCallbacks(callbacks); |
| 583 WaitableCallbackResults* waitable_results = | 583 scoped_ptr<WaitableCallbackResults> waitable_results = |
| 584 WaitableCallbackResults::MaybeCreate(callbacks); | 584 WaitableCallbackResults::MaybeCreate(callbacks); |
| 585 CallDispatcherOnMainThread( | 585 CallDispatcherOnMainThread( |
| 586 main_thread_loop_.get(), | 586 main_thread_loop_.get(), |
| 587 &FileSystemDispatcher::CreateSnapshotFile, | 587 &FileSystemDispatcher::CreateSnapshotFile, |
| 588 MakeTuple(GURL(path), | 588 MakeTuple(GURL(path), |
| 589 base::Bind(&CreateSnapshotFileCallbackAdapter, | 589 base::Bind(&CreateSnapshotFileCallbackAdapter, |
| 590 CurrentWorkerId(), callbacks_id, | 590 CurrentWorkerId(), callbacks_id, |
| 591 base::Unretained(waitable_results), | 591 waitable_results.get(), |
| 592 main_thread_loop_), | 592 main_thread_loop_), |
| 593 base::Bind(&StatusCallbackAdapter, | 593 base::Bind(&StatusCallbackAdapter, |
| 594 CurrentWorkerId(), callbacks_id, | 594 CurrentWorkerId(), callbacks_id, |
| 595 base::Unretained(waitable_results))), | 595 waitable_results.get())), |
| 596 make_scoped_ptr(waitable_results)); | 596 waitable_results.Pass()); |
| 597 } | 597 } |
| 598 | 598 |
| 599 int WebFileSystemImpl::RegisterCallbacks( | 599 int WebFileSystemImpl::RegisterCallbacks( |
| 600 const WebFileSystemCallbacks& callbacks) { | 600 const WebFileSystemCallbacks& callbacks) { |
| 601 DCHECK(CalledOnValidThread()); | 601 DCHECK(CalledOnValidThread()); |
| 602 int id = next_callbacks_id_++; | 602 int id = next_callbacks_id_++; |
| 603 callbacks_[id] = callbacks; | 603 callbacks_[id] = callbacks; |
| 604 return id; | 604 return id; |
| 605 } | 605 } |
| 606 | 606 |
| 607 WebFileSystemCallbacks WebFileSystemImpl::GetAndUnregisterCallbacks( | 607 WebFileSystemCallbacks WebFileSystemImpl::GetAndUnregisterCallbacks( |
| 608 int callbacks_id) { | 608 int callbacks_id) { |
| 609 DCHECK(CalledOnValidThread()); | 609 DCHECK(CalledOnValidThread()); |
| 610 CallbacksMap::iterator found = callbacks_.find(callbacks_id); | 610 CallbacksMap::iterator found = callbacks_.find(callbacks_id); |
| 611 DCHECK(found != callbacks_.end()); | 611 DCHECK(found != callbacks_.end()); |
| 612 WebFileSystemCallbacks callbacks = found->second; | 612 WebFileSystemCallbacks callbacks = found->second; |
| 613 callbacks_.erase(found); | 613 callbacks_.erase(found); |
| 614 return callbacks; | 614 return callbacks; |
| 615 } | 615 } |
| 616 | 616 |
| 617 } // namespace content | 617 } // namespace content |
| OLD | NEW |