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

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

Issue 10836069: Revert 149576 - gdata: Make WeakPtrFactory the last parameter (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 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 GDataUploaderInterface* uploader, 728 GDataUploaderInterface* uploader,
729 DriveWebAppsRegistryInterface* webapps_registry, 729 DriveWebAppsRegistryInterface* webapps_registry,
730 base::SequencedTaskRunner* blocking_task_runner) 730 base::SequencedTaskRunner* blocking_task_runner)
731 : profile_(profile), 731 : profile_(profile),
732 cache_(cache), 732 cache_(cache),
733 uploader_(uploader), 733 uploader_(uploader),
734 documents_service_(documents_service), 734 documents_service_(documents_service),
735 webapps_registry_(webapps_registry), 735 webapps_registry_(webapps_registry),
736 update_timer_(true /* retain_user_task */, true /* is_repeating */), 736 update_timer_(true /* retain_user_task */, true /* is_repeating */),
737 hide_hosted_docs_(false), 737 hide_hosted_docs_(false),
738 blocking_task_runner_(blocking_task_runner), 738 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
739 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 739 ui_weak_ptr_(ui_weak_ptr_factory_.GetWeakPtr()),
740 blocking_task_runner_(blocking_task_runner) {
740 // Should be created from the file browser extension API on UI thread. 741 // Should be created from the file browser extension API on UI thread.
741 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
742 } 743 }
743 744
744 void GDataFileSystem::Initialize() { 745 void GDataFileSystem::Initialize() {
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 746 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
746 747
747 documents_service_->Initialize(profile_); 748 documents_service_->Initialize(profile_);
748 749
749 directory_service_.reset(new GDataDirectoryService); 750 directory_service_.reset(new GDataDirectoryService);
750 751
751 PrefService* pref_service = profile_->GetPrefs(); 752 PrefService* pref_service = profile_->GetPrefs();
752 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); 753 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles);
753 754
754 InitializePreferenceObserver(); 755 InitializePreferenceObserver();
755 } 756 }
756 757
757 void GDataFileSystem::CheckForUpdates() { 758 void GDataFileSystem::CheckForUpdates() {
758 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 759 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
759 ContentOrigin initial_origin = directory_service_->origin(); 760 ContentOrigin initial_origin = directory_service_->origin();
760 if (initial_origin == FROM_SERVER) { 761 if (initial_origin == FROM_SERVER) {
761 directory_service_->set_origin(REFRESHING); 762 directory_service_->set_origin(REFRESHING);
762 ReloadFeedFromServerIfNeeded( 763 ReloadFeedFromServerIfNeeded(
763 initial_origin, 764 initial_origin,
764 directory_service_->largest_changestamp(), 765 directory_service_->largest_changestamp(),
765 directory_service_->root()->GetFilePath(), 766 directory_service_->root()->GetFilePath(),
766 base::Bind(&GDataFileSystem::OnUpdateChecked, 767 base::Bind(&GDataFileSystem::OnUpdateChecked,
767 weak_ptr_factory_.GetWeakPtr(), 768 ui_weak_ptr_,
768 initial_origin)); 769 initial_origin));
769 } 770 }
770 } 771 }
771 772
772 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin, 773 void GDataFileSystem::OnUpdateChecked(ContentOrigin initial_origin,
773 GDataFileError error, 774 GDataFileError error,
774 GDataEntry* /* entry */) { 775 GDataEntry* /* entry */) {
775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 776 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
776 777
777 if (error != GDATA_FILE_OK) { 778 if (error != GDATA_FILE_OK) {
(...skipping 21 matching lines...) Expand all
799 } 800 }
800 801
801 void GDataFileSystem::StartUpdates() { 802 void GDataFileSystem::StartUpdates() {
802 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 803 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
803 804
804 DCHECK(!update_timer_.IsRunning()); 805 DCHECK(!update_timer_.IsRunning());
805 update_timer_.Start(FROM_HERE, 806 update_timer_.Start(FROM_HERE,
806 base::TimeDelta::FromSeconds( 807 base::TimeDelta::FromSeconds(
807 kGDataUpdateCheckIntervalInSec), 808 kGDataUpdateCheckIntervalInSec),
808 base::Bind(&GDataFileSystem::CheckForUpdates, 809 base::Bind(&GDataFileSystem::CheckForUpdates,
809 weak_ptr_factory_.GetWeakPtr())); 810 ui_weak_ptr_));
810 } 811 }
811 812
812 void GDataFileSystem::StopUpdates() { 813 void GDataFileSystem::StopUpdates() {
813 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 814 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
814 DCHECK(update_timer_.IsRunning()); 815 DCHECK(update_timer_.IsRunning());
815 update_timer_.Stop(); 816 update_timer_.Stop();
816 } 817 }
817 818
818 void GDataFileSystem::GetEntryInfoByResourceId( 819 void GDataFileSystem::GetEntryInfoByResourceId(
819 const std::string& resource_id, 820 const std::string& resource_id,
820 const GetEntryInfoWithFilePathCallback& callback) { 821 const GetEntryInfoWithFilePathCallback& callback) {
821 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 822 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
822 BrowserThread::CurrentlyOn(BrowserThread::IO)); 823 BrowserThread::CurrentlyOn(BrowserThread::IO));
823 RunTaskOnUIThread( 824 RunTaskOnUIThread(
824 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread, 825 base::Bind(&GDataFileSystem::GetEntryInfoByResourceIdOnUIThread,
825 weak_ptr_factory_.GetWeakPtr(), 826 ui_weak_ptr_,
826 resource_id, 827 resource_id,
827 CreateRelayCallback(callback))); 828 CreateRelayCallback(callback)));
828 } 829 }
829 830
830 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread( 831 void GDataFileSystem::GetEntryInfoByResourceIdOnUIThread(
831 const std::string& resource_id, 832 const std::string& resource_id,
832 const GetEntryInfoWithFilePathCallback& callback) { 833 const GetEntryInfoWithFilePathCallback& callback) {
833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 834 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
834 directory_service_->GetEntryByResourceIdAsync(resource_id, 835 directory_service_->GetEntryByResourceIdAsync(resource_id,
835 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread, 836 base::Bind(&GDataFileSystem::GetEntryInfoByEntryOnUIThread,
836 weak_ptr_factory_.GetWeakPtr(), 837 ui_weak_ptr_,
837 callback)); 838 callback));
838 } 839 }
839 840
840 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( 841 void GDataFileSystem::GetEntryInfoByEntryOnUIThread(
841 const GetEntryInfoWithFilePathCallback& callback, 842 const GetEntryInfoWithFilePathCallback& callback,
842 GDataEntry* entry) { 843 GDataEntry* entry) {
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
844 845
845 if (entry) { 846 if (entry) {
846 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 847 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto);
(...skipping 14 matching lines...) Expand all
861 const FindEntryCallback& callback) { 862 const FindEntryCallback& callback) {
862 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 863 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
863 864
864 if (directory_service_->origin() == INITIALIZING) { 865 if (directory_service_->origin() == INITIALIZING) {
865 // If root feed is not initialized but the initialization process has 866 // If root feed is not initialized but the initialization process has
866 // already started, add an observer to execute the remaining task after 867 // already started, add an observer to execute the remaining task after
867 // the end of the initialization. 868 // the end of the initialization.
868 AddObserver(new InitialLoadObserver( 869 AddObserver(new InitialLoadObserver(
869 this, 870 this,
870 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 871 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
871 weak_ptr_factory_.GetWeakPtr(), 872 ui_weak_ptr_,
872 search_file_path, 873 search_file_path,
873 callback))); 874 callback)));
874 return; 875 return;
875 } else if (directory_service_->origin() == UNINITIALIZED) { 876 } else if (directory_service_->origin() == UNINITIALIZED) {
876 // Load root feed from this disk cache. Upon completion, kick off server 877 // Load root feed from this disk cache. Upon completion, kick off server
877 // fetching. 878 // fetching.
878 directory_service_->set_origin(INITIALIZING); 879 directory_service_->set_origin(INITIALIZING);
879 LoadRootFeedFromCache( 880 LoadRootFeedFromCache(
880 true, // should_load_from_server 881 true, // should_load_from_server
881 search_file_path, 882 search_file_path,
882 // This is the initial load, hence we'll notify when it's done. 883 // This is the initial load, hence we'll notify when it's done.
883 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished, 884 base::Bind(&GDataFileSystem::RunAndNotifyInitialLoadFinished,
884 weak_ptr_factory_.GetWeakPtr(), 885 ui_weak_ptr_,
885 callback)); 886 callback));
886 return; 887 return;
887 } 888 }
888 889
889 // Post a task to the same thread, rather than calling it here, as 890 // Post a task to the same thread, rather than calling it here, as
890 // FindEntryByPath() is asynchronous. 891 // FindEntryByPath() is asynchronous.
891 base::MessageLoopProxy::current()->PostTask( 892 base::MessageLoopProxy::current()->PostTask(
892 FROM_HERE, 893 FROM_HERE,
893 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, 894 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread,
894 weak_ptr_factory_.GetWeakPtr(), 895 ui_weak_ptr_,
895 search_file_path, 896 search_file_path,
896 callback)); 897 callback));
897 } 898 }
898 899
899 void GDataFileSystem::FindEntryByPathSyncOnUIThread( 900 void GDataFileSystem::FindEntryByPathSyncOnUIThread(
900 const FilePath& search_file_path, 901 const FilePath& search_file_path,
901 const FindEntryCallback& callback) { 902 const FindEntryCallback& callback) {
902 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
903 904
904 GDataEntry* entry = directory_service_->FindEntryByPathSync( 905 GDataEntry* entry = directory_service_->FindEntryByPathSync(
905 search_file_path); 906 search_file_path);
906 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry); 907 callback.Run(entry ? GDATA_FILE_OK : GDATA_FILE_ERROR_NOT_FOUND, entry);
907 } 908 }
908 909
909 void GDataFileSystem::ReloadFeedFromServerIfNeeded( 910 void GDataFileSystem::ReloadFeedFromServerIfNeeded(
910 ContentOrigin initial_origin, 911 ContentOrigin initial_origin,
911 int local_changestamp, 912 int local_changestamp,
912 const FilePath& search_file_path, 913 const FilePath& search_file_path,
913 const FindEntryCallback& callback) { 914 const FindEntryCallback& callback) {
914 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 915 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
915 916
916 // First fetch the latest changestamp to see if there were any new changes 917 // First fetch the latest changestamp to see if there were any new changes
917 // there at all. 918 // there at all.
918 documents_service_->GetAccountMetadata( 919 documents_service_->GetAccountMetadata(
919 base::Bind(&GDataFileSystem::OnGetAccountMetadata, 920 base::Bind(&GDataFileSystem::OnGetAccountMetadata,
920 weak_ptr_factory_.GetWeakPtr(), 921 ui_weak_ptr_,
921 initial_origin, 922 initial_origin,
922 local_changestamp, 923 local_changestamp,
923 search_file_path, 924 search_file_path,
924 callback)); 925 callback));
925 } 926 }
926 927
927 void GDataFileSystem::OnGetAccountMetadata( 928 void GDataFileSystem::OnGetAccountMetadata(
928 ContentOrigin initial_origin, 929 ContentOrigin initial_origin,
929 int local_changestamp, 930 int local_changestamp,
930 const FilePath& search_file_path, 931 const FilePath& search_file_path,
931 const FindEntryCallback& callback, 932 const FindEntryCallback& callback,
932 GDataErrorCode status, 933 GDataErrorCode status,
933 scoped_ptr<base::Value> feed_data) { 934 scoped_ptr<base::Value> feed_data) {
934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 935 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
935 936
936 GDataFileError error = GDataToGDataFileError(status); 937 GDataFileError error = GDataToGDataFileError(status);
937 if (error != GDATA_FILE_OK) { 938 if (error != GDATA_FILE_OK) {
938 // Get changes starting from the next changestamp from what we have locally. 939 // Get changes starting from the next changestamp from what we have locally.
939 LoadFeedFromServer(initial_origin, 940 LoadFeedFromServer(initial_origin,
940 local_changestamp + 1, 0, 941 local_changestamp + 1, 0,
941 true, /* should_fetch_multiple_feeds */ 942 true, /* should_fetch_multiple_feeds */
942 search_file_path, 943 search_file_path,
943 std::string() /* no search query */, 944 std::string() /* no search query */,
944 std::string() /* no directory resource ID */, 945 std::string() /* no directory resource ID */,
945 callback, 946 callback,
946 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 947 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
947 weak_ptr_factory_.GetWeakPtr())); 948 ui_weak_ptr_));
948 return; 949 return;
949 } 950 }
950 951
951 scoped_ptr<AccountMetadataFeed> account_metadata; 952 scoped_ptr<AccountMetadataFeed> account_metadata;
952 if (feed_data.get()) { 953 if (feed_data.get()) {
953 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data); 954 account_metadata = AccountMetadataFeed::CreateFrom(*feed_data);
954 #ifndef NDEBUG 955 #ifndef NDEBUG
955 // Save account metadata feed for analysis. 956 // Save account metadata feed for analysis.
956 const FilePath path = 957 const FilePath path =
957 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( 958 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
958 kAccountMetadataFile); 959 kAccountMetadataFile);
959 PostBlockingPoolSequencedTask( 960 PostBlockingPoolSequencedTask(
960 FROM_HERE, 961 FROM_HERE,
961 blocking_task_runner_, 962 blocking_task_runner_,
962 base::Bind(&SaveFeedOnBlockingPoolForDebugging, 963 base::Bind(&SaveFeedOnBlockingPoolForDebugging,
963 path, base::Passed(&feed_data))); 964 path, base::Passed(&feed_data)));
964 #endif 965 #endif
965 } 966 }
966 967
967 if (!account_metadata.get()) { 968 if (!account_metadata.get()) {
968 LoadFeedFromServer(initial_origin, 969 LoadFeedFromServer(initial_origin,
969 local_changestamp + 1, 0, 970 local_changestamp + 1, 0,
970 true, /* should_fetch_multiple_feeds */ 971 true, /* should_fetch_multiple_feeds */
971 search_file_path, 972 search_file_path,
972 std::string() /* no search query */, 973 std::string() /* no search query */,
973 std::string() /* no directory resource ID */, 974 std::string() /* no directory resource ID */,
974 callback, 975 callback,
975 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 976 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
976 weak_ptr_factory_.GetWeakPtr())); 977 ui_weak_ptr_));
977 return; 978 return;
978 } 979 }
979 980
980 webapps_registry_->UpdateFromFeed(account_metadata.get()); 981 webapps_registry_->UpdateFromFeed(account_metadata.get());
981 982
982 bool changes_detected = true; 983 bool changes_detected = true;
983 if (local_changestamp >= account_metadata->largest_changestamp()) { 984 if (local_changestamp >= account_metadata->largest_changestamp()) {
984 if (local_changestamp > account_metadata->largest_changestamp()) { 985 if (local_changestamp > account_metadata->largest_changestamp()) {
985 LOG(WARNING) << "Cached client feed is fresher than server, client = " 986 LOG(WARNING) << "Cached client feed is fresher than server, client = "
986 << local_changestamp 987 << local_changestamp
(...skipping 17 matching lines...) Expand all
1004 // Load changes from the server. 1005 // Load changes from the server.
1005 LoadFeedFromServer(initial_origin, 1006 LoadFeedFromServer(initial_origin,
1006 local_changestamp > 0 ? local_changestamp + 1 : 0, 1007 local_changestamp > 0 ? local_changestamp + 1 : 0,
1007 account_metadata->largest_changestamp(), 1008 account_metadata->largest_changestamp(),
1008 true, /* should_fetch_multiple_feeds */ 1009 true, /* should_fetch_multiple_feeds */
1009 search_file_path, 1010 search_file_path,
1010 std::string() /* no search query */, 1011 std::string() /* no search query */,
1011 std::string() /* no directory resource ID */, 1012 std::string() /* no directory resource ID */,
1012 callback, 1013 callback,
1013 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded, 1014 base::Bind(&GDataFileSystem::OnFeedFromServerLoaded,
1014 weak_ptr_factory_.GetWeakPtr())); 1015 ui_weak_ptr_));
1015 } 1016 }
1016 1017
1017 void GDataFileSystem::LoadFeedFromServer( 1018 void GDataFileSystem::LoadFeedFromServer(
1018 ContentOrigin initial_origin, 1019 ContentOrigin initial_origin,
1019 int start_changestamp, 1020 int start_changestamp,
1020 int root_feed_changestamp, 1021 int root_feed_changestamp,
1021 bool should_fetch_multiple_feeds, 1022 bool should_fetch_multiple_feeds,
1022 const FilePath& search_file_path, 1023 const FilePath& search_file_path,
1023 const std::string& search_query, 1024 const std::string& search_query,
1024 const std::string& directory_resource_id, 1025 const std::string& directory_resource_id,
1025 const FindEntryCallback& entry_found_callback, 1026 const FindEntryCallback& entry_found_callback,
1026 const LoadDocumentFeedCallback& feed_load_callback) { 1027 const LoadDocumentFeedCallback& feed_load_callback) {
1027 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1028 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1028 1029
1029 // |feed_list| will contain the list of all collected feed updates that 1030 // |feed_list| will contain the list of all collected feed updates that
1030 // we will receive through calls of DocumentsService::GetDocuments(). 1031 // we will receive through calls of DocumentsService::GetDocuments().
1031 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 1032 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
1032 new std::vector<DocumentFeed*>); 1033 new std::vector<DocumentFeed*>);
1033 const base::TimeTicks start_time = base::TimeTicks::Now(); 1034 const base::TimeTicks start_time = base::TimeTicks::Now();
1034 documents_service_->GetDocuments( 1035 documents_service_->GetDocuments(
1035 GURL(), // root feed start. 1036 GURL(), // root feed start.
1036 start_changestamp, 1037 start_changestamp,
1037 search_query, 1038 search_query,
1038 directory_resource_id, 1039 directory_resource_id,
1039 base::Bind(&GDataFileSystem::OnGetDocuments, 1040 base::Bind(&GDataFileSystem::OnGetDocuments,
1040 weak_ptr_factory_.GetWeakPtr(), 1041 ui_weak_ptr_,
1041 initial_origin, 1042 initial_origin,
1042 feed_load_callback, 1043 feed_load_callback,
1043 base::Owned(new GetDocumentsParams(start_changestamp, 1044 base::Owned(new GetDocumentsParams(start_changestamp,
1044 root_feed_changestamp, 1045 root_feed_changestamp,
1045 feed_list.release(), 1046 feed_list.release(),
1046 should_fetch_multiple_feeds, 1047 should_fetch_multiple_feeds,
1047 search_file_path, 1048 search_file_path,
1048 search_query, 1049 search_query,
1049 directory_resource_id, 1050 directory_resource_id,
1050 entry_found_callback)), 1051 entry_found_callback)),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 } 1085 }
1085 1086
1086 void GDataFileSystem::TransferFileFromRemoteToLocal( 1087 void GDataFileSystem::TransferFileFromRemoteToLocal(
1087 const FilePath& remote_src_file_path, 1088 const FilePath& remote_src_file_path,
1088 const FilePath& local_dest_file_path, 1089 const FilePath& local_dest_file_path,
1089 const FileOperationCallback& callback) { 1090 const FileOperationCallback& callback) {
1090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1091 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1091 1092
1092 GetFileByPath(remote_src_file_path, 1093 GetFileByPath(remote_src_file_path,
1093 base::Bind(&GDataFileSystem::OnGetFileCompleteForTransferFile, 1094 base::Bind(&GDataFileSystem::OnGetFileCompleteForTransferFile,
1094 weak_ptr_factory_.GetWeakPtr(), 1095 ui_weak_ptr_,
1095 local_dest_file_path, 1096 local_dest_file_path,
1096 callback), 1097 callback),
1097 GetDownloadDataCallback()); 1098 GetDownloadDataCallback());
1098 } 1099 }
1099 1100
1100 void GDataFileSystem::TransferFileFromLocalToRemote( 1101 void GDataFileSystem::TransferFileFromLocalToRemote(
1101 const FilePath& local_src_file_path, 1102 const FilePath& local_src_file_path,
1102 const FilePath& remote_dest_file_path, 1103 const FilePath& remote_dest_file_path,
1103 const FileOperationCallback& callback) { 1104 const FileOperationCallback& callback) {
1104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1105 1106
1106 // Make sure the destination directory exists. 1107 // Make sure the destination directory exists.
1107 GetEntryInfoByPath( 1108 GetEntryInfoByPath(
1108 remote_dest_file_path.DirName(), 1109 remote_dest_file_path.DirName(),
1109 base::Bind( 1110 base::Bind(
1110 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo, 1111 &GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo,
1111 weak_ptr_factory_.GetWeakPtr(), 1112 ui_weak_ptr_,
1112 local_src_file_path, 1113 local_src_file_path,
1113 remote_dest_file_path, 1114 remote_dest_file_path,
1114 callback)); 1115 callback));
1115 } 1116 }
1116 1117
1117 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo( 1118 void GDataFileSystem::TransferFileFromLocalToRemoteAfterGetEntryInfo(
1118 const FilePath& local_src_file_path, 1119 const FilePath& local_src_file_path,
1119 const FilePath& remote_dest_file_path, 1120 const FilePath& remote_dest_file_path,
1120 const FileOperationCallback& callback, 1121 const FileOperationCallback& callback,
1121 GDataFileError error, 1122 GDataFileError error,
(...skipping 19 matching lines...) Expand all
1141 } 1142 }
1142 1143
1143 std::string* resource_id = new std::string; 1144 std::string* resource_id = new std::string;
1144 PostBlockingPoolSequencedTaskAndReply( 1145 PostBlockingPoolSequencedTaskAndReply(
1145 FROM_HERE, 1146 FROM_HERE,
1146 blocking_task_runner_, 1147 blocking_task_runner_,
1147 base::Bind(&GetDocumentResourceIdOnBlockingPool, 1148 base::Bind(&GetDocumentResourceIdOnBlockingPool,
1148 local_src_file_path, 1149 local_src_file_path,
1149 resource_id), 1150 resource_id),
1150 base::Bind(&GDataFileSystem::TransferFileForResourceId, 1151 base::Bind(&GDataFileSystem::TransferFileForResourceId,
1151 weak_ptr_factory_.GetWeakPtr(), 1152 ui_weak_ptr_,
1152 local_src_file_path, 1153 local_src_file_path,
1153 remote_dest_file_path, 1154 remote_dest_file_path,
1154 callback, 1155 callback,
1155 base::Owned(resource_id))); 1156 base::Owned(resource_id)));
1156 } 1157 }
1157 1158
1158 void GDataFileSystem::TransferFileForResourceId( 1159 void GDataFileSystem::TransferFileForResourceId(
1159 const FilePath& local_file_path, 1160 const FilePath& local_file_path,
1160 const FilePath& remote_dest_file_path, 1161 const FilePath& remote_dest_file_path,
1161 const FileOperationCallback& callback, 1162 const FileOperationCallback& callback,
(...skipping 30 matching lines...) Expand all
1192 std::string* content_type = new std::string; 1193 std::string* content_type = new std::string;
1193 PostBlockingPoolSequencedTaskAndReply( 1194 PostBlockingPoolSequencedTaskAndReply(
1194 FROM_HERE, 1195 FROM_HERE,
1195 blocking_task_runner_, 1196 blocking_task_runner_,
1196 base::Bind(&GetLocalFileInfoOnBlockingPool, 1197 base::Bind(&GetLocalFileInfoOnBlockingPool,
1197 local_file_path, 1198 local_file_path,
1198 error, 1199 error,
1199 file_size, 1200 file_size,
1200 content_type), 1201 content_type),
1201 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, 1202 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread,
1202 weak_ptr_factory_.GetWeakPtr(), 1203 ui_weak_ptr_,
1203 StartFileUploadParams(local_file_path, 1204 StartFileUploadParams(local_file_path,
1204 remote_dest_file_path, 1205 remote_dest_file_path,
1205 callback), 1206 callback),
1206 base::Owned(error), 1207 base::Owned(error),
1207 base::Owned(file_size), 1208 base::Owned(file_size),
1208 base::Owned(content_type))); 1209 base::Owned(content_type)));
1209 } 1210 }
1210 1211
1211 void GDataFileSystem::StartFileUploadOnUIThread( 1212 void GDataFileSystem::StartFileUploadOnUIThread(
1212 const StartFileUploadParams& params, 1213 const StartFileUploadParams& params,
(...skipping 12 matching lines...) Expand all
1225 params.callback.Run(*error); 1226 params.callback.Run(*error);
1226 1227
1227 return; 1228 return;
1228 } 1229 }
1229 1230
1230 // Make sure the destination directory exists. 1231 // Make sure the destination directory exists.
1231 GetEntryInfoByPath( 1232 GetEntryInfoByPath(
1232 params.remote_file_path.DirName(), 1233 params.remote_file_path.DirName(),
1233 base::Bind( 1234 base::Bind(
1234 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo, 1235 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo,
1235 weak_ptr_factory_.GetWeakPtr(), 1236 ui_weak_ptr_,
1236 params, 1237 params,
1237 *file_size, 1238 *file_size,
1238 *content_type)); 1239 *content_type));
1239 } 1240 }
1240 1241
1241 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo( 1242 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo(
1242 const StartFileUploadParams& params, 1243 const StartFileUploadParams& params,
1243 int64 file_size, 1244 int64 file_size,
1244 std::string content_type, 1245 std::string content_type,
1245 GDataFileError error, 1246 GDataFileError error,
(...skipping 17 matching lines...) Expand all
1263 upload_file_info->gdata_path = params.remote_file_path; 1264 upload_file_info->gdata_path = params.remote_file_path;
1264 // Use the file name as the title. 1265 // Use the file name as the title.
1265 upload_file_info->title = params.remote_file_path.BaseName().value(); 1266 upload_file_info->title = params.remote_file_path.BaseName().value();
1266 upload_file_info->content_length = file_size; 1267 upload_file_info->content_length = file_size;
1267 upload_file_info->all_bytes_present = true; 1268 upload_file_info->all_bytes_present = true;
1268 upload_file_info->content_type = content_type; 1269 upload_file_info->content_type = content_type;
1269 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url()); 1270 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url());
1270 1271
1271 upload_file_info->completion_callback = 1272 upload_file_info->completion_callback =
1272 base::Bind(&GDataFileSystem::OnTransferCompleted, 1273 base::Bind(&GDataFileSystem::OnTransferCompleted,
1273 weak_ptr_factory_.GetWeakPtr(), 1274 ui_weak_ptr_,
1274 params.callback); 1275 params.callback);
1275 1276
1276 uploader_->UploadNewFile(upload_file_info.Pass()); 1277 uploader_->UploadNewFile(upload_file_info.Pass());
1277 } 1278 }
1278 1279
1279 void GDataFileSystem::OnTransferCompleted( 1280 void GDataFileSystem::OnTransferCompleted(
1280 const FileOperationCallback& callback, 1281 const FileOperationCallback& callback,
1281 GDataFileError error, 1282 GDataFileError error,
1282 scoped_ptr<UploadFileInfo> upload_file_info) { 1283 scoped_ptr<UploadFileInfo> upload_file_info) {
1283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 10 matching lines...) Expand all
1294 callback.Run(error); 1295 callback.Run(error);
1295 } 1296 }
1296 } 1297 }
1297 1298
1298 void GDataFileSystem::Copy(const FilePath& src_file_path, 1299 void GDataFileSystem::Copy(const FilePath& src_file_path,
1299 const FilePath& dest_file_path, 1300 const FilePath& dest_file_path,
1300 const FileOperationCallback& callback) { 1301 const FileOperationCallback& callback) {
1301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1302 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1303 BrowserThread::CurrentlyOn(BrowserThread::IO));
1303 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread, 1304 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CopyOnUIThread,
1304 weak_ptr_factory_.GetWeakPtr(), 1305 ui_weak_ptr_,
1305 src_file_path, 1306 src_file_path,
1306 dest_file_path, 1307 dest_file_path,
1307 CreateRelayCallback(callback))); 1308 CreateRelayCallback(callback)));
1308 } 1309 }
1309 1310
1310 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path, 1311 void GDataFileSystem::CopyOnUIThread(const FilePath& src_file_path,
1311 const FilePath& dest_file_path, 1312 const FilePath& dest_file_path,
1312 const FileOperationCallback& callback) { 1313 const FileOperationCallback& callback) {
1313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1314 1315
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 // in the document title. 1351 // in the document title.
1351 dest_file_path.BaseName().RemoveExtension().value(), 1352 dest_file_path.BaseName().RemoveExtension().value(),
1352 callback); 1353 callback);
1353 return; 1354 return;
1354 } 1355 }
1355 1356
1356 // TODO(benchan): Reimplement this once the server API supports 1357 // TODO(benchan): Reimplement this once the server API supports
1357 // copying of regular files directly on the server side. 1358 // copying of regular files directly on the server side.
1358 GetFileByPath(src_file_path, 1359 GetFileByPath(src_file_path,
1359 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy, 1360 base::Bind(&GDataFileSystem::OnGetFileCompleteForCopy,
1360 weak_ptr_factory_.GetWeakPtr(), 1361 ui_weak_ptr_,
1361 dest_file_path, 1362 dest_file_path,
1362 callback), 1363 callback),
1363 GetDownloadDataCallback()); 1364 GetDownloadDataCallback());
1364 } 1365 }
1365 1366
1366 void GDataFileSystem::OnGetFileCompleteForCopy( 1367 void GDataFileSystem::OnGetFileCompleteForCopy(
1367 const FilePath& remote_dest_file_path, 1368 const FilePath& remote_dest_file_path,
1368 const FileOperationCallback& callback, 1369 const FileOperationCallback& callback,
1369 GDataFileError error, 1370 GDataFileError error,
1370 const FilePath& local_file_path, 1371 const FilePath& local_file_path,
(...skipping 12 matching lines...) Expand all
1383 // on the same thread as Copy (IO thread). As TransferRegularFile must run 1384 // on the same thread as Copy (IO thread). As TransferRegularFile must run
1384 // on the UI thread, we thus need to post a task to the UI thread. 1385 // on the UI thread, we thus need to post a task to the UI thread.
1385 // Also, upon the completion of TransferRegularFile, we need to run |callback| 1386 // Also, upon the completion of TransferRegularFile, we need to run |callback|
1386 // on the same thread as Copy (IO thread), and the transition from UI thread 1387 // on the same thread as Copy (IO thread), and the transition from UI thread
1387 // to IO thread is handled by OnTransferRegularFileCompleteForCopy. 1388 // to IO thread is handled by OnTransferRegularFileCompleteForCopy.
1388 DCHECK_EQ(REGULAR_FILE, file_type); 1389 DCHECK_EQ(REGULAR_FILE, file_type);
1389 BrowserThread::PostTask( 1390 BrowserThread::PostTask(
1390 BrowserThread::UI, 1391 BrowserThread::UI,
1391 FROM_HERE, 1392 FROM_HERE,
1392 base::Bind(&GDataFileSystem::TransferRegularFile, 1393 base::Bind(&GDataFileSystem::TransferRegularFile,
1393 weak_ptr_factory_.GetWeakPtr(), 1394 ui_weak_ptr_,
1394 local_file_path, remote_dest_file_path, 1395 local_file_path, remote_dest_file_path,
1395 base::Bind(OnTransferRegularFileCompleteForCopy, 1396 base::Bind(OnTransferRegularFileCompleteForCopy,
1396 callback, 1397 callback,
1397 base::MessageLoopProxy::current()))); 1398 base::MessageLoopProxy::current())));
1398 } 1399 }
1399 1400
1400 void GDataFileSystem::OnGetFileCompleteForTransferFile( 1401 void GDataFileSystem::OnGetFileCompleteForTransferFile(
1401 const FilePath& local_dest_file_path, 1402 const FilePath& local_dest_file_path,
1402 const FileOperationCallback& callback, 1403 const FileOperationCallback& callback,
1403 GDataFileError error, 1404 GDataFileError error,
(...skipping 28 matching lines...) Expand all
1432 1433
1433 void GDataFileSystem::CopyDocumentToDirectory( 1434 void GDataFileSystem::CopyDocumentToDirectory(
1434 const FilePath& dir_path, 1435 const FilePath& dir_path,
1435 const std::string& resource_id, 1436 const std::string& resource_id,
1436 const FilePath::StringType& new_name, 1437 const FilePath::StringType& new_name,
1437 const FileOperationCallback& callback) { 1438 const FileOperationCallback& callback) {
1438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1439 1440
1440 documents_service_->CopyDocument(resource_id, new_name, 1441 documents_service_->CopyDocument(resource_id, new_name,
1441 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, 1442 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted,
1442 weak_ptr_factory_.GetWeakPtr(), 1443 ui_weak_ptr_,
1443 dir_path, 1444 dir_path,
1444 callback)); 1445 callback));
1445 } 1446 }
1446 1447
1447 void GDataFileSystem::Rename(const FilePath& file_path, 1448 void GDataFileSystem::Rename(const FilePath& file_path,
1448 const FilePath::StringType& new_name, 1449 const FilePath::StringType& new_name,
1449 const FilePathUpdateCallback& callback) { 1450 const FilePathUpdateCallback& callback) {
1450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1451 1452
1452 // It is a no-op if the file is renamed to the same name. 1453 // It is a no-op if the file is renamed to the same name.
1453 if (file_path.BaseName().value() == new_name) { 1454 if (file_path.BaseName().value() == new_name) {
1454 if (!callback.is_null()) { 1455 if (!callback.is_null()) {
1455 MessageLoop::current()->PostTask( 1456 MessageLoop::current()->PostTask(
1456 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, file_path)); 1457 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, file_path));
1457 } 1458 }
1458 return; 1459 return;
1459 } 1460 }
1460 1461
1461 // Get the edit URL of an entry at |file_path|. 1462 // Get the edit URL of an entry at |file_path|.
1462 GetEntryInfoByPath(file_path, 1463 GetEntryInfoByPath(file_path,
1463 base::Bind( 1464 base::Bind(
1464 &GDataFileSystem::RenameAfterGetEntryInfo, 1465 &GDataFileSystem::RenameAfterGetEntryInfo,
1465 weak_ptr_factory_.GetWeakPtr(), 1466 ui_weak_ptr_,
1466 file_path, 1467 file_path,
1467 new_name, 1468 new_name,
1468 callback)); 1469 callback));
1469 } 1470 }
1470 1471
1471 void GDataFileSystem::RenameAfterGetEntryInfo( 1472 void GDataFileSystem::RenameAfterGetEntryInfo(
1472 const FilePath& file_path, 1473 const FilePath& file_path,
1473 const FilePath::StringType& new_name, 1474 const FilePath::StringType& new_name,
1474 const FilePathUpdateCallback& callback, 1475 const FilePathUpdateCallback& callback,
1475 GDataFileError error, 1476 GDataFileError error,
(...skipping 17 matching lines...) Expand all
1493 if (new_file.Extension() == 1494 if (new_file.Extension() ==
1494 entry_proto->file_specific_info().document_extension()) { 1495 entry_proto->file_specific_info().document_extension()) {
1495 file_name = new_file.RemoveExtension().value(); 1496 file_name = new_file.RemoveExtension().value();
1496 } 1497 }
1497 } 1498 }
1498 1499
1499 documents_service_->RenameResource( 1500 documents_service_->RenameResource(
1500 GURL(entry_proto->edit_url()), 1501 GURL(entry_proto->edit_url()),
1501 file_name, 1502 file_name,
1502 base::Bind(&GDataFileSystem::OnRenameResourceCompleted, 1503 base::Bind(&GDataFileSystem::OnRenameResourceCompleted,
1503 weak_ptr_factory_.GetWeakPtr(), 1504 ui_weak_ptr_,
1504 file_path, 1505 file_path,
1505 file_name, 1506 file_name,
1506 callback)); 1507 callback));
1507 } 1508 }
1508 1509
1509 void GDataFileSystem::Move(const FilePath& src_file_path, 1510 void GDataFileSystem::Move(const FilePath& src_file_path,
1510 const FilePath& dest_file_path, 1511 const FilePath& dest_file_path,
1511 const FileOperationCallback& callback) { 1512 const FileOperationCallback& callback) {
1512 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1513 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1513 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1514 BrowserThread::CurrentlyOn(BrowserThread::IO));
1514 RunTaskOnUIThread(base::Bind(&GDataFileSystem::MoveOnUIThread, 1515 RunTaskOnUIThread(base::Bind(&GDataFileSystem::MoveOnUIThread,
1515 weak_ptr_factory_.GetWeakPtr(), 1516 ui_weak_ptr_,
1516 src_file_path, 1517 src_file_path,
1517 dest_file_path, 1518 dest_file_path,
1518 CreateRelayCallback(callback))); 1519 CreateRelayCallback(callback)));
1519 } 1520 }
1520 1521
1521 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path, 1522 void GDataFileSystem::MoveOnUIThread(const FilePath& src_file_path,
1522 const FilePath& dest_file_path, 1523 const FilePath& dest_file_path,
1523 const FileOperationCallback& callback) { 1524 const FileOperationCallback& callback) {
1524 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1525 1526
(...skipping 15 matching lines...) Expand all
1541 MessageLoop::current()->PostTask(FROM_HERE, 1542 MessageLoop::current()->PostTask(FROM_HERE,
1542 base::Bind(callback, error)); 1543 base::Bind(callback, error));
1543 } 1544 }
1544 return; 1545 return;
1545 } 1546 }
1546 1547
1547 // If the file/directory is moved to the same directory, just rename it. 1548 // If the file/directory is moved to the same directory, just rename it.
1548 if (src_file_path.DirName() == dest_parent_path) { 1549 if (src_file_path.DirName() == dest_parent_path) {
1549 FilePathUpdateCallback final_file_path_update_callback = 1550 FilePathUpdateCallback final_file_path_update_callback =
1550 base::Bind(&GDataFileSystem::OnFilePathUpdated, 1551 base::Bind(&GDataFileSystem::OnFilePathUpdated,
1551 weak_ptr_factory_.GetWeakPtr(), 1552 ui_weak_ptr_,
1552 callback); 1553 callback);
1553 1554
1554 Rename(src_file_path, dest_file_path.BaseName().value(), 1555 Rename(src_file_path, dest_file_path.BaseName().value(),
1555 final_file_path_update_callback); 1556 final_file_path_update_callback);
1556 return; 1557 return;
1557 } 1558 }
1558 1559
1559 // Otherwise, the move operation involves three steps: 1560 // Otherwise, the move operation involves three steps:
1560 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) 1561 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|)
1561 // within the same directory. The rename operation is a no-op if 1562 // within the same directory. The rename operation is a no-op if
1562 // basename(|src_file_path|) equals to basename(|dest_file_path|). 1563 // basename(|src_file_path|) equals to basename(|dest_file_path|).
1563 // 2. Removes the file from its parent directory (the file is not deleted), 1564 // 2. Removes the file from its parent directory (the file is not deleted),
1564 // which effectively moves the file to the root directory. 1565 // which effectively moves the file to the root directory.
1565 // 3. Adds the file to the parent directory of |dest_file_path|, which 1566 // 3. Adds the file to the parent directory of |dest_file_path|, which
1566 // effectively moves the file from the root directory to the parent 1567 // effectively moves the file from the root directory to the parent
1567 // directory of |dest_file_path|. 1568 // directory of |dest_file_path|.
1568 FilePathUpdateCallback add_file_to_directory_callback = 1569 FilePathUpdateCallback add_file_to_directory_callback =
1569 base::Bind(&GDataFileSystem::AddEntryToDirectory, 1570 base::Bind(&GDataFileSystem::AddEntryToDirectory,
1570 weak_ptr_factory_.GetWeakPtr(), 1571 ui_weak_ptr_,
1571 dest_file_path.DirName(), 1572 dest_file_path.DirName(),
1572 callback); 1573 callback);
1573 1574
1574 FilePathUpdateCallback remove_file_from_directory_callback = 1575 FilePathUpdateCallback remove_file_from_directory_callback =
1575 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, 1576 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory,
1576 weak_ptr_factory_.GetWeakPtr(), 1577 ui_weak_ptr_,
1577 src_file_path.DirName(), 1578 src_file_path.DirName(),
1578 add_file_to_directory_callback); 1579 add_file_to_directory_callback);
1579 1580
1580 Rename(src_file_path, dest_file_path.BaseName().value(), 1581 Rename(src_file_path, dest_file_path.BaseName().value(),
1581 remove_file_from_directory_callback); 1582 remove_file_from_directory_callback);
1582 } 1583 }
1583 1584
1584 void GDataFileSystem::AddEntryToDirectory( 1585 void GDataFileSystem::AddEntryToDirectory(
1585 const FilePath& dir_path, 1586 const FilePath& dir_path,
1586 const FileOperationCallback& callback, 1587 const FileOperationCallback& callback,
(...skipping 18 matching lines...) Expand all
1605 if (!callback.is_null()) 1606 if (!callback.is_null())
1606 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error)); 1607 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, error));
1607 1608
1608 return; 1609 return;
1609 } 1610 }
1610 1611
1611 documents_service_->AddResourceToDirectory( 1612 documents_service_->AddResourceToDirectory(
1612 dir_entry->content_url(), 1613 dir_entry->content_url(),
1613 entry->edit_url(), 1614 entry->edit_url(),
1614 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryCompleted, 1615 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryCompleted,
1615 weak_ptr_factory_.GetWeakPtr(), 1616 ui_weak_ptr_,
1616 callback, 1617 callback,
1617 file_path, 1618 file_path,
1618 dir_path)); 1619 dir_path));
1619 } 1620 }
1620 1621
1621 void GDataFileSystem::RemoveEntryFromDirectory( 1622 void GDataFileSystem::RemoveEntryFromDirectory(
1622 const FilePath& dir_path, 1623 const FilePath& dir_path,
1623 const FilePathUpdateCallback& callback, 1624 const FilePathUpdateCallback& callback,
1624 GDataFileError error, 1625 GDataFileError error,
1625 const FilePath& file_path) { 1626 const FilePath& file_path) {
(...skipping 18 matching lines...) Expand all
1644 base::Bind(callback, error, file_path)); 1645 base::Bind(callback, error, file_path));
1645 } 1646 }
1646 return; 1647 return;
1647 } 1648 }
1648 1649
1649 documents_service_->RemoveResourceFromDirectory( 1650 documents_service_->RemoveResourceFromDirectory(
1650 dir->content_url(), 1651 dir->content_url(),
1651 entry->edit_url(), 1652 entry->edit_url(),
1652 entry->resource_id(), 1653 entry->resource_id(),
1653 base::Bind(&GDataFileSystem::OnRemoveEntryFromDirectoryCompleted, 1654 base::Bind(&GDataFileSystem::OnRemoveEntryFromDirectoryCompleted,
1654 weak_ptr_factory_.GetWeakPtr(), 1655 ui_weak_ptr_,
1655 callback, 1656 callback,
1656 file_path, 1657 file_path,
1657 dir_path)); 1658 dir_path));
1658 } 1659 }
1659 1660
1660 void GDataFileSystem::Remove(const FilePath& file_path, 1661 void GDataFileSystem::Remove(const FilePath& file_path,
1661 bool is_recursive, 1662 bool is_recursive,
1662 const FileOperationCallback& callback) { 1663 const FileOperationCallback& callback) {
1663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1664 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1665 BrowserThread::CurrentlyOn(BrowserThread::IO));
1665 RunTaskOnUIThread(base::Bind(&GDataFileSystem::RemoveOnUIThread, 1666 RunTaskOnUIThread(base::Bind(&GDataFileSystem::RemoveOnUIThread,
1666 weak_ptr_factory_.GetWeakPtr(), 1667 ui_weak_ptr_,
1667 file_path, 1668 file_path,
1668 is_recursive, 1669 is_recursive,
1669 CreateRelayCallback(callback))); 1670 CreateRelayCallback(callback)));
1670 } 1671 }
1671 1672
1672 void GDataFileSystem::RemoveOnUIThread( 1673 void GDataFileSystem::RemoveOnUIThread(
1673 const FilePath& file_path, 1674 const FilePath& file_path,
1674 bool is_recursive, 1675 bool is_recursive,
1675 const FileOperationCallback& callback) { 1676 const FileOperationCallback& callback) {
1676 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1677 1678
1678 // Get the edit URL of an entry at |file_path|. 1679 // Get the edit URL of an entry at |file_path|.
1679 GetEntryInfoByPath(file_path, 1680 GetEntryInfoByPath(file_path,
1680 base::Bind( 1681 base::Bind(
1681 &GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo, 1682 &GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo,
1682 weak_ptr_factory_.GetWeakPtr(), 1683 ui_weak_ptr_,
1683 file_path, 1684 file_path,
1684 is_recursive, 1685 is_recursive,
1685 callback)); 1686 callback));
1686 } 1687 }
1687 1688
1688 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo( 1689 void GDataFileSystem::RemoveOnUIThreadAfterGetEntryInfo(
1689 const FilePath& file_path, 1690 const FilePath& file_path,
1690 bool /* is_recursive */, 1691 bool /* is_recursive */,
1691 const FileOperationCallback& callback, 1692 const FileOperationCallback& callback,
1692 GDataFileError error, 1693 GDataFileError error,
1693 scoped_ptr<GDataEntryProto> entry_proto) { 1694 scoped_ptr<GDataEntryProto> entry_proto) {
1694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1695 1696
1696 if (error != GDATA_FILE_OK) { 1697 if (error != GDATA_FILE_OK) {
1697 if (!callback.is_null()) { 1698 if (!callback.is_null()) {
1698 base::MessageLoopProxy::current()->PostTask( 1699 base::MessageLoopProxy::current()->PostTask(
1699 FROM_HERE, base::Bind(callback, error)); 1700 FROM_HERE, base::Bind(callback, error));
1700 } 1701 }
1701 return; 1702 return;
1702 } 1703 }
1703 1704
1704 DCHECK(entry_proto.get()); 1705 DCHECK(entry_proto.get());
1705 documents_service_->DeleteDocument( 1706 documents_service_->DeleteDocument(
1706 GURL(entry_proto->edit_url()), 1707 GURL(entry_proto->edit_url()),
1707 base::Bind(&GDataFileSystem::OnRemovedDocument, 1708 base::Bind(&GDataFileSystem::OnRemovedDocument,
1708 weak_ptr_factory_.GetWeakPtr(), 1709 ui_weak_ptr_,
1709 callback, 1710 callback,
1710 file_path)); 1711 file_path));
1711 } 1712 }
1712 1713
1713 void GDataFileSystem::CreateDirectory( 1714 void GDataFileSystem::CreateDirectory(
1714 const FilePath& directory_path, 1715 const FilePath& directory_path,
1715 bool is_exclusive, 1716 bool is_exclusive,
1716 bool is_recursive, 1717 bool is_recursive,
1717 const FileOperationCallback& callback) { 1718 const FileOperationCallback& callback) {
1718 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1719 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1719 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1720 BrowserThread::CurrentlyOn(BrowserThread::IO));
1720 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateDirectoryOnUIThread, 1721 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateDirectoryOnUIThread,
1721 weak_ptr_factory_.GetWeakPtr(), 1722 ui_weak_ptr_,
1722 directory_path, 1723 directory_path,
1723 is_exclusive, 1724 is_exclusive,
1724 is_recursive, 1725 is_recursive,
1725 CreateRelayCallback(callback))); 1726 CreateRelayCallback(callback)));
1726 } 1727 }
1727 1728
1728 void GDataFileSystem::CreateDirectoryOnUIThread( 1729 void GDataFileSystem::CreateDirectoryOnUIThread(
1729 const FilePath& directory_path, 1730 const FilePath& directory_path,
1730 bool is_exclusive, 1731 bool is_exclusive,
1731 bool is_recursive, 1732 bool is_recursive,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 MessageLoop::current()->PostTask(FROM_HERE, 1777 MessageLoop::current()->PostTask(FROM_HERE,
1777 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); 1778 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND));
1778 } 1779 }
1779 return; 1780 return;
1780 } 1781 }
1781 1782
1782 documents_service_->CreateDirectory( 1783 documents_service_->CreateDirectory(
1783 last_parent_dir_url, 1784 last_parent_dir_url,
1784 first_missing_path.BaseName().value(), 1785 first_missing_path.BaseName().value(),
1785 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted, 1786 base::Bind(&GDataFileSystem::OnCreateDirectoryCompleted,
1786 weak_ptr_factory_.GetWeakPtr(), 1787 ui_weak_ptr_,
1787 CreateDirectoryParams( 1788 CreateDirectoryParams(
1788 first_missing_path, 1789 first_missing_path,
1789 directory_path, 1790 directory_path,
1790 is_exclusive, 1791 is_exclusive,
1791 is_recursive, 1792 is_recursive,
1792 callback))); 1793 callback)));
1793 } 1794 }
1794 1795
1795 void GDataFileSystem::CreateFile(const FilePath& file_path, 1796 void GDataFileSystem::CreateFile(const FilePath& file_path,
1796 bool is_exclusive, 1797 bool is_exclusive,
1797 const FileOperationCallback& callback) { 1798 const FileOperationCallback& callback) {
1798 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1799 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1799 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1800 BrowserThread::CurrentlyOn(BrowserThread::IO));
1800 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread, 1801 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CreateFileOnUIThread,
1801 weak_ptr_factory_.GetWeakPtr(), 1802 ui_weak_ptr_,
1802 file_path, 1803 file_path,
1803 is_exclusive, 1804 is_exclusive,
1804 CreateRelayCallback(callback))); 1805 CreateRelayCallback(callback)));
1805 } 1806 }
1806 1807
1807 void GDataFileSystem::CreateFileOnUIThread( 1808 void GDataFileSystem::CreateFileOnUIThread(
1808 const FilePath& file_path, 1809 const FilePath& file_path,
1809 bool is_exclusive, 1810 bool is_exclusive,
1810 const FileOperationCallback& callback) { 1811 const FileOperationCallback& callback) {
1811 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1812 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1812 1813
1813 // First, checks the existence of a file at |file_path|. 1814 // First, checks the existence of a file at |file_path|.
1814 FindEntryByPathAsyncOnUIThread( 1815 FindEntryByPathAsyncOnUIThread(
1815 file_path, 1816 file_path,
1816 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile, 1817 base::Bind(&GDataFileSystem::OnGetEntryInfoForCreateFile,
1817 weak_ptr_factory_.GetWeakPtr(), 1818 ui_weak_ptr_,
1818 file_path, 1819 file_path,
1819 is_exclusive, 1820 is_exclusive,
1820 callback)); 1821 callback));
1821 } 1822 }
1822 1823
1823 void GDataFileSystem::OnGetEntryInfoForCreateFile( 1824 void GDataFileSystem::OnGetEntryInfoForCreateFile(
1824 const FilePath& file_path, 1825 const FilePath& file_path,
1825 bool is_exclusive, 1826 bool is_exclusive,
1826 const FileOperationCallback& callback, 1827 const FileOperationCallback& callback,
1827 GDataFileError result, 1828 GDataFileError result,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 } 1862 }
1862 1863
1863 void GDataFileSystem::GetFileByPath( 1864 void GDataFileSystem::GetFileByPath(
1864 const FilePath& file_path, 1865 const FilePath& file_path,
1865 const GetFileCallback& get_file_callback, 1866 const GetFileCallback& get_file_callback,
1866 const GetDownloadDataCallback& get_download_data_callback) { 1867 const GetDownloadDataCallback& get_download_data_callback) {
1867 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1868 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1868 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1869 BrowserThread::CurrentlyOn(BrowserThread::IO));
1869 RunTaskOnUIThread( 1870 RunTaskOnUIThread(
1870 base::Bind(&GDataFileSystem::GetFileByPathOnUIThread, 1871 base::Bind(&GDataFileSystem::GetFileByPathOnUIThread,
1871 weak_ptr_factory_.GetWeakPtr(), 1872 ui_weak_ptr_,
1872 file_path, 1873 file_path,
1873 CreateRelayCallback(get_file_callback), 1874 CreateRelayCallback(get_file_callback),
1874 CreateRelayCallback(get_download_data_callback))); 1875 CreateRelayCallback(get_download_data_callback)));
1875 } 1876 }
1876 1877
1877 void GDataFileSystem::GetFileByPathOnUIThread( 1878 void GDataFileSystem::GetFileByPathOnUIThread(
1878 const FilePath& file_path, 1879 const FilePath& file_path,
1879 const GetFileCallback& get_file_callback, 1880 const GetFileCallback& get_file_callback,
1880 const GetDownloadDataCallback& get_download_data_callback) { 1881 const GetDownloadDataCallback& get_download_data_callback) {
1881 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1882 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1882 1883
1883 GetEntryInfoByPath( 1884 GetEntryInfoByPath(
1884 file_path, 1885 file_path,
1885 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath, 1886 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath,
1886 weak_ptr_factory_.GetWeakPtr(), 1887 ui_weak_ptr_,
1887 file_path, 1888 file_path,
1888 CreateRelayCallback(get_file_callback), 1889 CreateRelayCallback(get_file_callback),
1889 CreateRelayCallback(get_download_data_callback))); 1890 CreateRelayCallback(get_download_data_callback)));
1890 } 1891 }
1891 1892
1892 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath( 1893 void GDataFileSystem::OnGetEntryInfoCompleteForGetFileByPath(
1893 const FilePath& file_path, 1894 const FilePath& file_path,
1894 const GetFileCallback& get_file_callback, 1895 const GetFileCallback& get_file_callback,
1895 const GetDownloadDataCallback& get_download_data_callback, 1896 const GetDownloadDataCallback& get_download_data_callback,
1896 GDataFileError error, 1897 GDataFileError error,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 FilePath local_tmp_path = cache_->GetCacheFilePath( 1967 FilePath local_tmp_path = cache_->GetCacheFilePath(
1967 entry_proto->resource_id(), 1968 entry_proto->resource_id(),
1968 entry_proto->file_specific_info().file_md5(), 1969 entry_proto->file_specific_info().file_md5(),
1969 GDataCache::CACHE_TYPE_TMP, 1970 GDataCache::CACHE_TYPE_TMP,
1970 GDataCache::CACHED_FILE_FROM_SERVER); 1971 GDataCache::CACHED_FILE_FROM_SERVER);
1971 cache_->GetFileOnUIThread( 1972 cache_->GetFileOnUIThread(
1972 entry_proto->resource_id(), 1973 entry_proto->resource_id(),
1973 entry_proto->file_specific_info().file_md5(), 1974 entry_proto->file_specific_info().file_md5(),
1974 base::Bind( 1975 base::Bind(
1975 &GDataFileSystem::OnGetFileFromCache, 1976 &GDataFileSystem::OnGetFileFromCache,
1976 weak_ptr_factory_.GetWeakPtr(), 1977 ui_weak_ptr_,
1977 GetFileFromCacheParams( 1978 GetFileFromCacheParams(
1978 file_path, 1979 file_path,
1979 local_tmp_path, 1980 local_tmp_path,
1980 GURL(entry_proto->content_url()), 1981 GURL(entry_proto->content_url()),
1981 entry_proto->resource_id(), 1982 entry_proto->resource_id(),
1982 entry_proto->file_specific_info().file_md5(), 1983 entry_proto->file_specific_info().file_md5(),
1983 entry_proto->file_specific_info().content_mime_type(), 1984 entry_proto->file_specific_info().content_mime_type(),
1984 get_file_callback, 1985 get_file_callback,
1985 get_download_data_callback))); 1986 get_download_data_callback)));
1986 } 1987 }
1987 1988
1988 void GDataFileSystem::GetFileByResourceId( 1989 void GDataFileSystem::GetFileByResourceId(
1989 const std::string& resource_id, 1990 const std::string& resource_id,
1990 const GetFileCallback& get_file_callback, 1991 const GetFileCallback& get_file_callback,
1991 const GetDownloadDataCallback& get_download_data_callback) { 1992 const GetDownloadDataCallback& get_download_data_callback) {
1992 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 1993 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
1993 BrowserThread::CurrentlyOn(BrowserThread::IO)); 1994 BrowserThread::CurrentlyOn(BrowserThread::IO));
1994 RunTaskOnUIThread( 1995 RunTaskOnUIThread(
1995 base::Bind(&GDataFileSystem::GetFileByResourceIdOnUIThread, 1996 base::Bind(&GDataFileSystem::GetFileByResourceIdOnUIThread,
1996 weak_ptr_factory_.GetWeakPtr(), 1997 ui_weak_ptr_,
1997 resource_id, 1998 resource_id,
1998 CreateRelayCallback(get_file_callback), 1999 CreateRelayCallback(get_file_callback),
1999 CreateRelayCallback(get_download_data_callback))); 2000 CreateRelayCallback(get_download_data_callback)));
2000 } 2001 }
2001 2002
2002 void GDataFileSystem::GetFileByResourceIdOnUIThread( 2003 void GDataFileSystem::GetFileByResourceIdOnUIThread(
2003 const std::string& resource_id, 2004 const std::string& resource_id,
2004 const GetFileCallback& get_file_callback, 2005 const GetFileCallback& get_file_callback,
2005 const GetDownloadDataCallback& get_download_data_callback) { 2006 const GetDownloadDataCallback& get_download_data_callback) {
2006 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2007 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2007 2008
2008 directory_service_->GetEntryByResourceIdAsync(resource_id, 2009 directory_service_->GetEntryByResourceIdAsync(resource_id,
2009 base::Bind(&GDataFileSystem::GetFileByEntryOnUIThread, 2010 base::Bind(&GDataFileSystem::GetFileByEntryOnUIThread,
2010 weak_ptr_factory_.GetWeakPtr(), 2011 ui_weak_ptr_,
2011 get_file_callback, 2012 get_file_callback,
2012 get_download_data_callback)); 2013 get_download_data_callback));
2013 } 2014 }
2014 2015
2015 void GDataFileSystem::GetFileByEntryOnUIThread( 2016 void GDataFileSystem::GetFileByEntryOnUIThread(
2016 const GetFileCallback& get_file_callback, 2017 const GetFileCallback& get_file_callback,
2017 const GetDownloadDataCallback& get_download_data_callback, 2018 const GetDownloadDataCallback& get_download_data_callback,
2018 GDataEntry* entry) { 2019 GDataEntry* entry) {
2019 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2020 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2020 2021
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 // content url from there (we want to make sure used content url is not 2069 // content url from there (we want to make sure used content url is not
2069 // stale). 2070 // stale).
2070 // 2071 //
2071 // Check if we have enough space, based on the expected file size. 2072 // Check if we have enough space, based on the expected file size.
2072 // - if we don't have enough space, try to free up the disk space 2073 // - if we don't have enough space, try to free up the disk space
2073 // - if we still don't have enough space, return "no space" error 2074 // - if we still don't have enough space, return "no space" error
2074 // - if we have enough space, start downloading the file from the server 2075 // - if we have enough space, start downloading the file from the server
2075 documents_service_->GetDocumentEntry( 2076 documents_service_->GetDocumentEntry(
2076 resource_id, 2077 resource_id,
2077 base::Bind(&GDataFileSystem::OnGetDocumentEntry, 2078 base::Bind(&GDataFileSystem::OnGetDocumentEntry,
2078 weak_ptr_factory_.GetWeakPtr(), 2079 ui_weak_ptr_,
2079 cache_file_path, 2080 cache_file_path,
2080 GetFileFromCacheParams(params.virtual_file_path, 2081 GetFileFromCacheParams(params.virtual_file_path,
2081 params.local_tmp_path, 2082 params.local_tmp_path,
2082 params.content_url, 2083 params.content_url,
2083 params.resource_id, 2084 params.resource_id,
2084 params.md5, 2085 params.md5,
2085 params.mime_type, 2086 params.mime_type,
2086 params.get_file_callback, 2087 params.get_file_callback,
2087 params.get_download_data_callback))); 2088 params.get_download_data_callback)));
2088 } 2089 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 2130
2130 bool* has_enough_space = new bool(false); 2131 bool* has_enough_space = new bool(false);
2131 PostBlockingPoolSequencedTaskAndReply( 2132 PostBlockingPoolSequencedTaskAndReply(
2132 FROM_HERE, 2133 FROM_HERE,
2133 blocking_task_runner_, 2134 blocking_task_runner_,
2134 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor, 2135 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor,
2135 base::Unretained(cache_), 2136 base::Unretained(cache_),
2136 file_size, 2137 file_size,
2137 has_enough_space), 2138 has_enough_space),
2138 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace, 2139 base::Bind(&GDataFileSystem::StartDownloadFileIfEnoughSpace,
2139 weak_ptr_factory_.GetWeakPtr(), 2140 ui_weak_ptr_,
2140 params, 2141 params,
2141 content_url, 2142 content_url,
2142 cache_file_path, 2143 cache_file_path,
2143 base::Owned(has_enough_space))); 2144 base::Owned(has_enough_space)));
2144 } 2145 }
2145 2146
2146 void GDataFileSystem::StartDownloadFileIfEnoughSpace( 2147 void GDataFileSystem::StartDownloadFileIfEnoughSpace(
2147 const GetFileFromCacheParams& params, 2148 const GetFileFromCacheParams& params,
2148 const GURL& content_url, 2149 const GURL& content_url,
2149 const FilePath& cache_file_path, 2150 const FilePath& cache_file_path,
(...skipping 10 matching lines...) Expand all
2160 } 2161 }
2161 return; 2162 return;
2162 } 2163 }
2163 2164
2164 // We have enough disk space. Start downloading the file. 2165 // We have enough disk space. Start downloading the file.
2165 documents_service_->DownloadFile( 2166 documents_service_->DownloadFile(
2166 params.virtual_file_path, 2167 params.virtual_file_path,
2167 params.local_tmp_path, 2168 params.local_tmp_path,
2168 content_url, 2169 content_url,
2169 base::Bind(&GDataFileSystem::OnFileDownloaded, 2170 base::Bind(&GDataFileSystem::OnFileDownloaded,
2170 weak_ptr_factory_.GetWeakPtr(), 2171 ui_weak_ptr_,
2171 params), 2172 params),
2172 params.get_download_data_callback); 2173 params.get_download_data_callback);
2173 } 2174 }
2174 2175
2175 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path, 2176 void GDataFileSystem::GetEntryInfoByPath(const FilePath& file_path,
2176 const GetEntryInfoCallback& callback) { 2177 const GetEntryInfoCallback& callback) {
2177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2178 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2179 BrowserThread::CurrentlyOn(BrowserThread::IO));
2179 RunTaskOnUIThread( 2180 RunTaskOnUIThread(
2180 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread, 2181 base::Bind(&GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread,
2181 weak_ptr_factory_.GetWeakPtr(), 2182 ui_weak_ptr_,
2182 file_path, 2183 file_path,
2183 CreateRelayCallback(callback))); 2184 CreateRelayCallback(callback)));
2184 } 2185 }
2185 2186
2186 void GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread( 2187 void GDataFileSystem::GetEntryInfoByPathAsyncOnUIThread(
2187 const FilePath& file_path, 2188 const FilePath& file_path,
2188 const GetEntryInfoCallback& callback) { 2189 const GetEntryInfoCallback& callback) {
2189 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2190 2191
2191 FindEntryByPathAsyncOnUIThread( 2192 FindEntryByPathAsyncOnUIThread(
2192 file_path, 2193 file_path,
2193 base::Bind(&GDataFileSystem::OnGetEntryInfo, 2194 base::Bind(&GDataFileSystem::OnGetEntryInfo,
2194 weak_ptr_factory_.GetWeakPtr(), 2195 ui_weak_ptr_,
2195 callback)); 2196 callback));
2196 } 2197 }
2197 2198
2198 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback, 2199 void GDataFileSystem::OnGetEntryInfo(const GetEntryInfoCallback& callback,
2199 GDataFileError error, 2200 GDataFileError error,
2200 GDataEntry* entry) { 2201 GDataEntry* entry) {
2201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2202 2203
2203 if (error != GDATA_FILE_OK) { 2204 if (error != GDATA_FILE_OK) {
2204 if (!callback.is_null()) 2205 if (!callback.is_null())
2205 callback.Run(error, scoped_ptr<GDataEntryProto>()); 2206 callback.Run(error, scoped_ptr<GDataEntryProto>());
2206 return; 2207 return;
2207 } 2208 }
2208 DCHECK(entry); 2209 DCHECK(entry);
2209 2210
2210 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); 2211 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto);
2211 entry->ToProtoFull(entry_proto.get()); 2212 entry->ToProtoFull(entry_proto.get());
2212 2213
2213 CheckLocalModificationAndRun(entry_proto.Pass(), callback); 2214 CheckLocalModificationAndRun(entry_proto.Pass(), callback);
2214 } 2215 }
2215 2216
2216 void GDataFileSystem::ReadDirectoryByPath( 2217 void GDataFileSystem::ReadDirectoryByPath(
2217 const FilePath& file_path, 2218 const FilePath& file_path,
2218 const ReadDirectoryCallback& callback) { 2219 const ReadDirectoryCallback& callback) {
2219 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2220 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2221 BrowserThread::CurrentlyOn(BrowserThread::IO));
2221 RunTaskOnUIThread( 2222 RunTaskOnUIThread(
2222 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, 2223 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread,
2223 weak_ptr_factory_.GetWeakPtr(), 2224 ui_weak_ptr_,
2224 file_path, 2225 file_path,
2225 CreateRelayCallback(callback))); 2226 CreateRelayCallback(callback)));
2226 } 2227 }
2227 2228
2228 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread( 2229 void GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread(
2229 const FilePath& file_path, 2230 const FilePath& file_path,
2230 const ReadDirectoryCallback& callback) { 2231 const ReadDirectoryCallback& callback) {
2231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2232 2233
2233 FindEntryByPathAsyncOnUIThread( 2234 FindEntryByPathAsyncOnUIThread(
2234 file_path, 2235 file_path,
2235 base::Bind(&GDataFileSystem::OnReadDirectory, 2236 base::Bind(&GDataFileSystem::OnReadDirectory,
2236 weak_ptr_factory_.GetWeakPtr(), 2237 ui_weak_ptr_,
2237 callback)); 2238 callback));
2238 } 2239 }
2239 2240
2240 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback, 2241 void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback,
2241 GDataFileError error, 2242 GDataFileError error,
2242 GDataEntry* entry) { 2243 GDataEntry* entry) {
2243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2244 2245
2245 if (error != GDATA_FILE_OK) { 2246 if (error != GDATA_FILE_OK) {
2246 if (!callback.is_null()) 2247 if (!callback.is_null())
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 2279
2279 if (!callback.is_null()) 2280 if (!callback.is_null())
2280 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass()); 2281 callback.Run(GDATA_FILE_OK, hide_hosted_docs_, entries.Pass());
2281 } 2282 }
2282 2283
2283 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) { 2284 void GDataFileSystem::RequestDirectoryRefresh(const FilePath& file_path) {
2284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2285 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2286 BrowserThread::CurrentlyOn(BrowserThread::IO));
2286 RunTaskOnUIThread( 2287 RunTaskOnUIThread(
2287 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread, 2288 base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread,
2288 weak_ptr_factory_.GetWeakPtr(), 2289 ui_weak_ptr_,
2289 file_path)); 2290 file_path));
2290 } 2291 }
2291 2292
2292 void GDataFileSystem::RequestDirectoryRefreshOnUIThread( 2293 void GDataFileSystem::RequestDirectoryRefreshOnUIThread(
2293 const FilePath& file_path) { 2294 const FilePath& file_path) {
2294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2295 2296
2296 // Make sure the destination directory exists. 2297 // Make sure the destination directory exists.
2297 GetEntryInfoByPath( 2298 GetEntryInfoByPath(
2298 file_path, 2299 file_path,
2299 base::Bind( 2300 base::Bind(
2300 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo, 2301 &GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo,
2301 weak_ptr_factory_.GetWeakPtr(), 2302 ui_weak_ptr_,
2302 file_path)); 2303 file_path));
2303 } 2304 }
2304 2305
2305 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo( 2306 void GDataFileSystem::RequestDirectoryRefreshOnUIThreadAfterGetEntryInfo(
2306 const FilePath& file_path, 2307 const FilePath& file_path,
2307 GDataFileError error, 2308 GDataFileError error,
2308 scoped_ptr<GDataEntryProto> entry_proto) { 2309 scoped_ptr<GDataEntryProto> entry_proto) {
2309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2310 2311
2311 if (error != GDATA_FILE_OK || 2312 if (error != GDATA_FILE_OK ||
2312 !entry_proto->file_info().is_directory()) { 2313 !entry_proto->file_info().is_directory()) {
2313 LOG(ERROR) << "Directory entry not found: " << file_path.value(); 2314 LOG(ERROR) << "Directory entry not found: " << file_path.value();
2314 return; 2315 return;
2315 } 2316 }
2316 2317
2317 LoadFeedFromServer(directory_service_->origin(), 2318 LoadFeedFromServer(directory_service_->origin(),
2318 0, // Not delta feed. 2319 0, // Not delta feed.
2319 0, // Not used. 2320 0, // Not used.
2320 true, // multiple feeds 2321 true, // multiple feeds
2321 file_path, 2322 file_path,
2322 std::string(), // No search query 2323 std::string(), // No search query
2323 entry_proto->resource_id(), 2324 entry_proto->resource_id(),
2324 FindEntryCallback(), // Not used. 2325 FindEntryCallback(), // Not used.
2325 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh, 2326 base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
2326 weak_ptr_factory_.GetWeakPtr())); 2327 ui_weak_ptr_));
2327 } 2328 }
2328 2329
2329 void GDataFileSystem::OnRequestDirectoryRefresh( 2330 void GDataFileSystem::OnRequestDirectoryRefresh(
2330 GetDocumentsParams* params, 2331 GetDocumentsParams* params,
2331 GDataFileError error) { 2332 GDataFileError error) {
2332 DCHECK(params); 2333 DCHECK(params);
2333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2334 2335
2335 const FilePath& directory_path = params->search_file_path; 2336 const FilePath& directory_path = params->search_file_path;
2336 if (error != GDATA_FILE_OK) { 2337 if (error != GDATA_FILE_OK) {
(...skipping 12 matching lines...) Expand all
2349 &unused_delta_feed_changestamp, 2350 &unused_delta_feed_changestamp,
2350 &unused_uma_stats); 2351 &unused_uma_stats);
2351 if (error != GDATA_FILE_OK) { 2352 if (error != GDATA_FILE_OK) {
2352 LOG(ERROR) << "Failed to convert feed: " << directory_path.value() 2353 LOG(ERROR) << "Failed to convert feed: " << directory_path.value()
2353 << ": " << error; 2354 << ": " << error;
2354 return; 2355 return;
2355 } 2356 }
2356 2357
2357 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id, 2358 directory_service_->GetEntryByResourceIdAsync(params->directory_resource_id,
2358 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry, 2359 base::Bind(&GDataFileSystem::RequestDirectoryRefreshByEntry,
2359 weak_ptr_factory_.GetWeakPtr(), 2360 ui_weak_ptr_,
2360 directory_path, 2361 directory_path,
2361 params->directory_resource_id, 2362 params->directory_resource_id,
2362 file_map)); 2363 file_map));
2363 } 2364 }
2364 2365
2365 void GDataFileSystem::RequestDirectoryRefreshByEntry( 2366 void GDataFileSystem::RequestDirectoryRefreshByEntry(
2366 const FilePath& directory_path, 2367 const FilePath& directory_path,
2367 const std::string& directory_resource_id, 2368 const std::string& directory_resource_id,
2368 const FileResourceIdMap& file_map, 2369 const FileResourceIdMap& file_map,
2369 GDataEntry* directory_entry) { 2370 GDataEntry* directory_entry) {
(...skipping 25 matching lines...) Expand all
2395 DVLOG(1) << "Directory refreshed: " << directory_path.value(); 2396 DVLOG(1) << "Directory refreshed: " << directory_path.value();
2396 } 2397 }
2397 2398
2398 void GDataFileSystem::UpdateFileByResourceId( 2399 void GDataFileSystem::UpdateFileByResourceId(
2399 const std::string& resource_id, 2400 const std::string& resource_id,
2400 const FileOperationCallback& callback) { 2401 const FileOperationCallback& callback) {
2401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2402 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2403 BrowserThread::CurrentlyOn(BrowserThread::IO));
2403 RunTaskOnUIThread( 2404 RunTaskOnUIThread(
2404 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, 2405 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread,
2405 weak_ptr_factory_.GetWeakPtr(), 2406 ui_weak_ptr_,
2406 resource_id, 2407 resource_id,
2407 CreateRelayCallback(callback))); 2408 CreateRelayCallback(callback)));
2408 } 2409 }
2409 2410
2410 void GDataFileSystem::UpdateFileByResourceIdOnUIThread( 2411 void GDataFileSystem::UpdateFileByResourceIdOnUIThread(
2411 const std::string& resource_id, 2412 const std::string& resource_id,
2412 const FileOperationCallback& callback) { 2413 const FileOperationCallback& callback) {
2413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2414 2415
2415 directory_service_->GetEntryByResourceIdAsync(resource_id, 2416 directory_service_->GetEntryByResourceIdAsync(resource_id,
2416 base::Bind(&GDataFileSystem::UpdateFileByEntryOnUIThread, 2417 base::Bind(&GDataFileSystem::UpdateFileByEntryOnUIThread,
2417 weak_ptr_factory_.GetWeakPtr(), 2418 ui_weak_ptr_,
2418 callback)); 2419 callback));
2419 } 2420 }
2420 2421
2421 void GDataFileSystem::UpdateFileByEntryOnUIThread( 2422 void GDataFileSystem::UpdateFileByEntryOnUIThread(
2422 const FileOperationCallback& callback, 2423 const FileOperationCallback& callback,
2423 GDataEntry* entry) { 2424 GDataEntry* entry) {
2424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2425 2426
2426 if (!entry || !entry->AsGDataFile()) { 2427 if (!entry || !entry->AsGDataFile()) {
2427 base::MessageLoopProxy::current()->PostTask( 2428 base::MessageLoopProxy::current()->PostTask(
2428 FROM_HERE, 2429 FROM_HERE,
2429 base::Bind(callback, 2430 base::Bind(callback,
2430 GDATA_FILE_ERROR_NOT_FOUND)); 2431 GDATA_FILE_ERROR_NOT_FOUND));
2431 return; 2432 return;
2432 } 2433 }
2433 GDataFile* file = entry->AsGDataFile(); 2434 GDataFile* file = entry->AsGDataFile();
2434 2435
2435 cache_->GetFileOnUIThread( 2436 cache_->GetFileOnUIThread(
2436 file->resource_id(), 2437 file->resource_id(),
2437 file->file_md5(), 2438 file->file_md5(),
2438 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFile, 2439 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFile,
2439 weak_ptr_factory_.GetWeakPtr(), 2440 ui_weak_ptr_,
2440 callback)); 2441 callback));
2441 } 2442 }
2442 2443
2443 void GDataFileSystem::OnGetFileCompleteForUpdateFile( 2444 void GDataFileSystem::OnGetFileCompleteForUpdateFile(
2444 const FileOperationCallback& callback, 2445 const FileOperationCallback& callback,
2445 GDataFileError error, 2446 GDataFileError error,
2446 const std::string& resource_id, 2447 const std::string& resource_id,
2447 const std::string& md5, 2448 const std::string& md5,
2448 const FilePath& cache_file_path) { 2449 const FilePath& cache_file_path) {
2449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2450 2451
2451 if (error != GDATA_FILE_OK) { 2452 if (error != GDATA_FILE_OK) {
2452 if (!callback.is_null()) 2453 if (!callback.is_null())
2453 callback.Run(error); 2454 callback.Run(error);
2454 return; 2455 return;
2455 } 2456 }
2456 2457
2457 // Gets the size of the cache file. Since the file is locally modified, the 2458 // Gets the size of the cache file. Since the file is locally modified, the
2458 // file size information stored in GDataEntry is not correct. 2459 // file size information stored in GDataEntry is not correct.
2459 GDataFileError* get_size_error = new GDataFileError(GDATA_FILE_ERROR_FAILED); 2460 GDataFileError* get_size_error = new GDataFileError(GDATA_FILE_ERROR_FAILED);
2460 int64* file_size = new int64(-1); 2461 int64* file_size = new int64(-1);
2461 PostBlockingPoolSequencedTaskAndReply( 2462 PostBlockingPoolSequencedTaskAndReply(
2462 FROM_HERE, 2463 FROM_HERE,
2463 blocking_task_runner_, 2464 blocking_task_runner_,
2464 base::Bind(&GetLocalFileSizeOnBlockingPool, 2465 base::Bind(&GetLocalFileSizeOnBlockingPool,
2465 cache_file_path, 2466 cache_file_path,
2466 get_size_error, 2467 get_size_error,
2467 file_size), 2468 file_size),
2468 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile, 2469 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile,
2469 weak_ptr_factory_.GetWeakPtr(), 2470 ui_weak_ptr_,
2470 callback, 2471 callback,
2471 resource_id, 2472 resource_id,
2472 md5, 2473 md5,
2473 cache_file_path, 2474 cache_file_path,
2474 base::Owned(get_size_error), 2475 base::Owned(get_size_error),
2475 base::Owned(file_size))); 2476 base::Owned(file_size)));
2476 } 2477 }
2477 2478
2478 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile( 2479 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile(
2479 const FileOperationCallback& callback, 2480 const FileOperationCallback& callback,
2480 const std::string& resource_id, 2481 const std::string& resource_id,
2481 const std::string& md5, 2482 const std::string& md5,
2482 const FilePath& cache_file_path, 2483 const FilePath& cache_file_path,
2483 GDataFileError* error, 2484 GDataFileError* error,
2484 int64* file_size) { 2485 int64* file_size) {
2485 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2486 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2486 2487
2487 if (*error != GDATA_FILE_OK) { 2488 if (*error != GDATA_FILE_OK) {
2488 if (!callback.is_null()) 2489 if (!callback.is_null())
2489 callback.Run(*error); 2490 callback.Run(*error);
2490 return; 2491 return;
2491 } 2492 }
2492 2493
2493 directory_service_->GetEntryByResourceIdAsync(resource_id, 2494 directory_service_->GetEntryByResourceIdAsync(resource_id,
2494 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, 2495 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry,
2495 weak_ptr_factory_.GetWeakPtr(), 2496 ui_weak_ptr_,
2496 callback, 2497 callback,
2497 md5, 2498 md5,
2498 *file_size, 2499 *file_size,
2499 cache_file_path)); 2500 cache_file_path));
2500 } 2501 }
2501 2502
2502 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( 2503 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry(
2503 const FileOperationCallback& callback, 2504 const FileOperationCallback& callback,
2504 const std::string& md5, 2505 const std::string& md5,
2505 int64 file_size, 2506 int64 file_size,
2506 const FilePath& cache_file_path, 2507 const FilePath& cache_file_path,
2507 GDataEntry* entry) { 2508 GDataEntry* entry) {
2508 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2509 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2509 2510
2510 if (!entry || !entry->AsGDataFile()) { 2511 if (!entry || !entry->AsGDataFile()) {
2511 if (!callback.is_null()) 2512 if (!callback.is_null())
2512 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); 2513 callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
2513 return; 2514 return;
2514 } 2515 }
2515 GDataFile* file = entry->AsGDataFile(); 2516 GDataFile* file = entry->AsGDataFile();
2516 2517
2517 uploader_->UploadExistingFile( 2518 uploader_->UploadExistingFile(
2518 file->upload_url(), 2519 file->upload_url(),
2519 file->GetFilePath(), 2520 file->GetFilePath(),
2520 cache_file_path, 2521 cache_file_path,
2521 file_size, 2522 file_size,
2522 file->content_mime_type(), 2523 file->content_mime_type(),
2523 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, 2524 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded,
2524 weak_ptr_factory_.GetWeakPtr(), 2525 ui_weak_ptr_,
2525 callback)); 2526 callback));
2526 } 2527 }
2527 2528
2528 void GDataFileSystem::OnUpdatedFileUploaded( 2529 void GDataFileSystem::OnUpdatedFileUploaded(
2529 const FileOperationCallback& callback, 2530 const FileOperationCallback& callback,
2530 GDataFileError error, 2531 GDataFileError error,
2531 scoped_ptr<UploadFileInfo> upload_file_info) { 2532 scoped_ptr<UploadFileInfo> upload_file_info) {
2532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2533 DCHECK(upload_file_info.get()); 2534 DCHECK(upload_file_info.get());
2534 2535
2535 if (error != GDATA_FILE_OK) { 2536 if (error != GDATA_FILE_OK) {
2536 if (!callback.is_null()) 2537 if (!callback.is_null())
2537 callback.Run(error); 2538 callback.Run(error);
2538 return; 2539 return;
2539 } 2540 }
2540 2541
2541 AddUploadedFile(UPLOAD_EXISTING_FILE, 2542 AddUploadedFile(UPLOAD_EXISTING_FILE,
2542 upload_file_info->gdata_path.DirName(), 2543 upload_file_info->gdata_path.DirName(),
2543 upload_file_info->entry.Pass(), 2544 upload_file_info->entry.Pass(),
2544 upload_file_info->file_path, 2545 upload_file_info->file_path,
2545 GDataCache::FILE_OPERATION_MOVE, 2546 GDataCache::FILE_OPERATION_MOVE,
2546 base::Bind(&OnAddUploadFileCompleted, callback, error)); 2547 base::Bind(&OnAddUploadFileCompleted, callback, error));
2547 } 2548 }
2548 2549
2549 void GDataFileSystem::GetAvailableSpace( 2550 void GDataFileSystem::GetAvailableSpace(
2550 const GetAvailableSpaceCallback& callback) { 2551 const GetAvailableSpaceCallback& callback) {
2551 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2552 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2552 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2553 BrowserThread::CurrentlyOn(BrowserThread::IO));
2553 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread, 2554 RunTaskOnUIThread(base::Bind(&GDataFileSystem::GetAvailableSpaceOnUIThread,
2554 weak_ptr_factory_.GetWeakPtr(), 2555 ui_weak_ptr_,
2555 CreateRelayCallback(callback))); 2556 CreateRelayCallback(callback)));
2556 } 2557 }
2557 2558
2558 void GDataFileSystem::GetAvailableSpaceOnUIThread( 2559 void GDataFileSystem::GetAvailableSpaceOnUIThread(
2559 const GetAvailableSpaceCallback& callback) { 2560 const GetAvailableSpaceCallback& callback) {
2560 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2561 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2561 2562
2562 documents_service_->GetAccountMetadata( 2563 documents_service_->GetAccountMetadata(
2563 base::Bind(&GDataFileSystem::OnGetAvailableSpace, 2564 base::Bind(&GDataFileSystem::OnGetAvailableSpace,
2564 weak_ptr_factory_.GetWeakPtr(), 2565 ui_weak_ptr_,
2565 callback)); 2566 callback));
2566 } 2567 }
2567 2568
2568 void GDataFileSystem::OnGetAvailableSpace( 2569 void GDataFileSystem::OnGetAvailableSpace(
2569 const GetAvailableSpaceCallback& callback, 2570 const GetAvailableSpaceCallback& callback,
2570 GDataErrorCode status, 2571 GDataErrorCode status,
2571 scoped_ptr<base::Value> data) { 2572 scoped_ptr<base::Value> data) {
2572 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2573 2574
2574 GDataFileError error = GDataToGDataFileError(status); 2575 GDataFileError error = GDataToGDataFileError(status);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2684 } 2685 }
2685 2686
2686 // We will need information about result entry to create info for callback. 2687 // We will need information about result entry to create info for callback.
2687 // We can't use |entry| anymore, so we have to refetch entry from file 2688 // We can't use |entry| anymore, so we have to refetch entry from file
2688 // system. Also, |entry| doesn't have file path set before |RefreshFile| 2689 // system. Also, |entry| doesn't have file path set before |RefreshFile|
2689 // call, so we can't get file path from there. 2690 // call, so we can't get file path from there.
2690 directory_service_->GetEntryByResourceIdAsync(entry_resource_id, 2691 directory_service_->GetEntryByResourceIdAsync(entry_resource_id,
2691 base::Bind(&AddEntryToSearchResults, 2692 base::Bind(&AddEntryToSearchResults,
2692 results, 2693 results,
2693 callback, 2694 callback,
2694 base::Bind(&GDataFileSystem::CheckForUpdates, 2695 base::Bind(&GDataFileSystem::CheckForUpdates, ui_weak_ptr_),
2695 weak_ptr_factory_.GetWeakPtr()),
2696 error, 2696 error,
2697 i+1 == feed->entries().size())); 2697 i+1 == feed->entries().size()));
2698 } 2698 }
2699 } 2699 }
2700 2700
2701 void GDataFileSystem::Search(const std::string& search_query, 2701 void GDataFileSystem::Search(const std::string& search_query,
2702 const SearchCallback& callback) { 2702 const SearchCallback& callback) {
2703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 2703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
2704 BrowserThread::CurrentlyOn(BrowserThread::IO)); 2704 BrowserThread::CurrentlyOn(BrowserThread::IO));
2705 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread, 2705 RunTaskOnUIThread(base::Bind(&GDataFileSystem::SearchAsyncOnUIThread,
2706 weak_ptr_factory_.GetWeakPtr(), 2706 ui_weak_ptr_,
2707 search_query, 2707 search_query,
2708 CreateRelayCallback(callback))); 2708 CreateRelayCallback(callback)));
2709 } 2709 }
2710 2710
2711 void GDataFileSystem::SearchAsyncOnUIThread( 2711 void GDataFileSystem::SearchAsyncOnUIThread(
2712 const std::string& search_query, 2712 const std::string& search_query,
2713 const SearchCallback& callback) { 2713 const SearchCallback& callback) {
2714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2714 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2715 scoped_ptr<std::vector<DocumentFeed*> > feed_list( 2715 scoped_ptr<std::vector<DocumentFeed*> > feed_list(
2716 new std::vector<DocumentFeed*>); 2716 new std::vector<DocumentFeed*>);
2717 2717
2718 ContentOrigin initial_origin = directory_service_->origin(); 2718 ContentOrigin initial_origin = directory_service_->origin();
2719 LoadFeedFromServer(initial_origin, 2719 LoadFeedFromServer(initial_origin,
2720 0, 0, // We don't use change stamps when fetching search 2720 0, 0, // We don't use change stamps when fetching search
2721 // data; we always fetch the whole result feed. 2721 // data; we always fetch the whole result feed.
2722 false, // Stop fetching search results after first feed 2722 false, // Stop fetching search results after first feed
2723 // chunk to avoid displaying huge number of search 2723 // chunk to avoid displaying huge number of search
2724 // results (especially since we don't cache them). 2724 // results (especially since we don't cache them).
2725 FilePath(), // Not used. 2725 FilePath(), // Not used.
2726 search_query, 2726 search_query,
2727 std::string(), // No directory resource ID. 2727 std::string(), // No directory resource ID.
2728 FindEntryCallback(), // Not used. 2728 FindEntryCallback(), // Not used.
2729 base::Bind(&GDataFileSystem::OnSearch, 2729 base::Bind(&GDataFileSystem::OnSearch,
2730 weak_ptr_factory_.GetWeakPtr(), 2730 ui_weak_ptr_, callback));
2731 callback));
2732 } 2731 }
2733 2732
2734 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin, 2733 void GDataFileSystem::OnGetDocuments(ContentOrigin initial_origin,
2735 const LoadDocumentFeedCallback& callback, 2734 const LoadDocumentFeedCallback& callback,
2736 GetDocumentsParams* params, 2735 GetDocumentsParams* params,
2737 base::TimeTicks start_time, 2736 base::TimeTicks start_time,
2738 GDataErrorCode status, 2737 GDataErrorCode status,
2739 scoped_ptr<base::Value> data) { 2738 scoped_ptr<base::Value> data) {
2740 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2739 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2741 2740
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2799 // Check if we need to collect more data to complete the directory list. 2798 // Check if we need to collect more data to complete the directory list.
2800 if (params->should_fetch_multiple_feeds && has_next_feed_url && 2799 if (params->should_fetch_multiple_feeds && has_next_feed_url &&
2801 !next_feed_url.is_empty()) { 2800 !next_feed_url.is_empty()) {
2802 // Kick of the remaining part of the feeds. 2801 // Kick of the remaining part of the feeds.
2803 documents_service_->GetDocuments( 2802 documents_service_->GetDocuments(
2804 next_feed_url, 2803 next_feed_url,
2805 params->start_changestamp, 2804 params->start_changestamp,
2806 params->search_query, 2805 params->search_query,
2807 params->directory_resource_id, 2806 params->directory_resource_id,
2808 base::Bind(&GDataFileSystem::OnGetDocuments, 2807 base::Bind(&GDataFileSystem::OnGetDocuments,
2809 weak_ptr_factory_.GetWeakPtr(), 2808 ui_weak_ptr_,
2810 initial_origin, 2809 initial_origin,
2811 callback, 2810 callback,
2812 base::Owned( 2811 base::Owned(
2813 new GetDocumentsParams( 2812 new GetDocumentsParams(
2814 params->start_changestamp, 2813 params->start_changestamp,
2815 params->root_feed_changestamp, 2814 params->root_feed_changestamp,
2816 params->feed_list.release(), 2815 params->feed_list.release(),
2817 params->should_fetch_multiple_feeds, 2816 params->should_fetch_multiple_feeds,
2818 params->search_file_path, 2817 params->search_file_path,
2819 params->search_query, 2818 params->search_query,
(...skipping 18 matching lines...) Expand all
2838 2837
2839 const FilePath path = 2838 const FilePath path =
2840 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append( 2839 cache_->GetCacheDirectoryPath(GDataCache::CACHE_TYPE_META).Append(
2841 kFilesystemProtoFile); 2840 kFilesystemProtoFile);
2842 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path, 2841 LoadRootFeedParams* params = new LoadRootFeedParams(search_file_path,
2843 should_load_from_server, 2842 should_load_from_server,
2844 callback); 2843 callback);
2845 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE, 2844 BrowserThread::GetBlockingPool()->PostTaskAndReply(FROM_HERE,
2846 base::Bind(&LoadProtoOnBlockingPool, path, params), 2845 base::Bind(&LoadProtoOnBlockingPool, path, params),
2847 base::Bind(&GDataFileSystem::OnProtoLoaded, 2846 base::Bind(&GDataFileSystem::OnProtoLoaded,
2848 weak_ptr_factory_.GetWeakPtr(), 2847 ui_weak_ptr_,
2849 base::Owned(params))); 2848 base::Owned(params)));
2850 } 2849 }
2851 2850
2852 void GDataFileSystem::LoadRootFeedFromCacheForTesting() { 2851 void GDataFileSystem::LoadRootFeedFromCacheForTesting() {
2853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2854 2853
2855 LoadRootFeedFromCache( 2854 LoadRootFeedFromCache(
2856 false, // should_load_from_server. 2855 false, // should_load_from_server.
2857 // search_path doesn't matter if FindEntryCallback parameter is null . 2856 // search_path doesn't matter if FindEntryCallback parameter is null .
2858 FilePath(), 2857 FilePath(),
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
3068 const FilePath& downloaded_file_path) { 3067 const FilePath& downloaded_file_path) {
3069 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3068 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3070 3069
3071 // If user cancels download of a pinned-but-not-fetched file, mark file as 3070 // If user cancels download of a pinned-but-not-fetched file, mark file as
3072 // unpinned so that we do not sync the file again. 3071 // unpinned so that we do not sync the file again.
3073 if (status == GDATA_CANCELLED) { 3072 if (status == GDATA_CANCELLED) {
3074 cache_->GetCacheEntryOnUIThread( 3073 cache_->GetCacheEntryOnUIThread(
3075 params.resource_id, 3074 params.resource_id,
3076 params.md5, 3075 params.md5,
3077 base::Bind(&GDataFileSystem::UnpinIfPinned, 3076 base::Bind(&GDataFileSystem::UnpinIfPinned,
3078 weak_ptr_factory_.GetWeakPtr(), 3077 ui_weak_ptr_,
3079 params.resource_id, 3078 params.resource_id,
3080 params.md5)); 3079 params.md5));
3081 } 3080 }
3082 3081
3083 // At this point, the disk can be full or nearly full for several reasons: 3082 // At this point, the disk can be full or nearly full for several reasons:
3084 // - The expected file size was incorrect and the file was larger 3083 // - The expected file size was incorrect and the file was larger
3085 // - There was an in-flight download operation and it used up space 3084 // - There was an in-flight download operation and it used up space
3086 // - The disk became full for some user actions we cannot control 3085 // - The disk became full for some user actions we cannot control
3087 // (ex. the user might have downloaded a large file from a regular web site) 3086 // (ex. the user might have downloaded a large file from a regular web site)
3088 // 3087 //
3089 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, 3088 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE,
3090 // and try to free up space, even if the file was downloaded successfully. 3089 // and try to free up space, even if the file was downloaded successfully.
3091 bool* has_enough_space = new bool(false); 3090 bool* has_enough_space = new bool(false);
3092 PostBlockingPoolSequencedTaskAndReply( 3091 PostBlockingPoolSequencedTaskAndReply(
3093 FROM_HERE, 3092 FROM_HERE,
3094 blocking_task_runner_, 3093 blocking_task_runner_,
3095 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor, 3094 base::Bind(&GDataCache::FreeDiskSpaceIfNeededFor,
3096 base::Unretained(cache_), 3095 base::Unretained(cache_),
3097 0, 3096 0,
3098 has_enough_space), 3097 has_enough_space),
3099 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, 3098 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked,
3100 weak_ptr_factory_.GetWeakPtr(), 3099 ui_weak_ptr_,
3101 params, 3100 params,
3102 status, 3101 status,
3103 content_url, 3102 content_url,
3104 downloaded_file_path, 3103 downloaded_file_path,
3105 base::Owned(has_enough_space))); 3104 base::Owned(has_enough_space)));
3106 } 3105 }
3107 3106
3108 void GDataFileSystem::UnpinIfPinned( 3107 void GDataFileSystem::UnpinIfPinned(
3109 const std::string& resource_id, 3108 const std::string& resource_id,
3110 const std::string& md5, 3109 const std::string& md5,
(...skipping 20 matching lines...) Expand all
3131 // to wait for this operation to finish since the user can already use the 3130 // to wait for this operation to finish since the user can already use the
3132 // downloaded file. 3131 // downloaded file.
3133 if (error == GDATA_FILE_OK) { 3132 if (error == GDATA_FILE_OK) {
3134 if (*has_enough_space) { 3133 if (*has_enough_space) {
3135 cache_->StoreOnUIThread( 3134 cache_->StoreOnUIThread(
3136 params.resource_id, 3135 params.resource_id,
3137 params.md5, 3136 params.md5,
3138 downloaded_file_path, 3137 downloaded_file_path,
3139 GDataCache::FILE_OPERATION_MOVE, 3138 GDataCache::FILE_OPERATION_MOVE,
3140 base::Bind(&GDataFileSystem::OnDownloadStoredToCache, 3139 base::Bind(&GDataFileSystem::OnDownloadStoredToCache,
3141 weak_ptr_factory_.GetWeakPtr())); 3140 ui_weak_ptr_));
3142 } else { 3141 } else {
3143 // If we don't have enough space, remove the downloaded file, and 3142 // If we don't have enough space, remove the downloaded file, and
3144 // report "no space" error. 3143 // report "no space" error.
3145 PostBlockingPoolSequencedTask( 3144 PostBlockingPoolSequencedTask(
3146 FROM_HERE, 3145 FROM_HERE,
3147 blocking_task_runner_, 3146 blocking_task_runner_,
3148 base::Bind(base::IgnoreResult(&file_util::Delete), 3147 base::Bind(base::IgnoreResult(&file_util::Delete),
3149 downloaded_file_path, 3148 downloaded_file_path,
3150 false /* recursive*/)); 3149 false /* recursive*/));
3151 error = GDATA_FILE_ERROR_NO_SPACE; 3150 error = GDATA_FILE_ERROR_NO_SPACE;
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
3424 const FilePath& file_content_path, 3423 const FilePath& file_content_path,
3425 GDataCache::FileOperationType cache_operation, 3424 GDataCache::FileOperationType cache_operation,
3426 const base::Closure& callback) { 3425 const base::Closure& callback) {
3427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3428 3427
3429 // Post a task to the same thread, rather than calling it here, as 3428 // Post a task to the same thread, rather than calling it here, as
3430 // AddUploadedFile() is asynchronous. 3429 // AddUploadedFile() is asynchronous.
3431 base::MessageLoopProxy::current()->PostTask( 3430 base::MessageLoopProxy::current()->PostTask(
3432 FROM_HERE, 3431 FROM_HERE,
3433 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread, 3432 base::Bind(&GDataFileSystem::AddUploadedFileOnUIThread,
3434 weak_ptr_factory_.GetWeakPtr(), 3433 ui_weak_ptr_,
3435 upload_mode, 3434 upload_mode,
3436 virtual_dir_path, 3435 virtual_dir_path,
3437 base::Passed(&entry), 3436 base::Passed(&entry),
3438 file_content_path, 3437 file_content_path,
3439 cache_operation, 3438 cache_operation,
3440 callback)); 3439 callback));
3441 } 3440 }
3442 3441
3443 void GDataFileSystem::AddUploadedFileOnUIThread( 3442 void GDataFileSystem::AddUploadedFileOnUIThread(
3444 UploadMode upload_mode, 3443 UploadMode upload_mode,
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 pref_registrar_.reset(new PrefChangeRegistrar()); 3549 pref_registrar_.reset(new PrefChangeRegistrar());
3551 pref_registrar_->Init(profile_->GetPrefs()); 3550 pref_registrar_->Init(profile_->GetPrefs());
3552 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 3551 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
3553 } 3552 }
3554 3553
3555 void GDataFileSystem::OpenFile(const FilePath& file_path, 3554 void GDataFileSystem::OpenFile(const FilePath& file_path,
3556 const OpenFileCallback& callback) { 3555 const OpenFileCallback& callback) {
3557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 3556 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
3558 BrowserThread::CurrentlyOn(BrowserThread::IO)); 3557 BrowserThread::CurrentlyOn(BrowserThread::IO));
3559 RunTaskOnUIThread(base::Bind(&GDataFileSystem::OpenFileOnUIThread, 3558 RunTaskOnUIThread(base::Bind(&GDataFileSystem::OpenFileOnUIThread,
3560 weak_ptr_factory_.GetWeakPtr(), 3559 ui_weak_ptr_,
3561 file_path, 3560 file_path,
3562 CreateRelayCallback(callback))); 3561 CreateRelayCallback(callback)));
3563 } 3562 }
3564 3563
3565 void GDataFileSystem::OpenFileOnUIThread(const FilePath& file_path, 3564 void GDataFileSystem::OpenFileOnUIThread(const FilePath& file_path,
3566 const OpenFileCallback& callback) { 3565 const OpenFileCallback& callback) {
3567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3568 3567
3569 // If the file is already opened, it cannot be opened again before closed. 3568 // If the file is already opened, it cannot be opened again before closed.
3570 // This is for avoiding simultaneous modification to the file, and moreover 3569 // This is for avoiding simultaneous modification to the file, and moreover
3571 // to avoid an inconsistent cache state (suppose an operation sequence like 3570 // to avoid an inconsistent cache state (suppose an operation sequence like
3572 // Open->Open->modify->Close->modify->Close; the second modify may not be 3571 // Open->Open->modify->Close->modify->Close; the second modify may not be
3573 // synchronized to the server since it is already Closed on the cache). 3572 // synchronized to the server since it is already Closed on the cache).
3574 if (open_files_.find(file_path) != open_files_.end()) { 3573 if (open_files_.find(file_path) != open_files_.end()) {
3575 MessageLoop::current()->PostTask( 3574 MessageLoop::current()->PostTask(
3576 FROM_HERE, 3575 FROM_HERE,
3577 base::Bind(callback, GDATA_FILE_ERROR_IN_USE, FilePath())); 3576 base::Bind(callback, GDATA_FILE_ERROR_IN_USE, FilePath()));
3578 return; 3577 return;
3579 } 3578 }
3580 open_files_.insert(file_path); 3579 open_files_.insert(file_path);
3581 3580
3582 GetEntryInfoByPath( 3581 GetEntryInfoByPath(
3583 file_path, 3582 file_path,
3584 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile, 3583 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForOpenFile,
3585 weak_ptr_factory_.GetWeakPtr(), 3584 ui_weak_ptr_,
3586 file_path, 3585 file_path,
3587 base::Bind(&GDataFileSystem::OnOpenFileFinished, 3586 base::Bind(&GDataFileSystem::OnOpenFileFinished,
3588 weak_ptr_factory_.GetWeakPtr(), 3587 ui_weak_ptr_,
3589 file_path, 3588 file_path,
3590 callback))); 3589 callback)));
3591 } 3590 }
3592 3591
3593 void GDataFileSystem::OnGetEntryInfoCompleteForOpenFile( 3592 void GDataFileSystem::OnGetEntryInfoCompleteForOpenFile(
3594 const FilePath& file_path, 3593 const FilePath& file_path,
3595 const OpenFileCallback& callback, 3594 const OpenFileCallback& callback,
3596 GDataFileError error, 3595 GDataFileError error,
3597 scoped_ptr<GDataEntryProto> entry_proto) { 3596 scoped_ptr<GDataEntryProto> entry_proto) {
3598 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 12 matching lines...) Expand all
3611 if (error != GDATA_FILE_OK) { 3610 if (error != GDATA_FILE_OK) {
3612 if (!callback.is_null()) 3611 if (!callback.is_null())
3613 callback.Run(error, FilePath()); 3612 callback.Run(error, FilePath());
3614 return; 3613 return;
3615 } 3614 }
3616 3615
3617 DCHECK(!entry_proto->resource_id().empty()); 3616 DCHECK(!entry_proto->resource_id().empty());
3618 GetResolvedFileByPath( 3617 GetResolvedFileByPath(
3619 file_path, 3618 file_path,
3620 base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile, 3619 base::Bind(&GDataFileSystem::OnGetFileCompleteForOpenFile,
3621 weak_ptr_factory_.GetWeakPtr(), 3620 ui_weak_ptr_,
3622 callback, 3621 callback,
3623 GetFileCompleteForOpenParams( 3622 GetFileCompleteForOpenParams(
3624 entry_proto->resource_id(), 3623 entry_proto->resource_id(),
3625 entry_proto->file_specific_info().file_md5())), 3624 entry_proto->file_specific_info().file_md5())),
3626 GetDownloadDataCallback(), 3625 GetDownloadDataCallback(),
3627 error, 3626 error,
3628 entry_proto.get()); 3627 entry_proto.get());
3629 } 3628 }
3630 3629
3631 void GDataFileSystem::OnGetFileCompleteForOpenFile( 3630 void GDataFileSystem::OnGetFileCompleteForOpenFile(
(...skipping 11 matching lines...) Expand all
3643 return; 3642 return;
3644 } 3643 }
3645 3644
3646 // OpenFileOnUIThread ensures that the file is a regular file. 3645 // OpenFileOnUIThread ensures that the file is a regular file.
3647 DCHECK_EQ(REGULAR_FILE, file_type); 3646 DCHECK_EQ(REGULAR_FILE, file_type);
3648 3647
3649 cache_->MarkDirtyOnUIThread( 3648 cache_->MarkDirtyOnUIThread(
3650 entry_proto.resource_id, 3649 entry_proto.resource_id,
3651 entry_proto.md5, 3650 entry_proto.md5,
3652 base::Bind(&GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile, 3651 base::Bind(&GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile,
3653 weak_ptr_factory_.GetWeakPtr(), 3652 ui_weak_ptr_,
3654 callback)); 3653 callback));
3655 } 3654 }
3656 3655
3657 void GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile( 3656 void GDataFileSystem::OnMarkDirtyInCacheCompleteForOpenFile(
3658 const OpenFileCallback& callback, 3657 const OpenFileCallback& callback,
3659 GDataFileError error, 3658 GDataFileError error,
3660 const std::string& resource_id, 3659 const std::string& resource_id,
3661 const std::string& md5, 3660 const std::string& md5,
3662 const FilePath& cache_file_path) { 3661 const FilePath& cache_file_path) {
3663 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3662 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
(...skipping 16 matching lines...) Expand all
3680 3679
3681 if (!callback.is_null()) 3680 if (!callback.is_null())
3682 callback.Run(result, cache_file_path); 3681 callback.Run(result, cache_file_path);
3683 } 3682 }
3684 3683
3685 void GDataFileSystem::CloseFile(const FilePath& file_path, 3684 void GDataFileSystem::CloseFile(const FilePath& file_path,
3686 const FileOperationCallback& callback) { 3685 const FileOperationCallback& callback) {
3687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 3686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
3688 BrowserThread::CurrentlyOn(BrowserThread::IO)); 3687 BrowserThread::CurrentlyOn(BrowserThread::IO));
3689 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, 3688 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread,
3690 weak_ptr_factory_.GetWeakPtr(), 3689 ui_weak_ptr_,
3691 file_path, 3690 file_path,
3692 CreateRelayCallback(callback))); 3691 CreateRelayCallback(callback)));
3693 } 3692 }
3694 3693
3695 void GDataFileSystem::CloseFileOnUIThread( 3694 void GDataFileSystem::CloseFileOnUIThread(
3696 const FilePath& file_path, 3695 const FilePath& file_path,
3697 const FileOperationCallback& callback) { 3696 const FileOperationCallback& callback) {
3698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3699 3698
3700 if (open_files_.find(file_path) == open_files_.end()) { 3699 if (open_files_.find(file_path) == open_files_.end()) {
3701 // The file is not being opened. 3700 // The file is not being opened.
3702 MessageLoop::current()->PostTask( 3701 MessageLoop::current()->PostTask(
3703 FROM_HERE, 3702 FROM_HERE,
3704 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); 3703 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND));
3705 return; 3704 return;
3706 } 3705 }
3707 3706
3708 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. 3707 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|.
3709 GetEntryInfoByPathAsyncOnUIThread( 3708 GetEntryInfoByPathAsyncOnUIThread(
3710 file_path, 3709 file_path,
3711 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile, 3710 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile,
3712 weak_ptr_factory_.GetWeakPtr(), 3711 ui_weak_ptr_,
3713 file_path, 3712 file_path,
3714 base::Bind(&GDataFileSystem::OnCloseFileFinished, 3713 base::Bind(&GDataFileSystem::OnCloseFileFinished,
3715 weak_ptr_factory_.GetWeakPtr(), 3714 ui_weak_ptr_,
3716 file_path, 3715 file_path,
3717 callback))); 3716 callback)));
3718 } 3717 }
3719 3718
3720 void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile( 3719 void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile(
3721 const FilePath& file_path, 3720 const FilePath& file_path,
3722 const FileOperationCallback& callback, 3721 const FileOperationCallback& callback,
3723 GDataFileError error, 3722 GDataFileError error,
3724 scoped_ptr<GDataEntryProto> entry_proto) { 3723 scoped_ptr<GDataEntryProto> entry_proto) {
3725 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 3724 if (entry_proto.get() && !entry_proto->has_file_specific_info())
3726 error = GDATA_FILE_ERROR_NOT_FOUND; 3725 error = GDATA_FILE_ERROR_NOT_FOUND;
3727 3726
3728 if (error != GDATA_FILE_OK) { 3727 if (error != GDATA_FILE_OK) {
3729 if (!callback.is_null()) 3728 if (!callback.is_null())
3730 callback.Run(error); 3729 callback.Run(error);
3731 return; 3730 return;
3732 } 3731 }
3733 3732
3734 // Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must 3733 // Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must
3735 // always be called on paths opened by OpenFile, the file must be cached, 3734 // always be called on paths opened by OpenFile, the file must be cached,
3736 cache_->GetFileOnUIThread( 3735 cache_->GetFileOnUIThread(
3737 entry_proto->resource_id(), 3736 entry_proto->resource_id(),
3738 entry_proto->file_specific_info().file_md5(), 3737 entry_proto->file_specific_info().file_md5(),
3739 base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile, 3738 base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile,
3740 weak_ptr_factory_.GetWeakPtr(), 3739 ui_weak_ptr_,
3741 file_path, 3740 file_path,
3742 callback)); 3741 callback));
3743 } 3742 }
3744 3743
3745 void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile( 3744 void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile(
3746 const FilePath& file_path, 3745 const FilePath& file_path,
3747 const FileOperationCallback& callback, 3746 const FileOperationCallback& callback,
3748 GDataFileError error, 3747 GDataFileError error,
3749 const std::string& resource_id, 3748 const std::string& resource_id,
3750 const std::string& md5, 3749 const std::string& md5,
(...skipping 11 matching lines...) Expand all
3762 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; 3761 base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
3763 bool* get_file_info_result = new bool(false); 3762 bool* get_file_info_result = new bool(false);
3764 PostBlockingPoolSequencedTaskAndReply( 3763 PostBlockingPoolSequencedTaskAndReply(
3765 FROM_HERE, 3764 FROM_HERE,
3766 blocking_task_runner_, 3765 blocking_task_runner_,
3767 base::Bind(&GetFileInfoOnBlockingPool, 3766 base::Bind(&GetFileInfoOnBlockingPool,
3768 local_cache_path, 3767 local_cache_path,
3769 base::Unretained(file_info), 3768 base::Unretained(file_info),
3770 base::Unretained(get_file_info_result)), 3769 base::Unretained(get_file_info_result)),
3771 base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile, 3770 base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile,
3772 weak_ptr_factory_.GetWeakPtr(), 3771 ui_weak_ptr_,
3773 file_path, 3772 file_path,
3774 base::Owned(file_info), 3773 base::Owned(file_info),
3775 base::Owned(get_file_info_result), 3774 base::Owned(get_file_info_result),
3776 callback)); 3775 callback));
3777 } 3776 }
3778 3777
3779 void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile( 3778 void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile(
3780 const FilePath& file_path, 3779 const FilePath& file_path,
3781 base::PlatformFileInfo* file_info, 3780 base::PlatformFileInfo* file_info,
3782 bool* get_file_info_result, 3781 bool* get_file_info_result,
3783 const FileOperationCallback& callback) { 3782 const FileOperationCallback& callback) {
3784 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3783 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3785 3784
3786 if (!*get_file_info_result) { 3785 if (!*get_file_info_result) {
3787 if (!callback.is_null()) 3786 if (!callback.is_null())
3788 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); 3787 callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
3789 return; 3788 return;
3790 } 3789 }
3791 3790
3792 // Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for 3791 // Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for
3793 // modifying the entry's metadata. 3792 // modifying the entry's metadata.
3794 FindEntryByPathAsyncOnUIThread( 3793 FindEntryByPathAsyncOnUIThread(
3795 file_path, 3794 file_path,
3796 base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile, 3795 base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile,
3797 weak_ptr_factory_.GetWeakPtr(), 3796 ui_weak_ptr_,
3798 file_path, 3797 file_path,
3799 *file_info, 3798 *file_info,
3800 callback)); 3799 callback));
3801 } 3800 }
3802 3801
3803 void GDataFileSystem::OnGetEntryCompleteForCloseFile( 3802 void GDataFileSystem::OnGetEntryCompleteForCloseFile(
3804 const FilePath& file_path, 3803 const FilePath& file_path,
3805 const base::PlatformFileInfo& file_info, 3804 const base::PlatformFileInfo& file_info,
3806 const FileOperationCallback& callback, 3805 const FileOperationCallback& callback,
3807 GDataFileError error, 3806 GDataFileError error,
(...skipping 26 matching lines...) Expand all
3834 // Step 6 of CloseFile: Commit the modification in cache. This will trigger 3833 // Step 6 of CloseFile: Commit the modification in cache. This will trigger
3835 // background upload. 3834 // background upload.
3836 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache 3835 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache
3837 // if the file has not been modified. Come up with a way to detect the 3836 // if the file has not been modified. Come up with a way to detect the
3838 // intactness effectively, or provide a method for user to declare it when 3837 // intactness effectively, or provide a method for user to declare it when
3839 // calling CloseFile(). 3838 // calling CloseFile().
3840 cache_->CommitDirtyOnUIThread( 3839 cache_->CommitDirtyOnUIThread(
3841 file->resource_id(), 3840 file->resource_id(),
3842 file->file_md5(), 3841 file->file_md5(),
3843 base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile, 3842 base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile,
3844 weak_ptr_factory_.GetWeakPtr(), 3843 ui_weak_ptr_,
3845 callback)); 3844 callback));
3846 } 3845 }
3847 3846
3848 void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile( 3847 void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(
3849 const FileOperationCallback& callback, 3848 const FileOperationCallback& callback,
3850 GDataFileError error, 3849 GDataFileError error,
3851 const std::string& resource_id, 3850 const std::string& resource_id,
3852 const std::string& md5) { 3851 const std::string& md5) {
3853 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3852 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3854 3853
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3888 } 3887 }
3889 3888
3890 // Checks if the file is cached and modified locally. 3889 // Checks if the file is cached and modified locally.
3891 const std::string resource_id = entry_proto->resource_id(); 3890 const std::string resource_id = entry_proto->resource_id();
3892 const std::string md5 = entry_proto->file_specific_info().file_md5(); 3891 const std::string md5 = entry_proto->file_specific_info().file_md5();
3893 cache_->GetCacheEntryOnUIThread( 3892 cache_->GetCacheEntryOnUIThread(
3894 resource_id, 3893 resource_id,
3895 md5, 3894 md5,
3896 base::Bind( 3895 base::Bind(
3897 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, 3896 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry,
3898 weak_ptr_factory_.GetWeakPtr(), 3897 ui_weak_ptr_, base::Passed(&entry_proto), callback));
3899 base::Passed(&entry_proto),
3900 callback));
3901 } 3898 }
3902 3899
3903 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( 3900 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry(
3904 scoped_ptr<GDataEntryProto> entry_proto, 3901 scoped_ptr<GDataEntryProto> entry_proto,
3905 const GetEntryInfoCallback& callback, 3902 const GetEntryInfoCallback& callback,
3906 bool success, 3903 bool success,
3907 const GDataCacheEntry& cache_entry) { 3904 const GDataCacheEntry& cache_entry) {
3908 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3909 3906
3910 // When no dirty cache is found, use the original entry info as is. 3907 // When no dirty cache is found, use the original entry info as is.
3911 if (!success || !cache_entry.is_dirty()) { 3908 if (!success || !cache_entry.is_dirty()) {
3912 if (!callback.is_null()) 3909 if (!callback.is_null())
3913 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3910 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3914 return; 3911 return;
3915 } 3912 }
3916 3913
3917 // Gets the cache file path. 3914 // Gets the cache file path.
3918 const std::string& resource_id = entry_proto->resource_id(); 3915 const std::string& resource_id = entry_proto->resource_id();
3919 const std::string& md5 = entry_proto->file_specific_info().file_md5(); 3916 const std::string& md5 = entry_proto->file_specific_info().file_md5();
3920 cache_->GetFileOnUIThread( 3917 cache_->GetFileOnUIThread(
3921 resource_id, 3918 resource_id,
3922 md5, 3919 md5,
3923 base::Bind( 3920 base::Bind(
3924 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, 3921 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile,
3925 weak_ptr_factory_.GetWeakPtr(), 3922 ui_weak_ptr_, base::Passed(&entry_proto), callback));
3926 base::Passed(&entry_proto),
3927 callback));
3928 } 3923 }
3929 3924
3930 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( 3925 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile(
3931 scoped_ptr<GDataEntryProto> entry_proto, 3926 scoped_ptr<GDataEntryProto> entry_proto,
3932 const GetEntryInfoCallback& callback, 3927 const GetEntryInfoCallback& callback,
3933 GDataFileError error, 3928 GDataFileError error,
3934 const std::string& resource_id, 3929 const std::string& resource_id,
3935 const std::string& md5, 3930 const std::string& md5,
3936 const FilePath& local_cache_path) { 3931 const FilePath& local_cache_path) {
3937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3932 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3938 3933
3939 // When no dirty cache is found, use the original entry info as is. 3934 // When no dirty cache is found, use the original entry info as is.
3940 if (error != GDATA_FILE_OK) { 3935 if (error != GDATA_FILE_OK) {
3941 if (!callback.is_null()) 3936 if (!callback.is_null())
3942 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3937 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3943 return; 3938 return;
3944 } 3939 }
3945 3940
3946 // If the cache is dirty, obtain the file info from the cache file itself. 3941 // If the cache is dirty, obtain the file info from the cache file itself.
3947 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; 3942 base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
3948 bool* get_file_info_result = new bool(false); 3943 bool* get_file_info_result = new bool(false);
3949 PostBlockingPoolSequencedTaskAndReply( 3944 PostBlockingPoolSequencedTaskAndReply(
3950 FROM_HERE, 3945 FROM_HERE,
3951 blocking_task_runner_, 3946 blocking_task_runner_,
3952 base::Bind(&GetFileInfoOnBlockingPool, 3947 base::Bind(&GetFileInfoOnBlockingPool,
3953 local_cache_path, 3948 local_cache_path,
3954 base::Unretained(file_info), 3949 base::Unretained(file_info),
3955 base::Unretained(get_file_info_result)), 3950 base::Unretained(get_file_info_result)),
3956 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, 3951 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo,
3957 weak_ptr_factory_.GetWeakPtr(), 3952 ui_weak_ptr_,
3958 base::Passed(&entry_proto), 3953 base::Passed(&entry_proto),
3959 callback, 3954 callback,
3960 base::Owned(file_info), 3955 base::Owned(file_info),
3961 base::Owned(get_file_info_result))); 3956 base::Owned(get_file_info_result)));
3962 } 3957 }
3963 3958
3964 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( 3959 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo(
3965 scoped_ptr<GDataEntryProto> entry_proto, 3960 scoped_ptr<GDataEntryProto> entry_proto,
3966 const GetEntryInfoCallback& callback, 3961 const GetEntryInfoCallback& callback,
3967 base::PlatformFileInfo* file_info, 3962 base::PlatformFileInfo* file_info,
3968 bool* get_file_info_result) { 3963 bool* get_file_info_result) {
3969 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3964 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3970 3965
3971 if (!*get_file_info_result) { 3966 if (!*get_file_info_result) {
3972 if (!callback.is_null()) 3967 if (!callback.is_null())
3973 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>()); 3968 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>());
3974 return; 3969 return;
3975 } 3970 }
3976 3971
3977 PlatformFileInfoProto entry_file_info; 3972 PlatformFileInfoProto entry_file_info;
3978 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3973 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3979 *entry_proto->mutable_file_info() = entry_file_info; 3974 *entry_proto->mutable_file_info() = entry_file_info;
3980 if (!callback.is_null()) 3975 if (!callback.is_null())
3981 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3976 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3982 } 3977 }
3983 3978
3984 } // namespace gdata 3979 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_operation_runner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698