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

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

Issue 10827326: gdata: Make callback parameter mandatory for GetEntryInfo family (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 614 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
615 if (update_timer_.IsRunning()) 615 if (update_timer_.IsRunning())
616 update_timer_.Stop(); 616 update_timer_.Stop();
617 } 617 }
618 618
619 void GDataFileSystem::GetEntryInfoByResourceId( 619 void GDataFileSystem::GetEntryInfoByResourceId(
620 const std::string& resource_id, 620 const std::string& resource_id,
621 const GetEntryInfoWithFilePathCallback& callback) { 621 const GetEntryInfoWithFilePathCallback& callback) {
622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 622 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
623 BrowserThread::CurrentlyOn(BrowserThread::IO)); 623 BrowserThread::CurrentlyOn(BrowserThread::IO));
624 DCHECK(!callback.is_null());
625
624 RunTaskOnUIThread( 626 RunTaskOnUIThread(
625 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread, 627 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread,
626 ui_weak_ptr_, 628 ui_weak_ptr_,
627 resource_id, 629 resource_id,
628 CreateRelayCallback(callback))); 630 CreateRelayCallback(callback)));
629 } 631 }
630 632
631 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread( 633 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread(
632 const std::string& resource_id, 634 const std::string& resource_id,
633 const GetEntryInfoWithFilePathCallback& callback) { 635 const GetEntryInfoWithFilePathCallback& callback) {
634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
637 DCHECK(!callback.is_null());
638
635 directory_service_->GetEntryByResourceIdAsync(resource_id, 639 directory_service_->GetEntryByResourceIdAsync(resource_id,
636 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread, 640 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread,
637 ui_weak_ptr_, 641 ui_weak_ptr_,
638 callback)); 642 callback));
639 } 643 }
640 644
641 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( 645 void GDataFileSystem::GetEntryInfoByEntryOnUIThread(
642 const GetEntryInfoWithFilePathCallback& callback, 646 const GetEntryInfoWithFilePathCallback& callback,
643 GDataEntry* entry) { 647 GDataEntry* entry) {
644 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 648 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
649 DCHECK(!callback.is_null());
645 650
646 if (entry) { 651 if (entry) {
647 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 652 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto);
648 entry->ToProtoFull(entry_proto.get()); 653 entry->ToProtoFull(entry_proto.get());
649 CheckLocalModificationAndRun( 654 CheckLocalModificationAndRun(
650 entry_proto.Pass(), 655 entry_proto.Pass(),
651 base::Bind(&RunGetEntryInfoWithFilePathCallback, 656 base::Bind(&RunGetEntryInfoWithFilePathCallback,
652 callback, entry->GetFilePath())); 657 callback, entry->GetFilePath()));
653 } else { 658 } else {
654 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, 659 callback.Run(GDATA_FILE_ERROR_NOT_FOUND,
655 FilePath(), 660 FilePath(),
656 scoped_ptr<GDataEntryProto>()); 661 scoped_ptr<GDataEntryProto>());
657 } 662 }
658 } 663 }
659 664
660 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( 665 void GDataFileSystem::FindEntryByPathAsyncOnUIThread(
661 const FilePath& search_file_path, 666 const FilePath& search_file_path,
662 const FindEntryCallback& callback) { 667 const FindEntryCallback& callback) {
663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
669 DCHECK(!callback.is_null());
664 670
665 if (directory_service_->origin() == INITIALIZING) { 671 if (directory_service_->origin() == INITIALIZING) {
666 // If root feed is not initialized but the initialization process has 672 // If root feed is not initialized but the initialization process has
667 // already started, add an observer to execute the remaining task after 673 // already started, add an observer to execute the remaining task after
668 // the end of the initialization. 674 // the end of the initialization.
669 AddObserver(new InitialLoadObserver( 675 AddObserver(new InitialLoadObserver(
670 this, 676 this,
671 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 677 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
672 ui_weak_ptr_, 678 ui_weak_ptr_,
673 search_file_path, 679 search_file_path,
(...skipping 20 matching lines...) Expand all
694 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 700 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
695 ui_weak_ptr_, 701 ui_weak_ptr_,
696 search_file_path, 702 search_file_path,
697 callback)); 703 callback));
698 } 704 }
699 705
700 void GDataFileSystem::FindEntryByPathSyncOnUIThread( 706 void GDataFileSystem::FindEntryByPathSyncOnUIThread(
701 const FilePath& search_file_path, 707 const FilePath& search_file_path,
702 const FindEntryCallback& callback) { 708 const FindEntryCallback& callback) {
703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 709 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
710 DCHECK(!callback.is_null());
704 711
705 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback); 712 directory_service_->FindEntryByPathAndRunSync(search_file_path, callback);
706 } 713 }
707 714
708 void GDataFileSystem::TransferFileFromRemoteToLocal( 715 void GDataFileSystem::TransferFileFromRemoteToLocal(
709 const FilePath& remote_src_file_path, 716 const FilePath& remote_src_file_path,
710 const FilePath& local_dest_file_path, 717 const FilePath& local_dest_file_path,
711 const FileOperationCallback& callback) { 718 const FileOperationCallback& callback) {
712 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
713 DCHECK(!callback.is_null()); 720 DCHECK(!callback.is_null());
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 entry->ToProtoFull(entry_proto.get()); 1905 entry->ToProtoFull(entry_proto.get());
1899 1906
1900 CheckLocalModificationAndRun(entry_proto.Pass(), callback); 1907 CheckLocalModificationAndRun(entry_proto.Pass(), callback);
1901 } 1908 }
1902 1909
1903 void GDataFileSystem::ReadDirectoryByPath( 1910 void GDataFileSystem::ReadDirectoryByPath(
1904 const FilePath& file_path, 1911 const FilePath& file_path,
1905 const ReadDirectoryWithSettingCallback& callback) { 1912 const ReadDirectoryWithSettingCallback& callback) {
1906 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1907 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1914 BrowserThread::CurrentlyOn(BrowserThread::IO));
1915 DCHECK(!callback.is_null());
1916
1908 RunTaskOnUIThread( 1917 RunTaskOnUIThread(
1909 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, 1918 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread,
1910 ui_weak_ptr_, 1919 ui_weak_ptr_,
1911 file_path, 1920 file_path,
1912 CreateRelayCallback(callback))); 1921 CreateRelayCallback(callback)));
1913 } 1922 }
1914 1923
1915 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread( 1924 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread(
1916 const FilePath& file_path, 1925 const FilePath& file_path,
1917 const ReadDirectoryWithSettingCallback& callback) { 1926 const ReadDirectoryWithSettingCallback& callback) {
1918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1927 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1928 DCHECK(!callback.is_null());
1919 1929
1920 FindEntryByPathAsyncOnUIThread( 1930 FindEntryByPathAsyncOnUIThread(
1921 file_path, 1931 file_path,
1922 base::Bind(&GDataFileSystem::OnReadDirectory, 1932 base::Bind(&GDataFileSystem::OnReadDirectory,
1923 ui_weak_ptr_, 1933 ui_weak_ptr_,
1924 callback)); 1934 callback));
1925 } 1935 }
1926 1936
1927 void GDataFileSystem::OnReadDirectory( 1937 void GDataFileSystem::OnReadDirectory(
1928 const ReadDirectoryWithSettingCallback& callback, 1938 const ReadDirectoryWithSettingCallback& callback,
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
2826 // Notify the observers that the file system is being unmounted. 2836 // Notify the observers that the file system is being unmounted.
2827 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2837 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2828 OnFileSystemBeingUnmounted()); 2838 OnFileSystemBeingUnmounted());
2829 } 2839 }
2830 2840
2831 void GDataFileSystem::RunAndNotifyInitialLoadFinished( 2841 void GDataFileSystem::RunAndNotifyInitialLoadFinished(
2832 const FindEntryCallback& callback, 2842 const FindEntryCallback& callback,
2833 GDataFileError error, 2843 GDataFileError error,
2834 GDataEntry* entry) { 2844 GDataEntry* entry) {
2835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2845 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2846 DCHECK(!callback.is_null());
2836 2847
2837 if (!callback.is_null()) 2848 callback.Run(error, entry);
2838 callback.Run(error, entry);
2839 2849
2840 DVLOG(1) << "RunAndNotifyInitialLoadFinished"; 2850 DVLOG(1) << "RunAndNotifyInitialLoadFinished";
2841 2851
2842 // Notify the observers that root directory has been initialized. 2852 // Notify the observers that root directory has been initialized.
2843 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 2853 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
2844 OnInitialLoadFinished()); 2854 OnInitialLoadFinished());
2845 } 2855 }
2846 2856
2847 GDataFileError GDataFileSystem::AddNewDirectory( 2857 GDataFileError GDataFileSystem::AddNewDirectory(
2848 const FilePath& directory_path, base::Value* entry_value) { 2858 const FilePath& directory_path, base::Value* entry_value) {
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3294 3304
3295 // Then invokes the user-supplied callback function. 3305 // Then invokes the user-supplied callback function.
3296 callback.Run(result); 3306 callback.Run(result);
3297 } 3307 }
3298 3308
3299 void GDataFileSystem::CheckLocalModificationAndRun( 3309 void GDataFileSystem::CheckLocalModificationAndRun(
3300 scoped_ptr<GDataEntryProto> entry_proto, 3310 scoped_ptr<GDataEntryProto> entry_proto,
3301 const GetEntryInfoCallback& callback) { 3311 const GetEntryInfoCallback& callback) {
3302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3312 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3303 DCHECK(entry_proto.get()); 3313 DCHECK(entry_proto.get());
3314 DCHECK(!callback.is_null());
3304 3315
3305 // For entries that will never be cached, use the original entry info as is. 3316 // For entries that will never be cached, use the original entry info as is.
3306 if (!entry_proto->has_file_specific_info() || 3317 if (!entry_proto->has_file_specific_info() ||
3307 entry_proto->file_specific_info().is_hosted_document()) { 3318 entry_proto->file_specific_info().is_hosted_document()) {
3308 if (!callback.is_null()) 3319 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3309 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3310 return; 3320 return;
3311 } 3321 }
3312 3322
3313 // Checks if the file is cached and modified locally. 3323 // Checks if the file is cached and modified locally.
3314 const std::string resource_id = entry_proto->resource_id(); 3324 const std::string resource_id = entry_proto->resource_id();
3315 const std::string md5 = entry_proto->file_specific_info().file_md5(); 3325 const std::string md5 = entry_proto->file_specific_info().file_md5();
3316 cache_->GetCacheEntryOnUIThread( 3326 cache_->GetCacheEntryOnUIThread(
3317 resource_id, 3327 resource_id,
3318 md5, 3328 md5,
3319 base::Bind( 3329 base::Bind(
3320 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, 3330 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry,
3321 ui_weak_ptr_, base::Passed(&entry_proto), callback)); 3331 ui_weak_ptr_, base::Passed(&entry_proto), callback));
3322 } 3332 }
3323 3333
3324 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( 3334 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry(
3325 scoped_ptr<GDataEntryProto> entry_proto, 3335 scoped_ptr<GDataEntryProto> entry_proto,
3326 const GetEntryInfoCallback& callback, 3336 const GetEntryInfoCallback& callback,
3327 bool success, 3337 bool success,
3328 const GDataCacheEntry& cache_entry) { 3338 const GDataCacheEntry& cache_entry) {
3329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3340 DCHECK(!callback.is_null());
3330 3341
3331 // When no dirty cache is found, use the original entry info as is. 3342 // When no dirty cache is found, use the original entry info as is.
3332 if (!success || !cache_entry.is_dirty()) { 3343 if (!success || !cache_entry.is_dirty()) {
3333 if (!callback.is_null()) 3344 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3334 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3335 return; 3345 return;
3336 } 3346 }
3337 3347
3338 // Gets the cache file path. 3348 // Gets the cache file path.
3339 const std::string& resource_id = entry_proto->resource_id(); 3349 const std::string& resource_id = entry_proto->resource_id();
3340 const std::string& md5 = entry_proto->file_specific_info().file_md5(); 3350 const std::string& md5 = entry_proto->file_specific_info().file_md5();
3341 cache_->GetFileOnUIThread( 3351 cache_->GetFileOnUIThread(
3342 resource_id, 3352 resource_id,
3343 md5, 3353 md5,
3344 base::Bind( 3354 base::Bind(
3345 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, 3355 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile,
3346 ui_weak_ptr_, base::Passed(&entry_proto), callback)); 3356 ui_weak_ptr_, base::Passed(&entry_proto), callback));
3347 } 3357 }
3348 3358
3349 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( 3359 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile(
3350 scoped_ptr<GDataEntryProto> entry_proto, 3360 scoped_ptr<GDataEntryProto> entry_proto,
3351 const GetEntryInfoCallback& callback, 3361 const GetEntryInfoCallback& callback,
3352 GDataFileError error, 3362 GDataFileError error,
3353 const std::string& resource_id, 3363 const std::string& resource_id,
3354 const std::string& md5, 3364 const std::string& md5,
3355 const FilePath& local_cache_path) { 3365 const FilePath& local_cache_path) {
3356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3367 DCHECK(!callback.is_null());
3357 3368
3358 // When no dirty cache is found, use the original entry info as is. 3369 // When no dirty cache is found, use the original entry info as is.
3359 if (error != GDATA_FILE_OK) { 3370 if (error != GDATA_FILE_OK) {
3360 if (!callback.is_null()) 3371 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3361 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3362 return; 3372 return;
3363 } 3373 }
3364 3374
3365 // If the cache is dirty, obtain the file info from the cache file itself. 3375 // If the cache is dirty, obtain the file info from the cache file itself.
3366 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; 3376 base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
3367 bool* get_file_info_result = new bool(false); 3377 bool* get_file_info_result = new bool(false);
3368 util::PostBlockingPoolSequencedTaskAndReply( 3378 util::PostBlockingPoolSequencedTaskAndReply(
3369 FROM_HERE, 3379 FROM_HERE,
3370 blocking_task_runner_, 3380 blocking_task_runner_,
3371 base::Bind(&GetFileInfoOnBlockingPool, 3381 base::Bind(&GetFileInfoOnBlockingPool,
3372 local_cache_path, 3382 local_cache_path,
3373 base::Unretained(file_info), 3383 base::Unretained(file_info),
3374 base::Unretained(get_file_info_result)), 3384 base::Unretained(get_file_info_result)),
3375 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, 3385 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo,
3376 ui_weak_ptr_, 3386 ui_weak_ptr_,
3377 base::Passed(&entry_proto), 3387 base::Passed(&entry_proto),
3378 callback, 3388 callback,
3379 base::Owned(file_info), 3389 base::Owned(file_info),
3380 base::Owned(get_file_info_result))); 3390 base::Owned(get_file_info_result)));
3381 } 3391 }
3382 3392
3383 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( 3393 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo(
3384 scoped_ptr<GDataEntryProto> entry_proto, 3394 scoped_ptr<GDataEntryProto> entry_proto,
3385 const GetEntryInfoCallback& callback, 3395 const GetEntryInfoCallback& callback,
3386 base::PlatformFileInfo* file_info, 3396 base::PlatformFileInfo* file_info,
3387 bool* get_file_info_result) { 3397 bool* get_file_info_result) {
3388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3399 DCHECK(!callback.is_null());
3389 3400
3390 if (!*get_file_info_result) { 3401 if (!*get_file_info_result) {
3391 if (!callback.is_null()) 3402 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>());
3392 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>());
3393 return; 3403 return;
3394 } 3404 }
3395 3405
3396 PlatformFileInfoProto entry_file_info; 3406 PlatformFileInfoProto entry_file_info;
3397 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3407 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3398 *entry_proto->mutable_file_info() = entry_file_info; 3408 *entry_proto->mutable_file_info() = entry_file_info;
3399 if (!callback.is_null()) 3409 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3400 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3401 } 3410 }
3402 3411
3403 } // namespace gdata 3412 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698