Chromium Code Reviews| 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 70 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = | 70 const FilePath::CharType kGDataCacheTmpDownloadsDir[] = |
| 71 FILE_PATH_LITERAL("tmp/downloads"); | 71 FILE_PATH_LITERAL("tmp/downloads"); |
| 72 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = | 72 const FilePath::CharType kGDataCacheTmpDocumentsDir[] = |
| 73 FILE_PATH_LITERAL("tmp/documents"); | 73 FILE_PATH_LITERAL("tmp/documents"); |
| 74 const FilePath::CharType kAccountMetadataFile[] = | 74 const FilePath::CharType kAccountMetadataFile[] = |
| 75 FILE_PATH_LITERAL("account_metadata.json"); | 75 FILE_PATH_LITERAL("account_metadata.json"); |
| 76 const FilePath::CharType kFilesystemProtoFile[] = | 76 const FilePath::CharType kFilesystemProtoFile[] = |
| 77 FILE_PATH_LITERAL("file_system.pb"); | 77 FILE_PATH_LITERAL("file_system.pb"); |
| 78 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); | 78 const FilePath::CharType kSymLinkToDevNull[] = FILE_PATH_LITERAL("/dev/null"); |
| 79 | 79 |
| 80 // GData update check interval (in seconds). | |
| 81 #ifndef NDEBUG | |
| 82 const int kGDataUpdateCheckIntervalInSec = 5; | |
| 83 #else | |
| 84 const int kGDataUpdateCheckIntervalInSec = 60; | |
| 85 #endif | |
| 86 | |
| 80 // Schedule for dumping root file system proto buffers to disk depending its | 87 // Schedule for dumping root file system proto buffers to disk depending its |
| 81 // total protobuffer size in MB. | 88 // total protobuffer size in MB. |
| 82 typedef struct { | 89 typedef struct { |
| 83 double size; | 90 double size; |
| 84 int timeout; | 91 int timeout; |
| 85 } SerializationTimetable; | 92 } SerializationTimetable; |
| 86 | 93 |
| 87 SerializationTimetable kSerializeTimetable[] = { | 94 SerializationTimetable kSerializeTimetable[] = { |
| 88 #ifndef NDEBUG | 95 #ifndef NDEBUG |
| 89 {0.5, 0}, // Less than 0.5MB, dump immediately. | 96 {0.5, 0}, // Less than 0.5MB, dump immediately. |
| (...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 921 // GDataFileSystem class implementatsion. | 928 // GDataFileSystem class implementatsion. |
| 922 | 929 |
| 923 GDataFileSystem::GDataFileSystem(Profile* profile, | 930 GDataFileSystem::GDataFileSystem(Profile* profile, |
| 924 DocumentsServiceInterface* documents_service) | 931 DocumentsServiceInterface* documents_service) |
| 925 : profile_(profile), | 932 : profile_(profile), |
| 926 documents_service_(documents_service), | 933 documents_service_(documents_service), |
| 927 on_io_completed_(new base::WaitableEvent( | 934 on_io_completed_(new base::WaitableEvent( |
| 928 true /* manual reset */, true /* initially signaled */)), | 935 true /* manual reset */, true /* initially signaled */)), |
| 929 cache_initialization_started_(false), | 936 cache_initialization_started_(false), |
| 930 num_pending_tasks_(0), | 937 num_pending_tasks_(0), |
| 938 update_timer_(true /* retain_user_task */, true /* is_repeating */), | |
| 931 hide_hosted_docs_(false), | 939 hide_hosted_docs_(false), |
| 932 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( | 940 ui_weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST( |
| 933 new base::WeakPtrFactory<GDataFileSystem>(this))), | 941 new base::WeakPtrFactory<GDataFileSystem>(this))), |
| 934 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()), | 942 ui_weak_ptr_(ui_weak_ptr_factory_->GetWeakPtr()), |
| 935 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()) { | 943 sequence_token_(BrowserThread::GetBlockingPool()->GetSequenceToken()) { |
| 936 // Should be created from the file browser extension API on UI thread. | 944 // Should be created from the file browser extension API on UI thread. |
| 937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 938 } | 946 } |
| 939 | 947 |
| 940 void GDataFileSystem::Initialize() { | 948 void GDataFileSystem::Initialize() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 954 documents_service_->Initialize(profile_); | 962 documents_service_->Initialize(profile_); |
| 955 | 963 |
| 956 root_.reset(new GDataRootDirectory); | 964 root_.reset(new GDataRootDirectory); |
| 957 | 965 |
| 958 PrefService* pref_service = profile_->GetPrefs(); | 966 PrefService* pref_service = profile_->GetPrefs(); |
| 959 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); | 967 hide_hosted_docs_ = pref_service->GetBoolean(prefs::kDisableGDataHostedFiles); |
| 960 | 968 |
| 961 InitializePreferenceObserver(); | 969 InitializePreferenceObserver(); |
| 962 } | 970 } |
| 963 | 971 |
| 972 void GDataFileSystem::CheckForUpdates() { | |
| 973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 974 ContentOrigin initial_origin = root_->origin(); | |
| 975 if (initial_origin == FROM_SERVER) { | |
| 976 root_->set_origin(REFRESHING); | |
| 977 ReloadFeedFromServerIfNeeded(initial_origin, | |
| 978 root_->largest_changestamp(), | |
| 979 root_->GetFilePath(), | |
| 980 gdata::FindEntryCallback()); | |
| 981 } | |
| 982 } | |
| 983 | |
| 964 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { | 984 bool GDataFileSystem::SetCacheRootPathForTesting(const FilePath& root_path) { |
| 965 if (cache_initialization_started_) | 985 if (cache_initialization_started_) |
| 966 return false; | 986 return false; |
| 967 cache_paths_.clear(); | 987 cache_paths_.clear(); |
| 968 SetCachePaths(root_path); | 988 SetCachePaths(root_path); |
| 969 return true; | 989 return true; |
| 970 } | 990 } |
| 971 | 991 |
| 972 GDataFileSystem::~GDataFileSystem() { | 992 GDataFileSystem::~GDataFileSystem() { |
| 973 // This should be called from UI thread, from GDataSystemService shutdown. | 993 // This should be called from UI thread, from GDataSystemService shutdown. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1009 } | 1029 } |
| 1010 | 1030 |
| 1011 void GDataFileSystem::AddObserver(Observer* observer) { | 1031 void GDataFileSystem::AddObserver(Observer* observer) { |
| 1012 observers_.AddObserver(observer); | 1032 observers_.AddObserver(observer); |
| 1013 } | 1033 } |
| 1014 | 1034 |
| 1015 void GDataFileSystem::RemoveObserver(Observer* observer) { | 1035 void GDataFileSystem::RemoveObserver(Observer* observer) { |
| 1016 observers_.RemoveObserver(observer); | 1036 observers_.RemoveObserver(observer); |
| 1017 } | 1037 } |
| 1018 | 1038 |
| 1039 void GDataFileSystem::StartUpdates() { | |
| 1040 update_timer_.Start(FROM_HERE, | |
|
zel
2012/05/03 21:40:41
you should DCHECK to make sure we are not calling
hshi
2012/05/03 21:45:01
Done.
| |
| 1041 base::TimeDelta::FromSeconds( | |
| 1042 kGDataUpdateCheckIntervalInSec), | |
| 1043 base::Bind(&GDataFileSystem::CheckForUpdates, | |
| 1044 ui_weak_ptr_)); | |
| 1045 } | |
| 1046 | |
| 1047 void GDataFileSystem::StopUpdates() { | |
| 1048 update_timer_.Stop(); | |
| 1049 } | |
| 1050 | |
| 1019 void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) { | 1051 void GDataFileSystem::Authenticate(const AuthStatusCallback& callback) { |
| 1020 // TokenFetcher, used in DocumentsService, must be run on UI thread. | 1052 // TokenFetcher, used in DocumentsService, must be run on UI thread. |
| 1021 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1053 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1022 | 1054 |
| 1023 documents_service_->Authenticate(callback); | 1055 documents_service_->Authenticate(callback); |
| 1024 } | 1056 } |
| 1025 | 1057 |
| 1026 void GDataFileSystem::FindEntryByResourceIdSync( | 1058 void GDataFileSystem::FindEntryByResourceIdSync( |
| 1027 const std::string& resource_id, | 1059 const std::string& resource_id, |
| 1028 FindEntryDelegate* delegate) { | 1060 FindEntryDelegate* delegate) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1059 callback))); | 1091 callback))); |
| 1060 return; | 1092 return; |
| 1061 } else if (root_->origin() == UNINITIALIZED) { | 1093 } else if (root_->origin() == UNINITIALIZED) { |
| 1062 // Load root feed from this disk cache. Upon completion, kick off server | 1094 // Load root feed from this disk cache. Upon completion, kick off server |
| 1063 // fetching. | 1095 // fetching. |
| 1064 root_->set_origin(INITIALIZING); | 1096 root_->set_origin(INITIALIZING); |
| 1065 LoadRootFeedFromCache(true, // should_load_from_server | 1097 LoadRootFeedFromCache(true, // should_load_from_server |
| 1066 search_file_path, | 1098 search_file_path, |
| 1067 callback); | 1099 callback); |
| 1068 return; | 1100 return; |
| 1069 } else if (root_->NeedsRefresh()) { | |
| 1070 // If content is stale or from disk from cache, fetch content from | |
| 1071 // the server. | |
| 1072 ContentOrigin initial_origin = root_->origin(); | |
| 1073 root_->set_origin(REFRESHING); | |
| 1074 ReloadFeedFromServerIfNeeded(initial_origin, | |
| 1075 root_->largest_changestamp(), | |
| 1076 search_file_path, | |
| 1077 callback); | |
| 1078 return; | |
| 1079 } | 1101 } |
| 1080 | 1102 |
| 1081 // Post a task to the same thread, rather than calling it here, as | 1103 // Post a task to the same thread, rather than calling it here, as |
| 1082 // FindEntryByPathAsync() is asynchronous. | 1104 // FindEntryByPathAsync() is asynchronous. |
| 1083 base::MessageLoopProxy::current()->PostTask( | 1105 base::MessageLoopProxy::current()->PostTask( |
| 1084 FROM_HERE, | 1106 FROM_HERE, |
| 1085 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, | 1107 base::Bind(&GDataFileSystem::FindEntryByPathSyncOnUIThread, |
| 1086 ui_weak_ptr_, | 1108 ui_weak_ptr_, |
| 1087 search_file_path, | 1109 search_file_path, |
| 1088 callback)); | 1110 callback)); |
| (...skipping 3682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4771 pref_registrar_->Init(profile_->GetPrefs()); | 4793 pref_registrar_->Init(profile_->GetPrefs()); |
| 4772 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 4794 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
| 4773 } | 4795 } |
| 4774 | 4796 |
| 4775 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 4797 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 4776 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 4798 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 4777 global_free_disk_getter_for_testing = getter; | 4799 global_free_disk_getter_for_testing = getter; |
| 4778 } | 4800 } |
| 4779 | 4801 |
| 4780 } // namespace gdata | 4802 } // namespace gdata |
| OLD | NEW |