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

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

Issue 10535145: chromeos: Stop calling gdata::GDataCache::GetCacheEntry on UI thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test Created 8 years, 6 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 <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
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 void GetCacheEntryOnBlockingPool(
satorux1 2012/06/13 23:03:03 nit: function comment is missing.
satorux1 2012/06/14 00:41:47 ping.
hashimoto 2012/06/14 01:17:53 Done.
463 GDataCache* cache,
464 const std::string& resource_id,
465 const std::string& md5,
466 scoped_ptr<GDataCache::CacheEntry>* cache_entry) {
467 cache_entry->reset(cache->GetCacheEntry(resource_id, md5).release());
468 }
469
462 // Runs GetFileCallback with pointers dereferenced. 470 // Runs GetFileCallback with pointers dereferenced.
463 // Used for PostTaskAndReply(). 471 // Used for PostTaskAndReply().
464 void RunGetFileCallbackHelper(const GetFileCallback& callback, 472 void RunGetFileCallbackHelper(const GetFileCallback& callback,
465 base::PlatformFileError* error, 473 base::PlatformFileError* error,
466 FilePath* file_path, 474 FilePath* file_path,
467 std::string* mime_type, 475 std::string* mime_type,
468 GDataFileType* file_type) { 476 GDataFileType* file_type) {
469 DCHECK(error); 477 DCHECK(error);
470 DCHECK(file_path); 478 DCHECK(file_path);
471 DCHECK(mime_type); 479 DCHECK(mime_type);
(...skipping 2764 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 void GDataFileSystem::OnFileDownloaded( 3244 void GDataFileSystem::OnFileDownloaded(
3237 const GetFileFromCacheParams& params, 3245 const GetFileFromCacheParams& params,
3238 GDataErrorCode status, 3246 GDataErrorCode status,
3239 const GURL& content_url, 3247 const GURL& content_url,
3240 const FilePath& downloaded_file_path) { 3248 const FilePath& downloaded_file_path) {
3241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3242 3250
3243 // If user cancels download of a pinned-but-not-fetched file, mark file as 3251 // 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. 3252 // unpinned so that we do not sync the file again.
3245 if (status == GDATA_CANCELLED) { 3253 if (status == GDATA_CANCELLED) {
3246 bool pinning_cancelled = false; 3254 scoped_ptr<GDataCache::CacheEntry>* cache_entry =
3247 { 3255 new scoped_ptr<GDataCache::CacheEntry>();
achuithb 2012/06/13 21:37:11 Why not GDataCache::CacheEntry* cache_entry = new
satorux1 2012/06/13 23:03:03 I think hashimoto's intention was to clarify owner
hashimoto 2012/06/14 00:12:42 We cannot use raw pointer here since NULL is passe
satorux1 2012/06/14 00:23:56 I'm confused. I thought we could delete "cache_ent
hashimoto 2012/06/14 00:33:35 In your code, UnpinIfPinned always receives NULL
satorux1 2012/06/14 00:37:57 Oh you are absolutely right... Then, I'm fine with
achuithb 2012/06/14 00:45:51 I think it would be preferable to copy CacheEntry
satorux1 2012/06/14 00:48:11 Ah, I like that!
hashimoto 2012/06/14 00:58:09 The reason I was not copying the object here was t
satorux1 2012/06/14 01:00:09 That's a very valid point... Maybe just a historic
hashimoto 2012/06/14 01:17:53 Done, added the default constructor for GDataCache
3248 // To access root_. Limit the scope as SetPinStateOnUIThread() will 3256 PostBlockingPoolSequencedTaskAndReply(
3249 // acquire the lock. 3257 FROM_HERE,
3250 base::AutoLock lock(lock_); 3258 base::Bind(&GetCacheEntryOnBlockingPool,
3251 // TODO(satorux): Should not call this on UI thread. crbug.com/131826. 3259 cache_,
3252 scoped_ptr<GDataCache::CacheEntry> cache_entry = cache_->GetCacheEntry( 3260 params.resource_id,
3253 params.resource_id, 3261 params.md5,
3254 params.md5); 3262 cache_entry),
3255 if (cache_entry.get() && cache_entry->IsPinned()) 3263 base::Bind(&GDataFileSystem::UnpinIfPinned,
3256 pinning_cancelled = true; 3264 ui_weak_ptr_,
3257 } 3265 params.virtual_file_path,
3258 // TODO(hshi): http://crbug.com/127138 notify when file properties change. 3266 base::Owned(cache_entry)));
3259 // This allows file manager to clear the "Available offline" checkbox.
3260 if (pinning_cancelled) {
3261 SetPinStateOnUIThread(params.virtual_file_path, false,
3262 FileOperationCallback());
3263 }
3264 } 3267 }
3265 3268
3266 // At this point, the disk can be full or nearly full for several reasons: 3269 // 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 3270 // - The expected file size was incorrect and the file was larger
3268 // - There was an in-flight download operation and it used up space 3271 // - There was an in-flight download operation and it used up space
3269 // - The disk became full for some user actions we cannot control 3272 // - 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) 3273 // (ex. the user might have downloaded a large file from a regular web site)
3271 // 3274 //
3272 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, 3275 // 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. 3276 // and try to free up space, even if the file was downloaded successfully.
3274 bool* has_enough_space = new bool(false); 3277 bool* has_enough_space = new bool(false);
3275 PostBlockingPoolSequencedTaskAndReply( 3278 PostBlockingPoolSequencedTaskAndReply(
3276 FROM_HERE, 3279 FROM_HERE,
3277 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded, 3280 base::Bind(&GDataFileSystem::FreeDiskSpaceIfNeeded,
3278 base::Unretained(this), 3281 base::Unretained(this),
3279 has_enough_space), 3282 has_enough_space),
3280 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked, 3283 base::Bind(&GDataFileSystem::OnFileDownloadedAndSpaceChecked,
3281 ui_weak_ptr_, 3284 ui_weak_ptr_,
3282 params, 3285 params,
3283 status, 3286 status,
3284 content_url, 3287 content_url,
3285 downloaded_file_path, 3288 downloaded_file_path,
3286 base::Owned(has_enough_space))); 3289 base::Owned(has_enough_space)));
3287 } 3290 }
3288 3291
3292 void GDataFileSystem::UnpinIfPinned(
3293 const FilePath& file_path,
3294 scoped_ptr<GDataCache::CacheEntry>* cache_entry) {
3295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3296 // TODO(hshi): http://crbug.com/127138 notify when file properties change.
3297 // This allows file manager to clear the "Available offline" checkbox.
3298 if ((*cache_entry).get() && (*cache_entry)->IsPinned())
3299 SetPinStateOnUIThread(file_path, false, FileOperationCallback());
3300 }
3301
3289 void GDataFileSystem::OnFileDownloadedAndSpaceChecked( 3302 void GDataFileSystem::OnFileDownloadedAndSpaceChecked(
3290 const GetFileFromCacheParams& params, 3303 const GetFileFromCacheParams& params,
3291 GDataErrorCode status, 3304 GDataErrorCode status,
3292 const GURL& content_url, 3305 const GURL& content_url,
3293 const FilePath& downloaded_file_path, 3306 const FilePath& downloaded_file_path,
3294 bool* has_enough_space) { 3307 bool* has_enough_space) {
3295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3296 3309
3297 base::PlatformFileError error = GDataToPlatformError(status); 3310 base::PlatformFileError error = GDataToPlatformError(status);
3298 3311
(...skipping 1905 matching lines...) Expand 10 before | Expand all | Expand 10 after
5204 base::PlatformFileError error, 5217 base::PlatformFileError error,
5205 const std::string& resource_id, 5218 const std::string& resource_id,
5206 const std::string& md5) { 5219 const std::string& md5) {
5207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 5220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
5208 5221
5209 if (!callback.is_null()) 5222 if (!callback.is_null())
5210 callback.Run(error); 5223 callback.Run(error);
5211 } 5224 }
5212 5225
5213 } // namespace gdata 5226 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698