| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // | 193 // |
| 194 // |callback| is run on the thread represented by |relay_proxy|. | 194 // |callback| is run on the thread represented by |relay_proxy|. |
| 195 void OnTransferRegularFileCompleteForCopy( | 195 void OnTransferRegularFileCompleteForCopy( |
| 196 const FileOperationCallback& callback, | 196 const FileOperationCallback& callback, |
| 197 scoped_refptr<base::MessageLoopProxy> relay_proxy, | 197 scoped_refptr<base::MessageLoopProxy> relay_proxy, |
| 198 base::PlatformFileError error) { | 198 base::PlatformFileError error) { |
| 199 if (!callback.is_null()) | 199 if (!callback.is_null()) |
| 200 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); | 200 relay_proxy->PostTask(FROM_HERE, base::Bind(callback, error)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 // Gets a cache entry from a GDataCache, must be called on the blocking pool. |
| 204 // The result value is copied to cache_entry on success. |
| 205 void GetCacheEntryOnBlockingPool( |
| 206 GDataCache* cache, |
| 207 const std::string& resource_id, |
| 208 const std::string& md5, |
| 209 GDataCache::CacheEntry* cache_entry, |
| 210 bool* success) { |
| 211 scoped_ptr<GDataCache::CacheEntry> value( |
| 212 cache->GetCacheEntry(resource_id, md5)); |
| 213 *success = value.get(); |
| 214 if (*success) |
| 215 *cache_entry = *value; |
| 216 } |
| 217 |
| 203 // Runs GetFileCallback with pointers dereferenced. | 218 // Runs GetFileCallback with pointers dereferenced. |
| 204 // Used for PostTaskAndReply(). | 219 // Used for PostTaskAndReply(). |
| 205 void RunGetFileCallbackHelper(const GetFileCallback& callback, | 220 void RunGetFileCallbackHelper(const GetFileCallback& callback, |
| 206 base::PlatformFileError* error, | 221 base::PlatformFileError* error, |
| 207 FilePath* file_path, | 222 FilePath* file_path, |
| 208 std::string* mime_type, | 223 std::string* mime_type, |
| 209 GDataFileType* file_type) { | 224 GDataFileType* file_type) { |
| 210 DCHECK(error); | 225 DCHECK(error); |
| 211 DCHECK(file_path); | 226 DCHECK(file_path); |
| 212 DCHECK(mime_type); | 227 DCHECK(mime_type); |
| (...skipping 2689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2902 void GDataFileSystem::OnFileDownloaded( | 2917 void GDataFileSystem::OnFileDownloaded( |
| 2903 const GetFileFromCacheParams& params, | 2918 const GetFileFromCacheParams& params, |
| 2904 GDataErrorCode status, | 2919 GDataErrorCode status, |
| 2905 const GURL& content_url, | 2920 const GURL& content_url, |
| 2906 const FilePath& downloaded_file_path) { | 2921 const FilePath& downloaded_file_path) { |
| 2907 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2908 | 2923 |
| 2909 // If user cancels download of a pinned-but-not-fetched file, mark file as | 2924 // If user cancels download of a pinned-but-not-fetched file, mark file as |
| 2910 // unpinned so that we do not sync the file again. | 2925 // unpinned so that we do not sync the file again. |
| 2911 if (status == GDATA_CANCELLED) { | 2926 if (status == GDATA_CANCELLED) { |
| 2912 bool pinning_cancelled = false; | 2927 GDataCache::CacheEntry* cache_entry = new GDataCache::CacheEntry; |
| 2913 { | 2928 bool* success = new bool(false); |
| 2914 // To access root_. Limit the scope as SetPinStateOnUIThread() will | 2929 PostBlockingPoolSequencedTaskAndReply( |
| 2915 // acquire the lock. | 2930 FROM_HERE, |
| 2916 base::AutoLock lock(lock_); | 2931 base::Bind(&GetCacheEntryOnBlockingPool, |
| 2917 // TODO(satorux): Should not call this on UI thread. crbug.com/131826. | 2932 cache_, |
| 2918 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( | 2933 params.resource_id, |
| 2919 params.resource_id, | 2934 params.md5, |
| 2920 params.md5); | 2935 cache_entry, |
| 2921 if (cache_entry.get() && cache_entry->IsPinned()) | 2936 success), |
| 2922 pinning_cancelled = true; | 2937 base::Bind(&GDataFileSystem::UnpinIfPinned, |
| 2923 } | 2938 ui_weak_ptr_, |
| 2924 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | 2939 params.virtual_file_path, |
| 2925 // This allows file manager to clear the "Available offline" checkbox. | 2940 base::Owned(cache_entry), |
| 2926 if (pinning_cancelled) { | 2941 base::Owned(success))); |
| 2927 SetPinStateOnUIThread(params.virtual_file_path, false, | |
| 2928 FileOperationCallback()); | |
| 2929 } | |
| 2930 } | 2942 } |
| 2931 | 2943 |
| 2932 // At this point, the disk can be full or nearly full for several reasons: | 2944 // At this point, the disk can be full or nearly full for several reasons: |
| 2933 // - The expected file size was incorrect and the file was larger | 2945 // - The expected file size was incorrect and the file was larger |
| 2934 // - There was an in-flight download operation and it used up space | 2946 // - There was an in-flight download operation and it used up space |
| 2935 // - The disk became full for some user actions we cannot control | 2947 // - The disk became full for some user actions we cannot control |
| 2936 // (ex. the user might have downloaded a large file from a regular web site) | 2948 // (ex. the user might have downloaded a large file from a regular web site) |
| 2937 // | 2949 // |
| 2938 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, | 2950 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, |
| 2939 // and try to free up space, even if the file was downloaded successfully. | 2951 // and try to free up space, even if the file was downloaded successfully. |
| 2940 bool* has_enough_space = new bool(false); | 2952 bool* has_enough_space = new bool(false); |
| 2941 PostBlockingPoolSequencedTaskAndReply( | 2953 PostBlockingPoolSequencedTaskAndReply( |
| 2942 FROM_HERE, | 2954 FROM_HERE, |
| 2943 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, | 2955 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, |
| 2944 base::Unretained(this), | 2956 base::Unretained(this), |
| 2945 has_enough_space), | 2957 has_enough_space), |
| 2946 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, | 2958 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, |
| 2947 ui_weak_ptr_, | 2959 ui_weak_ptr_, |
| 2948 params, | 2960 params, |
| 2949 status, | 2961 status, |
| 2950 content_url, | 2962 content_url, |
| 2951 downloaded_file_path, | 2963 downloaded_file_path, |
| 2952 base::Owned(has_enough_space))); | 2964 base::Owned(has_enough_space))); |
| 2953 } | 2965 } |
| 2954 | 2966 |
| 2967 void GDataFileSystem::UnpinIfPinned(const FilePath& file_path, |
| 2968 GDataCache::CacheEntry* cache_entry, |
| 2969 bool* cache_entry_is_valid) { |
| 2970 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2971 // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
| 2972 // This allows file manager to clear the "Available offline" checkbox. |
| 2973 if (*cache_entry_is_valid && cache_entry->IsPinned()) |
| 2974 SetPinStateOnUIThread(file_path, false, FileOperationCallback()); |
| 2975 } |
| 2976 |
| 2955 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( | 2977 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( |
| 2956 const GetFileFromCacheParams& params, | 2978 const GetFileFromCacheParams& params, |
| 2957 GDataErrorCode status, | 2979 GDataErrorCode status, |
| 2958 const GURL& content_url, | 2980 const GURL& content_url, |
| 2959 const FilePath& downloaded_file_path, | 2981 const FilePath& downloaded_file_path, |
| 2960 bool* has_enough_space) { | 2982 bool* has_enough_space) { |
| 2961 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2983 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2962 | 2984 |
| 2963 base::PlatformFileError error = GDataToPlatformError(status); | 2985 base::PlatformFileError error = GDataToPlatformError(status); |
| 2964 | 2986 |
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4197 base::PlatformFileError error, | 4219 base::PlatformFileError error, |
| 4198 const std::string& resource_id, | 4220 const std::string& resource_id, |
| 4199 const std::string& md5) { | 4221 const std::string& md5) { |
| 4200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 4222 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 4201 | 4223 |
| 4202 if (!callback.is_null()) | 4224 if (!callback.is_null()) |
| 4203 callback.Run(error); | 4225 callback.Run(error); |
| 4204 } | 4226 } |
| 4205 | 4227 |
| 4206 } // namespace gdata | 4228 } // namespace gdata |
| OLD | NEW |