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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 9583031: gdata:: Add GDataFileSystem::GetFile(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 9 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/gdata/gdata_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 documents_service_bound_to_ui_thread_, 395 documents_service_bound_to_ui_thread_,
396 params.feed_url, 396 params.feed_url,
397 base::Bind(&GDataFileSystem::OnGetDocuments, 397 base::Bind(&GDataFileSystem::OnGetDocuments,
398 file_system_bound_to_ui_thread_, 398 file_system_bound_to_ui_thread_,
399 params))); 399 params)));
400 } 400 }
401 401
402 void GDataFileSystem::Remove(const FilePath& file_path, 402 void GDataFileSystem::Remove(const FilePath& file_path,
403 bool is_recursive, 403 bool is_recursive,
404 const FileOperationCallback& callback) { 404 const FileOperationCallback& callback) {
405 GURL document_url = GetDocumentUrlFromPath(file_path); 405 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path);
406 if (document_url.is_empty()) { 406 if (!file_info) {
407 if (!callback.is_null()) { 407 if (!callback.is_null()) {
408 MessageLoop::current()->PostTask( 408 MessageLoop::current()->PostTask(
409 FROM_HERE, 409 FROM_HERE,
410 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND)); 410 base::Bind(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND));
411 } 411 }
412 return;
412 } 413 }
413 414
414 BrowserThread::PostTask( 415 BrowserThread::PostTask(
415 BrowserThread::UI, FROM_HERE, 416 BrowserThread::UI, FROM_HERE,
416 base::Bind( 417 base::Bind(
417 &DocumentsService::DeleteDocument, 418 &DocumentsService::DeleteDocument,
418 documents_service_bound_to_ui_thread_, 419 documents_service_bound_to_ui_thread_,
419 document_url, 420 file_info->self_url(),
420 base::Bind(&GDataFileSystem::OnRemovedDocument, 421 base::Bind(&GDataFileSystem::OnRemovedDocument,
421 file_system_bound_to_ui_thread_, 422 file_system_bound_to_ui_thread_,
422 callback, 423 callback,
423 file_path, 424 file_path,
424 // MessageLoopProxy is used to run |callback| on the 425 // MessageLoopProxy is used to run |callback| on the
425 // thread where Remove() was called. 426 // thread where this function was called.
426 base::MessageLoopProxy::current()))); 427 base::MessageLoopProxy::current())));
427 } 428 }
428 429
429 void GDataFileSystem::CreateDirectory( 430 void GDataFileSystem::CreateDirectory(
430 const FilePath& directory_path, 431 const FilePath& directory_path,
431 bool is_exclusive, 432 bool is_exclusive,
432 bool is_recursive, 433 bool is_recursive,
433 const FileOperationCallback& callback) { 434 const FileOperationCallback& callback) {
434 CreateDirectoryInternal(directory_path, is_exclusive, is_recursive, callback, 435 CreateDirectoryInternal(directory_path, is_exclusive, is_recursive, callback,
435 base::MessageLoopProxy::current()); 436 base::MessageLoopProxy::current());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 file_system_bound_to_ui_thread_, 495 file_system_bound_to_ui_thread_,
495 CreateDirectoryParams( 496 CreateDirectoryParams(
496 first_missing_path, 497 first_missing_path,
497 directory_path, 498 directory_path,
498 is_exclusive, 499 is_exclusive,
499 is_recursive, 500 is_recursive,
500 callback, 501 callback,
501 reply_proxy)))); 502 reply_proxy))));
502 } 503 }
503 504
505 void GDataFileSystem::GetFile(const FilePath& file_path,
506 const GetFileCallback& callback) {
507 GDataFileBase* file_info = GetGDataFileInfoFromPath(file_path);
508 if (!file_info) {
509 if (!callback.is_null()) {
510 MessageLoop::current()->PostTask(
511 FROM_HERE,
512 base::Bind(callback,
513 base::PLATFORM_FILE_ERROR_NOT_FOUND,
514 FilePath()));
515 }
516 return;
517 }
518
519 // TODO(satorux): We should get a file from the cache if it's present, but
520 // the caching layer is not implemented yet. For now, always download from
521 // the cloud.
522 BrowserThread::PostTask(
523 BrowserThread::UI, FROM_HERE,
524 base::Bind(
525 &DocumentsService::DownloadFile,
526 documents_service_bound_to_ui_thread_,
527 file_info->content_url(),
528 base::Bind(&GDataFileSystem::OnFileDownloaded,
529 file_system_bound_to_ui_thread_,
530 callback,
531 // MessageLoopProxy is used to run |callback| on the
532 // thread where this function was called.
533 base::MessageLoopProxy::current())));
534 }
535
504 void GDataFileSystem::UnsafeFindFileByPath( 536 void GDataFileSystem::UnsafeFindFileByPath(
505 const FilePath& file_path, scoped_refptr<FindFileDelegate> delegate) { 537 const FilePath& file_path, scoped_refptr<FindFileDelegate> delegate) {
506 lock_.AssertAcquired(); 538 lock_.AssertAcquired();
507 539
508 std::vector<FilePath::StringType> components; 540 std::vector<FilePath::StringType> components;
509 file_path.GetComponents(&components); 541 file_path.GetComponents(&components);
510 542
511 GDataDirectory* current_dir = root_.get(); 543 GDataDirectory* current_dir = root_.get();
512 FilePath directory_path; 544 FilePath directory_path;
513 for (size_t i = 0; i < components.size() && current_dir; i++) { 545 for (size_t i = 0; i < components.size() && current_dir; i++) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 delegate->OnFileFound(file_iter->second->AsGDataFile()); 577 delegate->OnFileFound(file_iter->second->AsGDataFile());
546 else 578 else
547 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); 579 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND);
548 580
549 return; 581 return;
550 } 582 }
551 } 583 }
552 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND); 584 delegate->OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND);
553 } 585 }
554 586
555 GURL GDataFileSystem::GetDocumentUrlFromPath(const FilePath& file_path) { 587 GDataFileBase* GDataFileSystem::GetGDataFileInfoFromPath(
588 const FilePath& file_path) {
556 base::AutoLock lock(lock_); 589 base::AutoLock lock(lock_);
557 // Find directory element within the cached file system snapshot. 590 // Find directory element within the cached file system snapshot.
558 scoped_refptr<ReadOnlyFindFileDelegate> find_delegate( 591 scoped_refptr<ReadOnlyFindFileDelegate> find_delegate(
559 new ReadOnlyFindFileDelegate()); 592 new ReadOnlyFindFileDelegate());
560 UnsafeFindFileByPath(file_path, find_delegate); 593 UnsafeFindFileByPath(file_path, find_delegate);
561 if (!find_delegate->file()) 594 if (!find_delegate->file())
562 return GURL(); 595 return NULL;
563 596
564 return find_delegate->file()->self_url(); 597 return find_delegate->file();
565 } 598 }
566 599
567 void GDataFileSystem::OnCreateDirectoryCompleted( 600 void GDataFileSystem::OnCreateDirectoryCompleted(
568 const CreateDirectoryParams& params, 601 const CreateDirectoryParams& params,
569 GDataErrorCode status, 602 GDataErrorCode status,
570 base::Value* created_entry) { 603 base::Value* created_entry) {
571 base::PlatformFileError error = GDataToPlatformError(status); 604 base::PlatformFileError error = GDataToPlatformError(status);
572 if (error != base::PLATFORM_FILE_OK) { 605 if (error != base::PLATFORM_FILE_OK) {
573 if (!params.callback.is_null()) 606 if (!params.callback.is_null())
574 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, error)); 607 params.proxy->PostTask(FROM_HERE, base::Bind(params.callback, error));
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 base::PlatformFileError error = GDataToPlatformError(status); 691 base::PlatformFileError error = GDataToPlatformError(status);
659 692
660 if (error == base::PLATFORM_FILE_OK) 693 if (error == base::PLATFORM_FILE_OK)
661 error = RemoveFileFromFileSystem(file_path); 694 error = RemoveFileFromFileSystem(file_path);
662 695
663 if (!callback.is_null()) { 696 if (!callback.is_null()) {
664 message_loop_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); 697 message_loop_proxy->PostTask(FROM_HERE, base::Bind(callback, error));
665 } 698 }
666 } 699 }
667 700
701 void GDataFileSystem::OnFileDownloaded(
702 const GetFileCallback& callback,
703 scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
704 GDataErrorCode status,
705 const GURL& content_url,
706 const FilePath& file_path) {
707 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
708
709 base::PlatformFileError error = GDataToPlatformError(status);
710
711 if (!callback.is_null()) {
712 message_loop_proxy->PostTask(FROM_HERE,
713 base::Bind(callback, error, file_path));
714 }
715 }
716
668 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem( 717 base::PlatformFileError GDataFileSystem::RemoveFileFromFileSystem(
669 const FilePath& file_path) { 718 const FilePath& file_path) {
670 // We need to lock here as well (despite FindFileByPath lock) since directory 719 // We need to lock here as well (despite FindFileByPath lock) since directory
671 // instance below is a 'live' object. 720 // instance below is a 'live' object.
672 base::AutoLock lock(lock_); 721 base::AutoLock lock(lock_);
673 722
674 // Find directory element within the cached file system snapshot. 723 // Find directory element within the cached file system snapshot.
675 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate( 724 scoped_refptr<ReadOnlyFindFileDelegate> update_delegate(
676 new ReadOnlyFindFileDelegate()); 725 new ReadOnlyFindFileDelegate());
677 UnsafeFindFileByPath(file_path, update_delegate); 726 UnsafeFindFileByPath(file_path, update_delegate);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 896
848 GDataFileSystemFactory::~GDataFileSystemFactory() { 897 GDataFileSystemFactory::~GDataFileSystemFactory() {
849 } 898 }
850 899
851 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor( 900 ProfileKeyedService* GDataFileSystemFactory::BuildServiceInstanceFor(
852 Profile* profile) const { 901 Profile* profile) const {
853 return new GDataFileSystem(profile); 902 return new GDataFileSystem(profile);
854 } 903 }
855 904
856 } // namespace gdata 905 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698