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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
598 base::SequencedTaskRunner* blocking_task_runner, | 598 base::SequencedTaskRunner* blocking_task_runner, |
599 const base::Closure& request_task, | 599 const base::Closure& request_task, |
600 const base::Closure& reply_task) { | 600 const base::Closure& reply_task) { |
601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
602 | 602 |
603 const bool posted = blocking_task_runner->PostTaskAndReply( | 603 const bool posted = blocking_task_runner->PostTaskAndReply( |
604 from_here, request_task, reply_task); | 604 from_here, request_task, reply_task); |
605 DCHECK(posted); | 605 DCHECK(posted); |
606 } | 606 } |
607 | 607 |
608 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and | |
609 // create GetEntryInfoCallback. | |
610 void RunGetEntryInfoWithFilePathCallback( | |
611 const GetEntryInfoWithFilePathCallback& callback, | |
612 const FilePath& path, | |
613 GDataFileError error, | |
614 scoped_ptr<GDataEntryProto> entry_proto) { | |
615 if (!callback.is_null()) | |
616 callback.Run(error, path, entry_proto.Pass()); | |
617 } | |
618 | |
608 } // namespace | 619 } // namespace |
609 | 620 |
610 // GDataFileSystem::GetDocumentsParams struct implementation. | 621 // GDataFileSystem::GetDocumentsParams struct implementation. |
611 struct GDataFileSystem::GetDocumentsParams { | 622 struct GDataFileSystem::GetDocumentsParams { |
612 GetDocumentsParams(int start_changestamp, | 623 GetDocumentsParams(int start_changestamp, |
613 int root_feed_changestamp, | 624 int root_feed_changestamp, |
614 std::vector<DocumentFeed*>* feed_list, | 625 std::vector<DocumentFeed*>* feed_list, |
615 bool should_fetch_multiple_feeds, | 626 bool should_fetch_multiple_feeds, |
616 const FilePath& search_file_path, | 627 const FilePath& search_file_path, |
617 const std::string& search_query, | 628 const std::string& search_query, |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
900 } | 911 } |
901 | 912 |
902 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( | 913 void GDataFileSystem::GetEntryInfoByEntryOnUIThread( |
903 const GetEntryInfoWithFilePathCallback& callback, | 914 const GetEntryInfoWithFilePathCallback& callback, |
904 GDataEntry* entry) { | 915 GDataEntry* entry) { |
905 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 916 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
906 | 917 |
907 if (entry) { | 918 if (entry) { |
908 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); | 919 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); |
909 entry->ToProtoFull(entry_proto.get()); | 920 entry->ToProtoFull(entry_proto.get()); |
910 callback.Run(GDATA_FILE_OK, entry->GetFilePath(), entry_proto.Pass()); | 921 CheckLocalModificationAndRun( |
922 entry_proto.Pass(), | |
923 base::Bind(&RunGetEntryInfoWithFilePathCallback, | |
924 callback, entry->GetFilePath())); | |
911 } else { | 925 } else { |
912 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, | 926 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, |
913 FilePath(), | 927 FilePath(), |
914 scoped_ptr<GDataEntryProto>()); | 928 scoped_ptr<GDataEntryProto>()); |
915 } | 929 } |
916 } | 930 } |
917 | 931 |
918 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( | 932 void GDataFileSystem::FindEntryByPathAsyncOnUIThread( |
919 const FilePath& search_file_path, | 933 const FilePath& search_file_path, |
920 const FindEntryCallback& callback) { | 934 const FindEntryCallback& callback) { |
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2254 if (error != GDATA_FILE_OK) { | 2268 if (error != GDATA_FILE_OK) { |
2255 if (!callback.is_null()) | 2269 if (!callback.is_null()) |
2256 callback.Run(error, scoped_ptr<GDataEntryProto>()); | 2270 callback.Run(error, scoped_ptr<GDataEntryProto>()); |
2257 return; | 2271 return; |
2258 } | 2272 } |
2259 DCHECK(entry); | 2273 DCHECK(entry); |
2260 | 2274 |
2261 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); | 2275 scoped_ptr<GDataEntryProto> entry_proto(new GDataEntryProto); |
2262 entry->ToProtoFull(entry_proto.get()); | 2276 entry->ToProtoFull(entry_proto.get()); |
2263 | 2277 |
2264 if (!callback.is_null()) | 2278 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
2265 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | |
2266 } | 2279 } |
2267 | 2280 |
2268 void GDataFileSystem::ReadDirectoryByPath( | 2281 void GDataFileSystem::ReadDirectoryByPath( |
2269 const FilePath& file_path, | 2282 const FilePath& file_path, |
2270 const ReadDirectoryCallback& callback) { | 2283 const ReadDirectoryCallback& callback) { |
2271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2272 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2285 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2273 RunTaskOnUIThread( | 2286 RunTaskOnUIThread( |
2274 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, | 2287 base::Bind(&GDataFileSystem::ReadDirectoryByPathAsyncOnUIThread, |
2275 ui_weak_ptr_, | 2288 ui_weak_ptr_, |
(...skipping 1885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4161 // All the invocation of |callback| from operations initiated from CloseFile | 4174 // All the invocation of |callback| from operations initiated from CloseFile |
4162 // must go through here. Removes the |file_path| from the remembered set so | 4175 // must go through here. Removes the |file_path| from the remembered set so |
4163 // that subsequent operations can open the file again. | 4176 // that subsequent operations can open the file again. |
4164 open_files_.erase(file_path); | 4177 open_files_.erase(file_path); |
4165 | 4178 |
4166 // Then invokes the user-supplied callback function. | 4179 // Then invokes the user-supplied callback function. |
4167 if (!callback.is_null()) | 4180 if (!callback.is_null()) |
4168 callback.Run(result); | 4181 callback.Run(result); |
4169 } | 4182 } |
4170 | 4183 |
4184 void GDataFileSystem::CheckLocalModificationAndRun( | |
4185 scoped_ptr<GDataEntryProto> entry_proto, | |
4186 const GetEntryInfoCallback& callback) { | |
4187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
4188 DCHECK(entry_proto.get()); | |
4189 | |
4190 // For entries that will never be cached, use the original entry info as is. | |
4191 if (!entry_proto->has_file_specific_info() || | |
4192 entry_proto->file_specific_info().is_hosted_document()) { | |
4193 if (!callback.is_null()) | |
4194 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | |
4195 return; | |
4196 } | |
4197 | |
4198 // Checks if the file is cached and modified locally. | |
4199 const std::string resource_id = entry_proto->resource_id(); | |
4200 const std::string md5 = entry_proto->file_specific_info().file_md5(); | |
4201 cache_->GetCacheEntryOnUIThread( | |
4202 resource_id, | |
4203 md5, | |
4204 base::Bind(&GDataFileSystem::ReflectLocalModificationAfterGetCacheEntry, | |
satorux1
2012/07/26 12:08:14
CheckLocalModificationAndRunAfterGetCacheEntry? be
kinaba
2012/07/27 01:47:44
Done.
| |
4205 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | |
4206 } | |
4207 | |
4208 void GDataFileSystem::ReflectLocalModificationAfterGetCacheEntry( | |
4209 scoped_ptr<GDataEntryProto> entry_proto, | |
4210 const GetEntryInfoCallback& callback, | |
4211 bool success, | |
4212 const GDataCacheEntry& cache_entry) { | |
4213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
4214 | |
4215 // When no dirty cache is found, use the original entry info as is. | |
4216 if (!success || !cache_entry.is_dirty()) { | |
4217 if (!callback.is_null()) | |
4218 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | |
4219 return; | |
4220 } | |
4221 | |
4222 // Gets the cache file path. | |
4223 const std::string& resource_id = entry_proto->resource_id(); | |
4224 const std::string& md5 = entry_proto->file_specific_info().file_md5(); | |
4225 cache_->GetFileOnUIThread( | |
4226 resource_id, | |
4227 md5, | |
4228 base::Bind(&GDataFileSystem::ReflectLocalModificationAfterGetCacheFile, | |
4229 ui_weak_ptr_, base::Passed(&entry_proto), callback)); | |
4230 } | |
4231 | |
4232 void GDataFileSystem::ReflectLocalModificationAfterGetCacheFile( | |
satorux1
2012/07/26 12:08:14
ditto
kinaba
2012/07/27 01:47:44
Done.
| |
4233 scoped_ptr<GDataEntryProto> entry_proto, | |
4234 const GetEntryInfoCallback& callback, | |
4235 GDataFileError error, | |
4236 const std::string& resource_id, | |
4237 const std::string& md5, | |
4238 const FilePath& local_cache_path) { | |
4239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
4240 | |
4241 // When no dirty cache is found, use the original entry info as is. | |
4242 if (error != GDATA_FILE_OK) { | |
4243 if (!callback.is_null()) | |
4244 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | |
4245 return; | |
4246 } | |
4247 | |
4248 // If the cache is dirty, obtain the file info from the cache file itself. | |
4249 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | |
4250 bool* get_file_info_result = new bool(false); | |
4251 PostBlockingPoolSequencedTaskAndReply( | |
4252 FROM_HERE, | |
4253 blocking_task_runner_, | |
4254 base::Bind(&GetFileInfoOnBlockingPool, | |
4255 local_cache_path, | |
4256 base::Unretained(file_info), | |
4257 base::Unretained(get_file_info_result)), | |
4258 base::Bind(&GDataFileSystem::ReflectLocalModificationAfterGetFileInfo, | |
4259 ui_weak_ptr_, | |
4260 base::Passed(&entry_proto), | |
4261 callback, | |
4262 base::Owned(file_info), | |
4263 base::Owned(get_file_info_result))); | |
4264 } | |
4265 | |
4266 void GDataFileSystem::ReflectLocalModificationAfterGetFileInfo( | |
satorux1
2012/07/26 12:08:14
ditto
kinaba
2012/07/27 01:47:44
Done.
| |
4267 scoped_ptr<GDataEntryProto> entry_proto, | |
4268 const GetEntryInfoCallback& callback, | |
4269 base::PlatformFileInfo* file_info, | |
4270 bool* get_file_info_result) { | |
4271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
4272 | |
4273 if (!*get_file_info_result) { | |
4274 if (!callback.is_null()) | |
4275 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>()); | |
4276 return; | |
4277 } | |
4278 | |
4279 PlatformFileInfoProto entry_file_info; | |
4280 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | |
4281 *entry_proto->mutable_file_info() = entry_file_info; | |
4282 if (!callback.is_null()) | |
4283 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | |
4284 } | |
4285 | |
4171 } // namespace gdata | 4286 } // namespace gdata |
OLD | NEW |