| 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_cache.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_cache.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/chromeos/chromeos_version.h" | 9 #include "base/chromeos/chromeos_version.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // Appends |resource_id| ID to |resource_ids| unconditionally. | 231 // Appends |resource_id| ID to |resource_ids| unconditionally. |
| 232 void CollectAnyFile(std::vector<std::string>* resource_ids, | 232 void CollectAnyFile(std::vector<std::string>* resource_ids, |
| 233 const std::string& resource_id, | 233 const std::string& resource_id, |
| 234 const GDataCacheEntry& /* cache_entry */) { | 234 const GDataCacheEntry& /* cache_entry */) { |
| 235 DCHECK(resource_ids); | 235 DCHECK(resource_ids); |
| 236 | 236 |
| 237 resource_ids->push_back(resource_id); | 237 resource_ids->push_back(resource_id); |
| 238 } | 238 } |
| 239 | 239 |
| 240 // Runs callback with pointers dereferenced. | 240 // Runs callback with pointers dereferenced. |
| 241 // Used to implement SetMountedStateOnUIThread. | 241 // Used to implement SetMountedStateOnUIThread and ClearAllOnUIThread. |
| 242 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, | 242 void RunChangeCacheStateCallback(const ChangeCacheStateCallback& callback, |
| 243 GDataFileError* error, | 243 const GDataFileError* error, |
| 244 FilePath* cache_file_path) { | 244 const FilePath* cache_file_path) { |
| 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 246 DCHECK(error); | 246 DCHECK(error); |
| 247 DCHECK(cache_file_path); | 247 DCHECK(cache_file_path); |
| 248 | 248 |
| 249 if (!callback.is_null()) | 249 if (!callback.is_null()) |
| 250 callback.Run(*error, *cache_file_path); | 250 callback.Run(*error, *cache_file_path); |
| 251 } | 251 } |
| 252 | 252 |
| 253 // Runs callback with pointers dereferenced. | 253 // Runs callback with pointers dereferenced. |
| 254 // Used to implement *OnUIThread methods. | 254 // Used to implement *OnUIThread methods. |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 weak_ptr_factory_.GetWeakPtr(), | 566 weak_ptr_factory_.GetWeakPtr(), |
| 567 base::Owned(error), | 567 base::Owned(error), |
| 568 resource_id, | 568 resource_id, |
| 569 md5, | 569 md5, |
| 570 callback)); | 570 callback)); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void GDataCache::SetMountedStateOnUIThread( | 573 void GDataCache::SetMountedStateOnUIThread( |
| 574 const FilePath& file_path, | 574 const FilePath& file_path, |
| 575 bool to_mount, | 575 bool to_mount, |
| 576 const SetMountedStateCallback& callback) { | 576 const ChangeCacheStateCallback& callback) { |
| 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 578 | 578 |
| 579 GDataFileError* error = | 579 GDataFileError* error = |
| 580 new GDataFileError(GDATA_FILE_OK); | 580 new GDataFileError(GDATA_FILE_OK); |
| 581 FilePath* cache_file_path = new FilePath; | 581 FilePath* cache_file_path = new FilePath; |
| 582 blocking_task_runner_->PostTaskAndReply( | 582 blocking_task_runner_->PostTaskAndReply( |
| 583 FROM_HERE, | 583 FROM_HERE, |
| 584 base::Bind(&GDataCache::SetMountedState, | 584 base::Bind(&GDataCache::SetMountedState, |
| 585 base::Unretained(this), | 585 base::Unretained(this), |
| 586 file_path, | 586 file_path, |
| 587 to_mount, | 587 to_mount, |
| 588 error, | 588 error, |
| 589 cache_file_path), | 589 cache_file_path), |
| 590 base::Bind(&RunSetMountedStateCallback, | 590 base::Bind(&RunChangeCacheStateCallback, |
| 591 callback, | 591 callback, |
| 592 base::Owned(error), | 592 base::Owned(error), |
| 593 base::Owned(cache_file_path))); | 593 base::Owned(cache_file_path))); |
| 594 } | 594 } |
| 595 | 595 |
| 596 void GDataCache::MarkDirtyOnUIThread(const std::string& resource_id, | 596 void GDataCache::MarkDirtyOnUIThread(const std::string& resource_id, |
| 597 const std::string& md5, | 597 const std::string& md5, |
| 598 const GetFileFromCacheCallback& callback) { | 598 const GetFileFromCacheCallback& callback) { |
| 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 600 | 600 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 base::Unretained(this), | 675 base::Unretained(this), |
| 676 resource_id, | 676 resource_id, |
| 677 error), | 677 error), |
| 678 base::Bind(&RunCacheOperationCallback, | 678 base::Bind(&RunCacheOperationCallback, |
| 679 callback, | 679 callback, |
| 680 base::Owned(error), | 680 base::Owned(error), |
| 681 resource_id, | 681 resource_id, |
| 682 "" /* md5 */)); | 682 "" /* md5 */)); |
| 683 } | 683 } |
| 684 | 684 |
| 685 void GDataCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { |
| 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 687 |
| 688 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); |
| 689 |
| 690 blocking_task_runner_->PostTaskAndReply( |
| 691 FROM_HERE, |
| 692 base::Bind(&GDataCache::ClearAll, |
| 693 base::Unretained(this), |
| 694 error), |
| 695 base::Bind(&RunChangeCacheStateCallback, |
| 696 callback, |
| 697 base::Owned(error), |
| 698 &cache_root_path_)); |
| 699 } |
| 700 |
| 685 void GDataCache::RequestInitializeOnUIThread() { | 701 void GDataCache::RequestInitializeOnUIThread() { |
| 686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 702 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 687 | 703 |
| 688 blocking_task_runner_->PostTask( | 704 blocking_task_runner_->PostTask( |
| 689 FROM_HERE, | 705 FROM_HERE, |
| 690 base::Bind(&GDataCache::Initialize, base::Unretained(this))); | 706 base::Bind(&GDataCache::Initialize, base::Unretained(this))); |
| 691 } | 707 } |
| 692 | 708 |
| 693 void GDataCache::ForceRescanOnUIThreadForTesting() { | 709 void GDataCache::ForceRescanOnUIThreadForTesting() { |
| 694 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 710 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 for (size_t i = 0; i < paths_to_delete.size(); ++i) { | 1444 for (size_t i = 0; i < paths_to_delete.size(); ++i) { |
| 1429 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); | 1445 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); |
| 1430 } | 1446 } |
| 1431 | 1447 |
| 1432 // Now that all file operations have completed, remove from cache map. | 1448 // Now that all file operations have completed, remove from cache map. |
| 1433 metadata_->RemoveCacheEntry(resource_id); | 1449 metadata_->RemoveCacheEntry(resource_id); |
| 1434 | 1450 |
| 1435 *error = GDATA_FILE_OK; | 1451 *error = GDATA_FILE_OK; |
| 1436 } | 1452 } |
| 1437 | 1453 |
| 1454 void GDataCache::ClearAll(GDataFileError* error) { |
| 1455 AssertOnSequencedWorkerPool(); |
| 1456 DCHECK(error); |
| 1457 |
| 1458 bool success = file_util::Delete(cache_root_path_, true); |
| 1459 Initialize(); |
| 1460 |
| 1461 *error = success ? GDATA_FILE_OK : GDATA_FILE_ERROR_FAILED; |
| 1462 } |
| 1463 |
| 1438 void GDataCache::OnPinned(GDataFileError* error, | 1464 void GDataCache::OnPinned(GDataFileError* error, |
| 1439 const std::string& resource_id, | 1465 const std::string& resource_id, |
| 1440 const std::string& md5, | 1466 const std::string& md5, |
| 1441 const CacheOperationCallback& callback) { | 1467 const CacheOperationCallback& callback) { |
| 1442 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1443 DCHECK(error); | 1469 DCHECK(error); |
| 1444 | 1470 |
| 1445 if (!callback.is_null()) | 1471 if (!callback.is_null()) |
| 1446 callback.Run(*error, resource_id, md5); | 1472 callback.Run(*error, resource_id, md5); |
| 1447 | 1473 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1547 const GDataCacheEntry& cache_entry) { | 1573 const GDataCacheEntry& cache_entry) { |
| 1548 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1574 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
| 1549 } | 1575 } |
| 1550 | 1576 |
| 1551 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1577 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
| 1552 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1578 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
| 1553 global_free_disk_getter_for_testing = getter; | 1579 global_free_disk_getter_for_testing = getter; |
| 1554 } | 1580 } |
| 1555 | 1581 |
| 1556 } // namespace gdata | 1582 } // namespace gdata |
| OLD | NEW |