Index: chrome/browser/chromeos/gdata/gdata_file_system.cc |
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
index ea62ae804e2908ac49edcd7a42b96ca5e7bd9d45..0c46a31db5c30d262283e71121e174ed9241419d 100644 |
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc |
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc |
@@ -459,6 +459,20 @@ void OnTransferRegularFileCompleteForCopy( |
relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); |
} |
+// 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.
|
+void GetCacheEntryOnBlockingPool( |
+ GDataCache* cache, |
+ const std::string& resource_id, |
+ const std::string& md5, |
+ GDataCache::CacheEntry* cache_entry, |
+ bool* result) { |
satorux1
2012/06/14 01:24:42
result sounds rather vague. maybe result -> succes
hashimoto
2012/06/14 03:12:02
Done.
|
+ scoped_ptr<GDataCache::CacheEntry> value( |
+ cache->GetCacheEntry(resource_id, md5)); |
+ *result = value.get(); |
+ if (*result) |
+ *cache_entry = *value; |
+} |
+ |
// Runs GetFileCallback with pointers dereferenced. |
// Used for PostTaskAndReply(). |
void RunGetFileCallbackHelper(const GetFileCallback& callback, |
@@ -3243,24 +3257,21 @@ void GDataFileSystem::OnFileDownloaded( |
// If user cancels download of a pinned-but-not-fetched file, mark file as |
// unpinned so that we do not sync the file again. |
if (status == GDATA_CANCELLED) { |
- bool pinning_cancelled = false; |
- { |
- // To access root_. Limit the scope as SetPinStateOnUIThread() will |
- // acquire the lock. |
- base::AutoLock lock(lock_); |
- // TODO(satorux): Should not call this on UI thread. crbug.com/131826. |
- scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( |
- params.resource_id, |
- params.md5); |
- if (cache_entry.get() && cache_entry->IsPinned()) |
- pinning_cancelled = true; |
- } |
- // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
- // This allows file manager to clear the "Available offline" checkbox. |
- if (pinning_cancelled) { |
- SetPinStateOnUIThread(params.virtual_file_path, false, |
- FileOperationCallback()); |
- } |
+ GDataCache::CacheEntry* cache_entry = new GDataCache::CacheEntry; |
+ bool* result = new bool(false); |
satorux1
2012/06/14 01:24:42
ditto.
hashimoto
2012/06/14 03:12:02
Done.
|
+ PostBlockingPoolSequencedTaskAndReply( |
+ FROM_HERE, |
+ base::Bind(&GetCacheEntryOnBlockingPool, |
+ cache_, |
+ params.resource_id, |
+ params.md5, |
+ cache_entry, |
+ result), |
+ base::Bind(&GDataFileSystem::UnpinIfPinned, |
+ ui_weak_ptr_, |
+ params.virtual_file_path, |
+ base::Owned(cache_entry), |
+ base::Owned(result))); |
} |
// At this point, the disk can be full or nearly full for several reasons: |
@@ -3286,6 +3297,16 @@ void GDataFileSystem::OnFileDownloaded( |
base::Owned(has_enough_space))); |
} |
+void GDataFileSystem::UnpinIfPinned(const FilePath& file_path, |
+ GDataCache::CacheEntry* cache_entry, |
+ bool* cache_entry_is_valid) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
+ // This allows file manager to clear the "Available offline" checkbox. |
+ if (*cache_entry_is_valid && cache_entry->IsPinned()) |
+ SetPinStateOnUIThread(file_path, false, FileOperationCallback()); |
+} |
+ |
void GDataFileSystem::OnFileDownloadedAndSpaceChecked( |
const GetFileFromCacheParams& params, |
GDataErrorCode status, |