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