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 <set> | 7 #include <set> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 3211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3222 // The file is not being opened. | 3222 // The file is not being opened. |
| 3223 MessageLoop::current()->PostTask( | 3223 MessageLoop::current()->PostTask( |
| 3224 FROM_HERE, | 3224 FROM_HERE, |
| 3225 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); | 3225 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); |
| 3226 return; | 3226 return; |
| 3227 } | 3227 } |
| 3228 | 3228 |
| 3229 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. | 3229 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. |
| 3230 directory_service_->GetEntryInfoByPath( | 3230 directory_service_->GetEntryInfoByPath( |
| 3231 file_path, | 3231 file_path, |
| 3232 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile, | 3232 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo, |
| 3233 ui_weak_ptr_, | 3233 ui_weak_ptr_, |
| 3234 file_path, | 3234 file_path, |
| 3235 base::Bind(&GDataFileSystem::OnCloseFileFinished, | 3235 base::Bind(&GDataFileSystem::CloseFileOnUIThreadFinalize, |
| 3236 ui_weak_ptr_, | 3236 ui_weak_ptr_, |
| 3237 file_path, | 3237 file_path, |
| 3238 callback))); | 3238 callback))); |
| 3239 } | 3239 } |
| 3240 | 3240 |
| 3241 void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile( | 3241 void GDataFileSystem::CloseFileOnUIThreadAfterGetEntryInfo( |
| 3242 const FilePath& file_path, | 3242 const FilePath& file_path, |
| 3243 const FileOperationCallback& callback, | 3243 const FileOperationCallback& callback, |
| 3244 GDataFileError error, | 3244 GDataFileError error, |
| 3245 scoped_ptr<GDataEntryProto> entry_proto) { | 3245 scoped_ptr<GDataEntryProto> entry_proto) { |
| 3246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3247 DCHECK(!callback.is_null()); | 3247 DCHECK(!callback.is_null()); |
| 3248 | 3248 |
| 3249 if (entry_proto.get() && !entry_proto->has_file_specific_info()) | 3249 if (entry_proto.get() && !entry_proto->has_file_specific_info()) |
| 3250 error = GDATA_FILE_ERROR_NOT_FOUND; | 3250 error = GDATA_FILE_ERROR_NOT_FOUND; |
| 3251 | 3251 |
| 3252 if (error != GDATA_FILE_OK) { | 3252 if (error != GDATA_FILE_OK) { |
| 3253 callback.Run(error); | 3253 callback.Run(error); |
| 3254 return; | 3254 return; |
| 3255 } | 3255 } |
| 3256 | 3256 |
| 3257 // Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must | 3257 // Step 2 of CloseFile: Commit the modification in cache. This will trigger |
| 3258 // always be called on paths opened by OpenFile, the file must be cached, | |
| 3259 cache_->GetFileOnUIThread( | |
| 3260 entry_proto->resource_id(), | |
| 3261 entry_proto->file_specific_info().file_md5(), | |
| 3262 base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile, | |
| 3263 ui_weak_ptr_, | |
| 3264 file_path, | |
| 3265 callback)); | |
| 3266 } | |
| 3267 | |
| 3268 void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile( | |
| 3269 const FilePath& file_path, | |
| 3270 const FileOperationCallback& callback, | |
| 3271 GDataFileError error, | |
| 3272 const std::string& resource_id, | |
| 3273 const std::string& md5, | |
| 3274 const FilePath& local_cache_path) { | |
| 3275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3276 DCHECK(!callback.is_null()); | |
| 3277 | |
| 3278 if (error != GDATA_FILE_OK) { | |
| 3279 callback.Run(error); | |
| 3280 return; | |
| 3281 } | |
| 3282 | |
| 3283 // Step 3 of CloseFile: Retrieves the (possibly modified) PlatformFileInfo of | |
| 3284 // the cache file. | |
| 3285 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | |
| 3286 bool* get_file_info_result = new bool(false); | |
| 3287 util::PostBlockingPoolSequencedTaskAndReply( | |
| 3288 FROM_HERE, | |
| 3289 blocking_task_runner_, | |
| 3290 base::Bind(&GetFileInfoOnBlockingPool, | |
| 3291 local_cache_path, | |
| 3292 base::Unretained(file_info), | |
| 3293 base::Unretained(get_file_info_result)), | |
| 3294 base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile, | |
| 3295 ui_weak_ptr_, | |
| 3296 file_path, | |
| 3297 base::Owned(file_info), | |
| 3298 base::Owned(get_file_info_result), | |
| 3299 callback)); | |
| 3300 } | |
| 3301 | |
| 3302 void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile( | |
| 3303 const FilePath& file_path, | |
| 3304 base::PlatformFileInfo* file_info, | |
| 3305 bool* get_file_info_result, | |
| 3306 const FileOperationCallback& callback) { | |
| 3307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3308 DCHECK(!callback.is_null()); | |
| 3309 | |
| 3310 if (!*get_file_info_result) { | |
| 3311 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); | |
| 3312 return; | |
| 3313 } | |
| 3314 | |
| 3315 // Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for | |
| 3316 // modifying the entry's metadata. | |
| 3317 FindEntryByPathAsyncOnUIThread( | |
| 3318 file_path, | |
| 3319 base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile, | |
| 3320 ui_weak_ptr_, | |
| 3321 *file_info, | |
| 3322 callback)); | |
| 3323 } | |
| 3324 | |
| 3325 void GDataFileSystem::OnGetEntryCompleteForCloseFile( | |
| 3326 const base::PlatformFileInfo& file_info, | |
| 3327 const FileOperationCallback& callback, | |
| 3328 GDataFileError error, | |
| 3329 GDataEntry* entry) { | |
| 3330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 3331 DCHECK(!callback.is_null()); | |
| 3332 | |
| 3333 if (error != GDATA_FILE_OK) { | |
| 3334 callback.Run(error); | |
| 3335 return; | |
| 3336 } | |
| 3337 | |
| 3338 DCHECK(entry); | |
| 3339 GDataFile* file = entry->AsGDataFile(); | |
| 3340 if (!file || file->file_md5().empty() || file->is_hosted_document()) { | |
| 3341 // No support for opening a directory or hosted document. | |
| 3342 callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION); | |
| 3343 return; | |
| 3344 } | |
| 3345 DCHECK(!file->resource_id().empty()); | |
| 3346 | |
| 3347 // Step 5 of CloseFile: | |
| 3348 // Update the in-memory meta data. Until the committed cache is uploaded in | |
| 3349 // background to the server and the change is propagated back, this in-memory | |
| 3350 // meta data is referred by subsequent file operations. So it needs to reflect | |
| 3351 // the modification made before committing. | |
| 3352 file->set_file_info(file_info); | |
| 3353 | |
| 3354 // Step 6 of CloseFile: Commit the modification in cache. This will trigger | |
| 3355 // background upload. | 3258 // background upload. |
| 3356 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache | 3259 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache |
| 3357 // if the file has not been modified. Come up with a way to detect the | 3260 // if the file has not been modified. Come up with a way to detect the |
| 3358 // intactness effectively, or provide a method for user to declare it when | 3261 // intactness effectively, or provide a method for user to declare it when |
| 3359 // calling CloseFile(). | 3262 // calling CloseFile(). |
| 3360 cache_->CommitDirtyOnUIThread( | 3263 cache_->CommitDirtyOnUIThread( |
| 3361 file->resource_id(), | 3264 entry_proto->resource_id(), |
| 3362 file->file_md5(), | 3265 entry_proto->file_specific_info().file_md5(), |
| 3363 base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile, | 3266 base::Bind(&GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache, |
| 3364 ui_weak_ptr_, | 3267 ui_weak_ptr_, |
| 3365 callback)); | 3268 callback)); |
| 3366 } | 3269 } |
| 3367 | 3270 |
| 3368 void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile( | 3271 void GDataFileSystem::CloseFileOnUIThreadAfterCommitDirtyInCache( |
| 3369 const FileOperationCallback& callback, | 3272 const FileOperationCallback& callback, |
| 3370 GDataFileError error, | 3273 GDataFileError error, |
| 3371 const std::string& /* resource_id */, | 3274 const std::string& /* resource_id */, |
| 3372 const std::string& /* md5 */) { | 3275 const std::string& /* md5 */) { |
| 3373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3374 DCHECK(!callback.is_null()); | 3277 DCHECK(!callback.is_null()); |
| 3375 | 3278 |
| 3376 callback.Run(error); | 3279 callback.Run(error); |
| 3377 } | 3280 } |
| 3378 | 3281 |
| 3379 void GDataFileSystem::OnCloseFileFinished( | 3282 void GDataFileSystem::CloseFileOnUIThreadFinalize( |
| 3380 const FilePath& file_path, | 3283 const FilePath& file_path, |
| 3381 const FileOperationCallback& callback, | 3284 const FileOperationCallback& callback, |
| 3382 GDataFileError result) { | 3285 GDataFileError result) { |
| 3383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3286 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 3384 DCHECK(!callback.is_null()); | 3287 DCHECK(!callback.is_null()); |
| 3385 | 3288 |
| 3386 // Step 7 of CloseFile. | 3289 // Step 3 of CloseFile. |
| 3387 // All the invocation of |callback| from operations initiated from CloseFile | 3290 // All the invocation of |callback| from operations initiated from CloseFile |
| 3388 // must go through here. Removes the |file_path| from the remembered set so | 3291 // must go through here. Removes the |file_path| from the remembered set so |
| 3389 // that subsequent operations can open the file again. | 3292 // that subsequent operations can open the file again. |
| 3390 open_files_.erase(file_path); | 3293 open_files_.erase(file_path); |
| 3391 | 3294 |
| 3392 // Then invokes the user-supplied callback function. | 3295 // Then invokes the user-supplied callback function. |
| 3393 callback.Run(result); | 3296 callback.Run(result); |
| 3394 } | 3297 } |
| 3395 | 3298 |
| 3396 void GDataFileSystem::CheckLocalModificationAndRun( | 3299 void GDataFileSystem::CheckLocalModificationAndRun( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3490 return; | 3393 return; |
| 3491 } | 3394 } |
| 3492 | 3395 |
| 3493 PlatformFileInfoProto entry_file_info; | 3396 PlatformFileInfoProto entry_file_info; |
| 3494 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3397 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
| 3495 *entry_proto->mutable_file_info() = entry_file_info; | 3398 *entry_proto->mutable_file_info() = entry_file_info; |
| 3496 if (!callback.is_null()) | 3399 if (!callback.is_null()) |
| 3497 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3400 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
| 3498 } | 3401 } |
| 3499 | 3402 |
| 3500 } // namespace gdata | 3403 } // namespace gdata |
|
satorux1
2012/08/14 05:19:56
97 lines are gone!!
| |
| OLD | NEW |