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

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

Issue 10182012: gdata: Remove GDataFileSystem::GetFileFromCacheByResourceIdAndMd5Internal() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 if (!callback.is_null()) 492 if (!callback.is_null())
493 callback.Run(*error, resource_id, md5); 493 callback.Run(*error, resource_id, md5);
494 } 494 }
495 495
496 // Ditto for GetFileFromCacheCallback. 496 // Ditto for GetFileFromCacheCallback.
497 void RunGetFileFromCacheCallbackHelper( 497 void RunGetFileFromCacheCallbackHelper(
498 const GetFileFromCacheCallback& callback, 498 const GetFileFromCacheCallback& callback,
499 base::PlatformFileError* error, 499 base::PlatformFileError* error,
500 const std::string& resource_id, 500 const std::string& resource_id,
501 const std::string& md5, 501 const std::string& md5,
502 const FilePath& gdata_file_path,
503 FilePath* cache_file_path) { 502 FilePath* cache_file_path) {
504 DCHECK(error); 503 DCHECK(error);
505 DCHECK(cache_file_path); 504 DCHECK(cache_file_path);
506 505
507 if (!callback.is_null()) 506 if (!callback.is_null())
508 callback.Run(*error, resource_id, md5, gdata_file_path, *cache_file_path); 507 callback.Run(*error, resource_id, md5, *cache_file_path);
509 } 508 }
510 509
511 void RunGetCacheStateCallbackHelper( 510 void RunGetCacheStateCallbackHelper(
512 const GetCacheStateCallback& callback, 511 const GetCacheStateCallback& callback,
513 base::PlatformFileError* error, 512 base::PlatformFileError* error,
514 int* cache_state) { 513 int* cache_state) {
515 DCHECK(error); 514 DCHECK(error);
516 DCHECK(cache_state); 515 DCHECK(cache_state);
517 516
518 if (!callback.is_null()) 517 if (!callback.is_null())
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 return; 1753 return;
1755 } 1754 }
1756 1755
1757 GetFileByPath(file_path, callback); 1756 GetFileByPath(file_path, callback);
1758 } 1757 }
1759 1758
1760 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params, 1759 void GDataFileSystem::OnGetFileFromCache(const GetFileFromCacheParams& params,
1761 base::PlatformFileError error, 1760 base::PlatformFileError error,
1762 const std::string& resource_id, 1761 const std::string& resource_id,
1763 const std::string& md5, 1762 const std::string& md5,
1764 const FilePath& gdata_file_path,
1765 const FilePath& cache_file_path) { 1763 const FilePath& cache_file_path) {
1766 // Have we found the file in cache? If so, return it back to the caller. 1764 // Have we found the file in cache? If so, return it back to the caller.
1767 if (error == base::PLATFORM_FILE_OK) { 1765 if (error == base::PLATFORM_FILE_OK) {
1768 if (!params.callback.is_null()) { 1766 if (!params.callback.is_null()) {
1769 params.proxy->PostTask(FROM_HERE, 1767 params.proxy->PostTask(FROM_HERE,
1770 base::Bind(params.callback, 1768 base::Bind(params.callback,
1771 error, 1769 error,
1772 cache_file_path, 1770 cache_file_path,
1773 params.mime_type, 1771 params.mime_type,
1774 REGULAR_FILE)); 1772 REGULAR_FILE));
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3220 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT); 3218 DCHECK(sub_dir_type == GDataRootDirectory::CACHE_TYPE_PERSISTENT);
3221 base_name += FilePath::kExtensionSeparator; 3219 base_name += FilePath::kExtensionSeparator;
3222 base_name += kLocallyModifiedFileExtension; 3220 base_name += kLocallyModifiedFileExtension;
3223 } else if (!md5.empty()) { 3221 } else if (!md5.empty()) {
3224 base_name += FilePath::kExtensionSeparator; 3222 base_name += FilePath::kExtensionSeparator;
3225 base_name += GDataEntry::EscapeUtf8FileName(md5); 3223 base_name += GDataEntry::EscapeUtf8FileName(md5);
3226 } 3224 }
3227 return cache_paths_[sub_dir_type].Append(base_name); 3225 return cache_paths_[sub_dir_type].Append(base_name);
3228 } 3226 }
3229 3227
3230 void GDataFileSystem::GetFileFromCacheByResourceIdAndMd5(
3231 const std::string& resource_id,
3232 const std::string& md5,
3233 const GetFileFromCacheCallback& callback) {
3234 GetFileFromCacheByResourceIdAndMd5Internal(
3235 resource_id, md5, FilePath(), callback);
3236 }
3237
3238 void GDataFileSystem::StoreToCache(const std::string& resource_id, 3228 void GDataFileSystem::StoreToCache(const std::string& resource_id,
3239 const std::string& md5, 3229 const std::string& md5,
3240 const FilePath& source_path, 3230 const FilePath& source_path,
3241 FileOperationType file_operation_type, 3231 FileOperationType file_operation_type,
3242 const CacheOperationCallback& callback) { 3232 const CacheOperationCallback& callback) {
3243 InitializeCacheIfNecessary(); 3233 InitializeCacheIfNecessary();
3244 3234
3245 base::PlatformFileError* error = 3235 base::PlatformFileError* error =
3246 new base::PlatformFileError(base::PLATFORM_FILE_OK); 3236 new base::PlatformFileError(base::PLATFORM_FILE_OK);
3247 PostBlockingPoolSequencedTaskAndReply( 3237 PostBlockingPoolSequencedTaskAndReply(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
3326 resource_id, 3316 resource_id,
3327 md5, 3317 md5,
3328 FILE_OPERATION_MOVE, 3318 FILE_OPERATION_MOVE,
3329 error, 3319 error,
3330 cache_file_path), 3320 cache_file_path),
3331 base::Bind(&RunGetFileFromCacheCallbackHelper, 3321 base::Bind(&RunGetFileFromCacheCallbackHelper,
3332 callback, 3322 callback,
3333 base::Owned(error), 3323 base::Owned(error),
3334 resource_id, 3324 resource_id,
3335 md5, 3325 md5,
3336 FilePath() /* gdata_file_path */,
3337 base::Owned(cache_file_path))); 3326 base::Owned(cache_file_path)));
3338 } 3327 }
3339 3328
3340 void GDataFileSystem::CommitDirtyInCache( 3329 void GDataFileSystem::CommitDirtyInCache(
3341 const std::string& resource_id, 3330 const std::string& resource_id,
3342 const std::string& md5, 3331 const std::string& md5,
3343 const CacheOperationCallback& callback) { 3332 const CacheOperationCallback& callback) {
3344 InitializeCacheIfNecessary(); 3333 InitializeCacheIfNecessary();
3345 3334
3346 base::PlatformFileError* error = 3335 base::PlatformFileError* error =
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 // Lock to update cache map. 3435 // Lock to update cache map.
3447 base::AutoLock lock(lock_); 3436 base::AutoLock lock(lock_);
3448 root_->SetCacheMap(cache_map); 3437 root_->SetCacheMap(cache_map);
3449 3438
3450 NotifyCacheInitialized(); 3439 NotifyCacheInitialized();
3451 } 3440 }
3452 3441
3453 void GDataFileSystem::GetFileFromCacheOnIOThreadPool( 3442 void GDataFileSystem::GetFileFromCacheOnIOThreadPool(
3454 const std::string& resource_id, 3443 const std::string& resource_id,
3455 const std::string& md5, 3444 const std::string& md5,
3456 const FilePath& gdata_file_path,
3457 base::PlatformFileError* error, 3445 base::PlatformFileError* error,
3458 FilePath* cache_file_path) { 3446 FilePath* cache_file_path) {
3459 DCHECK(error); 3447 DCHECK(error);
3460 DCHECK(cache_file_path); 3448 DCHECK(cache_file_path);
3461 3449
3462 // Lock to access cache map. 3450 // Lock to access cache map.
3463 base::AutoLock lock(lock_); 3451 base::AutoLock lock(lock_);
3464 3452
3465 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id, 3453 GDataRootDirectory::CacheEntry* entry = root_->GetCacheEntry(resource_id,
3466 md5); 3454 md5);
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 cache_state = GDataFile::SetCachePresent(cache_state); 4212 cache_state = GDataFile::SetCachePresent(cache_state);
4225 } 4213 }
4226 4214
4227 // Create and insert new entry into cache map. 4215 // Create and insert new entry into cache map.
4228 GDataRootDirectory::CacheEntry* entry = new GDataRootDirectory::CacheEntry( 4216 GDataRootDirectory::CacheEntry* entry = new GDataRootDirectory::CacheEntry(
4229 md5, sub_dir_type, cache_state); 4217 md5, sub_dir_type, cache_state);
4230 cache_map->insert(std::make_pair(resource_id, entry)); 4218 cache_map->insert(std::make_pair(resource_id, entry));
4231 } 4219 }
4232 } 4220 }
4233 4221
4234 void GDataFileSystem::GetFileFromCacheByResourceIdAndMd5Internal( 4222 void GDataFileSystem::GetFileFromCacheByResourceIdAndMd5(
4235 const std::string& resource_id, 4223 const std::string& resource_id,
4236 const std::string& md5, 4224 const std::string& md5,
4237 const FilePath& gdata_file_path,
4238 const GetFileFromCacheCallback& callback) { 4225 const GetFileFromCacheCallback& callback) {
4239 InitializeCacheIfNecessary(); 4226 InitializeCacheIfNecessary();
4240 4227
4241 base::PlatformFileError* error = 4228 base::PlatformFileError* error =
4242 new base::PlatformFileError(base::PLATFORM_FILE_OK); 4229 new base::PlatformFileError(base::PLATFORM_FILE_OK);
4243 FilePath* cache_file_path = new FilePath; 4230 FilePath* cache_file_path = new FilePath;
4244 PostBlockingPoolSequencedTaskAndReply( 4231 PostBlockingPoolSequencedTaskAndReply(
4245 kGDataFileSystemToken, 4232 kGDataFileSystemToken,
4246 FROM_HERE, 4233 FROM_HERE,
4247 base::Bind(&GDataFileSystem::GetFileFromCacheOnIOThreadPool, 4234 base::Bind(&GDataFileSystem::GetFileFromCacheOnIOThreadPool,
4248 base::Unretained(this), 4235 base::Unretained(this),
4249 resource_id, 4236 resource_id,
4250 md5, 4237 md5,
4251 gdata_file_path,
4252 error, 4238 error,
4253 cache_file_path), 4239 cache_file_path),
4254 base::Bind(&RunGetFileFromCacheCallbackHelper, 4240 base::Bind(&RunGetFileFromCacheCallbackHelper,
4255 callback, 4241 callback,
4256 base::Owned(error), 4242 base::Owned(error),
4257 resource_id, 4243 resource_id,
4258 md5, 4244 md5,
4259 gdata_file_path,
4260 base::Owned(cache_file_path))); 4245 base::Owned(cache_file_path)));
4261 } 4246 }
4262 4247
4263 void GDataFileSystem::RunTaskOnIOThreadPool(const base::Closure& task) { 4248 void GDataFileSystem::RunTaskOnIOThreadPool(const base::Closure& task) {
4264 task.Run(); 4249 task.Run();
4265 4250
4266 { 4251 {
4267 base::AutoLock lock(num_pending_tasks_lock_); 4252 base::AutoLock lock(num_pending_tasks_lock_);
4268 --num_pending_tasks_; 4253 --num_pending_tasks_;
4269 // Signal when the last task is completed. 4254 // Signal when the last task is completed.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4321 pref_registrar_->Init(profile_->GetPrefs()); 4306 pref_registrar_->Init(profile_->GetPrefs());
4322 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); 4307 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this);
4323 } 4308 }
4324 4309
4325 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { 4310 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) {
4326 delete global_free_disk_getter_for_testing; // Safe to delete NULL; 4311 delete global_free_disk_getter_for_testing; // Safe to delete NULL;
4327 global_free_disk_getter_for_testing = getter; 4312 global_free_disk_getter_for_testing = getter;
4328 } 4313 }
4329 4314
4330 } // namespace gdata 4315 } // 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