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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 // | 452 // |
453 // |callback| is run on the thread represented by |relay_proxy|. | 453 // |callback| is run on the thread represented by |relay_proxy|. |
454 void OnTransferRegularFileCompleteForCopy( | 454 void OnTransferRegularFileCompleteForCopy( |
455 const FileOperationCallback& callback, | 455 const FileOperationCallback& callback, |
456 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 456 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
457 base::PlatformFileError error) { | 457 base::PlatformFileError error) { |
458 if (!callback.is_null()) | 458 if (!callback.is_null()) |
459 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); | 459 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); |
460 } | 460 } |
461 | 461 |
462 // Gets a cache entry from a GDataCache, must be called on the blocking pool. | |
satorux1
2012/06/14 01:24:42
might want to document about cache_entry and resul
hashimoto
2012/06/14 03:12:02
Done.
| |
463 void GetCacheEntryOnBlockingPool( | |
464 GDataCache* cache, | |
465 const std::string& resource_id, | |
466 const std::string& md5, | |
467 GDataCache::CacheEntry* cache_entry, | |
468 bool* result) { | |
satorux1
2012/06/14 01:24:42
result sounds rather vague. maybe result -> succes
hashimoto
2012/06/14 03:12:02
Done.
| |
469 scoped_ptr<GDataCache::CacheEntry> value( | |
470 cache->GetCacheEntry(resource_id, md5)); | |
471 *result = value.get(); | |
472 if (*result) | |
473 *cache_entry = *value; | |
474 } | |
475 | |
462 // Runs GetFileCallback with pointers dereferenced. | 476 // Runs GetFileCallback with pointers dereferenced. |
463 // Used for PostTaskAndReply(). | 477 // Used for PostTaskAndReply(). |
464 void RunGetFileCallbackHelper(const GetFileCallback& callback, | 478 void RunGetFileCallbackHelper(const GetFileCallback& callback, |
465 base::PlatformFileError* error, | 479 base::PlatformFileError* error, |
466 FilePath* file_path, | 480 FilePath* file_path, |
467 std::string* mime_type, | 481 std::string* mime_type, |
468 GDataFileType* file_type) { | 482 GDataFileType* file_type) { |
469 DCHECK(error); | 483 DCHECK(error); |
470 DCHECK(file_path); | 484 DCHECK(file_path); |
471 DCHECK(mime_type); | 485 DCHECK(mime_type); |
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3236 void GDataFileSystem::OnFileDownloaded( | 3250 void GDataFileSystem::OnFileDownloaded( |
3237 const GetFileFromCacheParams& params, | 3251 const GetFileFromCacheParams& params, |
3238 GDataErrorCode status, | 3252 GDataErrorCode status, |
3239 const GURL& content_url, | 3253 const GURL& content_url, |
3240 const FilePath& downloaded_file_path) { | 3254 const FilePath& downloaded_file_path) { |
3241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3242 | 3256 |
3243 // If user cancels download of a pinned-but-not-fetched file, mark file as | 3257 // If user cancels download of a pinned-but-not-fetched file, mark file as |
3244 // unpinned so that we do not sync the file again. | 3258 // unpinned so that we do not sync the file again. |
3245 if (status == GDATA_CANCELLED) { | 3259 if (status == GDATA_CANCELLED) { |
3246 bool pinning_cancelled = false; | 3260 GDataCache::CacheEntry* cache_entry = new GDataCache::CacheEntry; |
3247 { | 3261 bool* result = new bool(false); |
satorux1
2012/06/14 01:24:42
ditto.
hashimoto
2012/06/14 03:12:02
Done.
| |
3248 // To access root_. Limit the scope as SetPinStateOnUIThread() will | 3262 PostBlockingPoolSequencedTaskAndReply( |
3249 // acquire the lock. | 3263 FROM_HERE, |
3250 base::AutoLock lock(lock_); | 3264 base::Bind(&GetCacheEntryOnBlockingPool, |
3251 // TODO(satorux): Should not call this on UI thread. crbug.com/131826. | 3265 cache_, |
3252 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( | 3266 params.resource_id, |
3253 params.resource_id, | 3267 params.md5, |
3254 params.md5); | 3268 cache_entry, |
3255 if (cache_entry.get() && cache_entry->IsPinned()) | 3269 result), |
3256 pinning_cancelled = true; | 3270 base::Bind(&GDataFileSystem::UnpinIfPinned, |
3257 } | 3271 ui_weak_ptr_, |
3258 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | 3272 params.virtual_file_path, |
3259 // This allows file manager to clear the "Available offline" checkbox. | 3273 base::Owned(cache_entry), |
3260 if (pinning_cancelled) { | 3274 base::Owned(result))); |
3261 SetPinStateOnUIThread(params.virtual_file_path, false, | |
3262 FileOperationCallback()); | |
3263 } | |
3264 } | 3275 } |
3265 | 3276 |
3266 // At this point, the disk can be full or nearly full for several reasons: | 3277 // At this point, the disk can be full or nearly full for several reasons: |
3267 // - The expected file size was incorrect and the file was larger | 3278 // - The expected file size was incorrect and the file was larger |
3268 // - There was an in-flight download operation and it used up space | 3279 // - There was an in-flight download operation and it used up space |
3269 // - The disk became full for some user actions we cannot control | 3280 // - The disk became full for some user actions we cannot control |
3270 // (ex. the user might have downloaded a large file from a regular web site) | 3281 // (ex. the user might have downloaded a large file from a regular web site) |
3271 // | 3282 // |
3272 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, | 3283 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, |
3273 // and try to free up space, even if the file was downloaded successfully. | 3284 // and try to free up space, even if the file was downloaded successfully. |
3274 bool* has_enough_space = new bool(false); | 3285 bool* has_enough_space = new bool(false); |
3275 PostBlockingPoolSequencedTaskAndReply( | 3286 PostBlockingPoolSequencedTaskAndReply( |
3276 FROM_HERE, | 3287 FROM_HERE, |
3277 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, | 3288 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, |
3278 base::Unretained(this), | 3289 base::Unretained(this), |
3279 has_enough_space), | 3290 has_enough_space), |
3280 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, | 3291 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, |
3281 ui_weak_ptr_, | 3292 ui_weak_ptr_, |
3282 params, | 3293 params, |
3283 status, | 3294 status, |
3284 content_url, | 3295 content_url, |
3285 downloaded_file_path, | 3296 downloaded_file_path, |
3286 base::Owned(has_enough_space))); | 3297 base::Owned(has_enough_space))); |
3287 } | 3298 } |
3288 | 3299 |
3300 void GDataFileSystem::UnpinIfPinned(const FilePath& file_path, | |
3301 GDataCache::CacheEntry* cache_entry, | |
3302 bool* cache_entry_is_valid) { | |
3303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
3304 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | |
3305 // This allows file manager to clear the "Available offline" checkbox. | |
3306 if (*cache_entry_is_valid && cache_entry->IsPinned()) | |
3307 SetPinStateOnUIThread(file_path, false, FileOperationCallback()); | |
3308 } | |
3309 | |
3289 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( | 3310 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( |
3290 const GetFileFromCacheParams& params, | 3311 const GetFileFromCacheParams& params, |
3291 GDataErrorCode status, | 3312 GDataErrorCode status, |
3292 const GURL& content_url, | 3313 const GURL& content_url, |
3293 const FilePath& downloaded_file_path, | 3314 const FilePath& downloaded_file_path, |
3294 bool* has_enough_space) { | 3315 bool* has_enough_space) { |
3295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
3296 | 3317 |
3297 base::PlatformFileError error = GDataToPlatformError(status); | 3318 base::PlatformFileError error = GDataToPlatformError(status); |
3298 | 3319 |
(...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5204 base::PlatformFileError error, | 5225 base::PlatformFileError error, |
5205 const std::string& resource_id, | 5226 const std::string& resource_id, |
5206 const std::string& md5) { | 5227 const std::string& md5) { |
5207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 5228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
5208 | 5229 |
5209 if (!callback.is_null()) | 5230 if (!callback.is_null()) |
5210 callback.Run(error); | 5231 callback.Run(error); |
5211 } | 5232 } |
5212 | 5233 |
5213 } // namespace gdata | 5234 } // namespace gdata |
OLD | NEW |