| 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( |
| 4205 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry, |
| 4206 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
| 4207 } |
| 4208 |
| 4209 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheEntry( |
| 4210 scoped_ptr<GDataEntryProto> entry_proto, |
| 4211 const GetEntryInfoCallback& callback, |
| 4212 bool success, |
| 4213 const GDataCacheEntry& cache_entry) { |
| 4214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 4215 |
| 4216 // When no dirty cache is found, use the original entry info as is. |
| 4217 if (!success || !cache_entry.is_dirty()) { |
| 4218 if (!callback.is_null()) |
| 4219 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 4220 return; |
| 4221 } |
| 4222 |
| 4223 // Gets the cache file path. |
| 4224 const std::string& resource_id = entry_proto->resource_id(); |
| 4225 const std::string& md5 = entry_proto->file_specific_info().file_md5(); |
| 4226 cache_->GetFileOnUIThread( |
| 4227 resource_id, |
| 4228 md5, |
| 4229 base::Bind( |
| 4230 &GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile, |
| 4231 ui_weak_ptr_, base::Passed(&entry_proto), callback)); |
| 4232 } |
| 4233 |
| 4234 void GDataFileSystem::CheckLocalModificationAndRunAfterGetCacheFile( |
| 4235 scoped_ptr<GDataEntryProto> entry_proto, |
| 4236 const GetEntryInfoCallback& callback, |
| 4237 GDataFileError error, |
| 4238 const std::string& resource_id, |
| 4239 const std::string& md5, |
| 4240 const FilePath& local_cache_path) { |
| 4241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 4242 |
| 4243 // When no dirty cache is found, use the original entry info as is. |
| 4244 if (error != GDATA_FILE_OK) { |
| 4245 if (!callback.is_null()) |
| 4246 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 4247 return; |
| 4248 } |
| 4249 |
| 4250 // If the cache is dirty, obtain the file info from the cache file itself. |
| 4251 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; |
| 4252 bool* get_file_info_result = new bool(false); |
| 4253 PostBlockingPoolSequencedTaskAndReply( |
| 4254 FROM_HERE, |
| 4255 blocking_task_runner_, |
| 4256 base::Bind(&GetFileInfoOnBlockingPool, |
| 4257 local_cache_path, |
| 4258 base::Unretained(file_info), |
| 4259 base::Unretained(get_file_info_result)), |
| 4260 base::Bind(&GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, |
| 4261 ui_weak_ptr_, |
| 4262 base::Passed(&entry_proto), |
| 4263 callback, |
| 4264 base::Owned(file_info), |
| 4265 base::Owned(get_file_info_result))); |
| 4266 } |
| 4267 |
| 4268 void GDataFileSystem::CheckLocalModificationAndRunAfterGetFileInfo( |
| 4269 scoped_ptr<GDataEntryProto> entry_proto, |
| 4270 const GetEntryInfoCallback& callback, |
| 4271 base::PlatformFileInfo* file_info, |
| 4272 bool* get_file_info_result) { |
| 4273 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 4274 |
| 4275 if (!*get_file_info_result) { |
| 4276 if (!callback.is_null()) |
| 4277 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, scoped_ptr<GDataEntryProto>()); |
| 4278 return; |
| 4279 } |
| 4280 |
| 4281 PlatformFileInfoProto entry_file_info; |
| 4282 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 4283 *entry_proto->mutable_file_info() = entry_file_info; |
| 4284 if (!callback.is_null()) |
| 4285 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 4286 } |
| 4287 |
| 4171 } // namespace gdata | 4288 } // namespace gdata |
| OLD | NEW |