Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10834295: gdata: Make callback parameters mandatory for CloseFile functions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 3162 matching lines...) Expand 10 before | Expand all | Expand 10 after
3173 open_files_.erase(file_path); 3173 open_files_.erase(file_path);
3174 3174
3175 if (!callback.is_null()) 3175 if (!callback.is_null())
3176 callback.Run(result, cache_file_path); 3176 callback.Run(result, cache_file_path);
3177 } 3177 }
3178 3178
3179 void GDataFileSystem::CloseFile(const FilePath& file_path, 3179 void GDataFileSystem::CloseFile(const FilePath& file_path,
3180 const FileOperationCallback& callback) { 3180 const FileOperationCallback& callback) {
3181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || 3181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) ||
3182 BrowserThread::CurrentlyOn(BrowserThread::IO)); 3182 BrowserThread::CurrentlyOn(BrowserThread::IO));
3183 DCHECK(!callback.is_null());
3184
3183 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread, 3185 RunTaskOnUIThread(base::Bind(&GDataFileSystem::CloseFileOnUIThread,
3184 ui_weak_ptr_, 3186 ui_weak_ptr_,
3185 file_path, 3187 file_path,
3186 CreateRelayCallback(callback))); 3188 CreateRelayCallback(callback)));
3187 } 3189 }
3188 3190
3189 void GDataFileSystem::CloseFileOnUIThread( 3191 void GDataFileSystem::CloseFileOnUIThread(
3190 const FilePath& file_path, 3192 const FilePath& file_path,
3191 const FileOperationCallback& callback) { 3193 const FileOperationCallback& callback) {
3192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3195 DCHECK(!callback.is_null());
3193 3196
3194 if (open_files_.find(file_path) == open_files_.end()) { 3197 if (open_files_.find(file_path) == open_files_.end()) {
3195 // The file is not being opened. 3198 // The file is not being opened.
3196 MessageLoop::current()->PostTask( 3199 MessageLoop::current()->PostTask(
3197 FROM_HERE, 3200 FROM_HERE,
3198 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND)); 3201 base::Bind(callback, GDATA_FILE_ERROR_NOT_FOUND));
3199 return; 3202 return;
3200 } 3203 }
3201 3204
3202 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|. 3205 // Step 1 of CloseFile: Get resource_id and md5 for |file_path|.
3203 GetEntryInfoByPathAsyncOnUIThread( 3206 GetEntryInfoByPathAsyncOnUIThread(
3204 file_path, 3207 file_path,
3205 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile, 3208 base::Bind(&GDataFileSystem::OnGetEntryInfoCompleteForCloseFile,
3206 ui_weak_ptr_, 3209 ui_weak_ptr_,
3207 file_path, 3210 file_path,
3208 base::Bind(&GDataFileSystem::OnCloseFileFinished, 3211 base::Bind(&GDataFileSystem::OnCloseFileFinished,
3209 ui_weak_ptr_, 3212 ui_weak_ptr_,
3210 file_path, 3213 file_path,
3211 callback))); 3214 callback)));
3212 } 3215 }
3213 3216
3214 void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile( 3217 void GDataFileSystem::OnGetEntryInfoCompleteForCloseFile(
3215 const FilePath& file_path, 3218 const FilePath& file_path,
3216 const FileOperationCallback& callback, 3219 const FileOperationCallback& callback,
3217 GDataFileError error, 3220 GDataFileError error,
3218 scoped_ptr<GDataEntryProto> entry_proto) { 3221 scoped_ptr<GDataEntryProto> entry_proto) {
3222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3223 DCHECK(!callback.is_null());
3224
3219 if (entry_proto.get() && !entry_proto->has_file_specific_info()) 3225 if (entry_proto.get() && !entry_proto->has_file_specific_info())
3220 error = GDATA_FILE_ERROR_NOT_FOUND; 3226 error = GDATA_FILE_ERROR_NOT_FOUND;
3221 3227
3222 if (error != GDATA_FILE_OK) { 3228 if (error != GDATA_FILE_OK) {
3223 if (!callback.is_null()) 3229 callback.Run(error);
3224 callback.Run(error);
3225 return; 3230 return;
3226 } 3231 }
3227 3232
3228 // Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must 3233 // Step 2 of CloseFile: Get the local path of the cache. Since CloseFile must
3229 // always be called on paths opened by OpenFile, the file must be cached, 3234 // always be called on paths opened by OpenFile, the file must be cached,
3230 cache_->GetFileOnUIThread( 3235 cache_->GetFileOnUIThread(
3231 entry_proto->resource_id(), 3236 entry_proto->resource_id(),
3232 entry_proto->file_specific_info().file_md5(), 3237 entry_proto->file_specific_info().file_md5(),
3233 base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile, 3238 base::Bind(&GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile,
3234 ui_weak_ptr_, 3239 ui_weak_ptr_,
3235 file_path, 3240 file_path,
3236 callback)); 3241 callback));
3237 } 3242 }
3238 3243
3239 void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile( 3244 void GDataFileSystem::OnGetCacheFilePathCompleteForCloseFile(
3240 const FilePath& file_path, 3245 const FilePath& file_path,
3241 const FileOperationCallback& callback, 3246 const FileOperationCallback& callback,
3242 GDataFileError error, 3247 GDataFileError error,
3243 const std::string& resource_id, 3248 const std::string& resource_id,
3244 const std::string& md5, 3249 const std::string& md5,
3245 const FilePath& local_cache_path) { 3250 const FilePath& local_cache_path) {
3246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3252 DCHECK(!callback.is_null());
3247 3253
3248 if (error != GDATA_FILE_OK) { 3254 if (error != GDATA_FILE_OK) {
3249 if (!callback.is_null()) 3255 callback.Run(error);
3250 callback.Run(error);
3251 return; 3256 return;
3252 } 3257 }
3253 3258
3254 // Step 3 of CloseFile: Retrieves the (possibly modified) PlatformFileInfo of 3259 // Step 3 of CloseFile: Retrieves the (possibly modified) PlatformFileInfo of
3255 // the cache file. 3260 // the cache file.
3256 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; 3261 base::PlatformFileInfo* file_info = new base::PlatformFileInfo;
3257 bool* get_file_info_result = new bool(false); 3262 bool* get_file_info_result = new bool(false);
3258 util::PostBlockingPoolSequencedTaskAndReply( 3263 util::PostBlockingPoolSequencedTaskAndReply(
3259 FROM_HERE, 3264 FROM_HERE,
3260 blocking_task_runner_, 3265 blocking_task_runner_,
3261 base::Bind(&GetFileInfoOnBlockingPool, 3266 base::Bind(&GetFileInfoOnBlockingPool,
3262 local_cache_path, 3267 local_cache_path,
3263 base::Unretained(file_info), 3268 base::Unretained(file_info),
3264 base::Unretained(get_file_info_result)), 3269 base::Unretained(get_file_info_result)),
3265 base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile, 3270 base::Bind(&GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile,
3266 ui_weak_ptr_, 3271 ui_weak_ptr_,
3267 file_path, 3272 file_path,
3268 base::Owned(file_info), 3273 base::Owned(file_info),
3269 base::Owned(get_file_info_result), 3274 base::Owned(get_file_info_result),
3270 callback)); 3275 callback));
3271 } 3276 }
3272 3277
3273 void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile( 3278 void GDataFileSystem::OnGetModifiedFileInfoCompleteForCloseFile(
3274 const FilePath& file_path, 3279 const FilePath& file_path,
3275 base::PlatformFileInfo* file_info, 3280 base::PlatformFileInfo* file_info,
3276 bool* get_file_info_result, 3281 bool* get_file_info_result,
3277 const FileOperationCallback& callback) { 3282 const FileOperationCallback& callback) {
3278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3284 DCHECK(!callback.is_null());
3279 3285
3280 if (!*get_file_info_result) { 3286 if (!*get_file_info_result) {
3281 if (!callback.is_null()) 3287 callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
3282 callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
3283 return; 3288 return;
3284 } 3289 }
3285 3290
3286 // Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for 3291 // Step 4 of CloseFile: Find GDataEntry corresponding to |file_path|, for
3287 // modifying the entry's metadata. 3292 // modifying the entry's metadata.
3288 FindEntryByPathAsyncOnUIThread( 3293 FindEntryByPathAsyncOnUIThread(
3289 file_path, 3294 file_path,
3290 base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile, 3295 base::Bind(&GDataFileSystem::OnGetEntryCompleteForCloseFile,
3291 ui_weak_ptr_, 3296 ui_weak_ptr_,
3292 file_path,
3293 *file_info, 3297 *file_info,
3294 callback)); 3298 callback));
3295 } 3299 }
3296 3300
3297 void GDataFileSystem::OnGetEntryCompleteForCloseFile( 3301 void GDataFileSystem::OnGetEntryCompleteForCloseFile(
3298 const FilePath& file_path,
3299 const base::PlatformFileInfo& file_info, 3302 const base::PlatformFileInfo& file_info,
3300 const FileOperationCallback& callback, 3303 const FileOperationCallback& callback,
3301 GDataFileError error, 3304 GDataFileError error,
3302 GDataEntry* entry) { 3305 GDataEntry* entry) {
3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3307 DCHECK(!callback.is_null());
3304 3308
3305 if (error != GDATA_FILE_OK) { 3309 if (error != GDATA_FILE_OK) {
3306 if (!callback.is_null()) 3310 callback.Run(error);
3307 callback.Run(error);
3308 return; 3311 return;
3309 } 3312 }
3310 3313
3311 DCHECK(entry); 3314 DCHECK(entry);
3312 GDataFile* file = entry->AsGDataFile(); 3315 GDataFile* file = entry->AsGDataFile();
3313 if (!file || file->file_md5().empty() || file->is_hosted_document()) { 3316 if (!file || file->file_md5().empty() || file->is_hosted_document()) {
3314 // No support for opening a directory or hosted document. 3317 // No support for opening a directory or hosted document.
3315 if (!callback.is_null()) 3318 callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
3316 callback.Run(GDATA_FILE_ERROR_INVALID_OPERATION);
3317 return; 3319 return;
3318 } 3320 }
3319 DCHECK(!file->resource_id().empty()); 3321 DCHECK(!file->resource_id().empty());
3320 3322
3321 // Step 5 of CloseFile: 3323 // Step 5 of CloseFile:
3322 // Update the in-memory meta data. Until the committed cache is uploaded in 3324 // Update the in-memory meta data. Until the committed cache is uploaded in
3323 // background to the server and the change is propagated back, this in-memory 3325 // background to the server and the change is propagated back, this in-memory
3324 // meta data is referred by subsequent file operations. So it needs to reflect 3326 // meta data is referred by subsequent file operations. So it needs to reflect
3325 // the modification made before committing. 3327 // the modification made before committing.
3326 file->set_file_info(file_info); 3328 file->set_file_info(file_info);
3327 3329
3328 // Step 6 of CloseFile: Commit the modification in cache. This will trigger 3330 // Step 6 of CloseFile: Commit the modification in cache. This will trigger
3329 // background upload. 3331 // background upload.
3330 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache 3332 // TODO(benchan,kinaba): Call ClearDirtyInCache instead of CommitDirtyInCache
3331 // if the file has not been modified. Come up with a way to detect the 3333 // if the file has not been modified. Come up with a way to detect the
3332 // intactness effectively, or provide a method for user to declare it when 3334 // intactness effectively, or provide a method for user to declare it when
3333 // calling CloseFile(). 3335 // calling CloseFile().
3334 cache_->CommitDirtyOnUIThread( 3336 cache_->CommitDirtyOnUIThread(
3335 file->resource_id(), 3337 file->resource_id(),
3336 file->file_md5(), 3338 file->file_md5(),
3337 base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile, 3339 base::Bind(&GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile,
3338 ui_weak_ptr_, 3340 ui_weak_ptr_,
3339 callback)); 3341 callback));
3340 } 3342 }
3341 3343
3342 void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile( 3344 void GDataFileSystem::OnCommitDirtyInCacheCompleteForCloseFile(
3343 const FileOperationCallback& callback, 3345 const FileOperationCallback& callback,
3344 GDataFileError error, 3346 GDataFileError error,
3345 const std::string& resource_id, 3347 const std::string& /* resource_id */,
3346 const std::string& md5) { 3348 const std::string& /* md5 */) {
3347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3350 DCHECK(!callback.is_null());
3348 3351
3349 if (!callback.is_null()) 3352 callback.Run(error);
3350 callback.Run(error);
3351 } 3353 }
3352 3354
3353 void GDataFileSystem::OnCloseFileFinished( 3355 void GDataFileSystem::OnCloseFileFinished(
3354 const FilePath& file_path, 3356 const FilePath& file_path,
3355 const FileOperationCallback& callback, 3357 const FileOperationCallback& callback,
3356 GDataFileError result) { 3358 GDataFileError result) {
3357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3360 DCHECK(!callback.is_null());
3358 3361
3359 // Step 7 of CloseFile. 3362 // Step 7 of CloseFile.
3360 // All the invocation of |callback| from operations initiated from CloseFile 3363 // All the invocation of |callback| from operations initiated from CloseFile
3361 // must go through here. Removes the |file_path| from the remembered set so 3364 // must go through here. Removes the |file_path| from the remembered set so
3362 // that subsequent operations can open the file again. 3365 // that subsequent operations can open the file again.
3363 open_files_.erase(file_path); 3366 open_files_.erase(file_path);
3364 3367
3365 // Then invokes the user-supplied callback function. 3368 // Then invokes the user-supplied callback function.
3366 if (!callback.is_null()) 3369 callback.Run(result);
3367 callback.Run(result);
3368 } 3370 }
3369 3371
3370 void GDataFileSystem::CheckLocalModificationAndRun( 3372 void GDataFileSystem::CheckLocalModificationAndRun(
3371 scoped_ptr<GDataEntryProto> entry_proto, 3373 scoped_ptr<GDataEntryProto> entry_proto,
3372 const GetEntryInfoCallback& callback) { 3374 const GetEntryInfoCallback& callback) {
3373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3374 DCHECK(entry_proto.get()); 3376 DCHECK(entry_proto.get());
3375 3377
3376 // For entries that will never be cached, use the original entry info as is. 3378 // For entries that will never be cached, use the original entry info as is.
3377 if (!entry_proto->has_file_specific_info() || 3379 if (!entry_proto->has_file_specific_info() ||
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3465 } 3467 }
3466 3468
3467 PlatformFileInfoProto entry_file_info; 3469 PlatformFileInfoProto entry_file_info;
3468 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 3470 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
3469 *entry_proto->mutable_file_info() = entry_file_info; 3471 *entry_proto->mutable_file_info() = entry_file_info;
3470 if (!callback.is_null()) 3472 if (!callback.is_null())
3471 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 3473 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
3472 } 3474 }
3473 3475
3474 } // namespace gdata 3476 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698