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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 ui_weak_ptr_, | 567 ui_weak_ptr_, |
568 base::Owned(error), | 568 base::Owned(error), |
569 resource_id, | 569 resource_id, |
570 md5, | 570 md5, |
571 callback)); | 571 callback)); |
572 } | 572 } |
573 | 573 |
574 void GDataCache::SetMountedStateOnUIThread( | 574 void GDataCache::SetMountedStateOnUIThread( |
575 const FilePath& file_path, | 575 const FilePath& file_path, |
576 bool to_mount, | 576 bool to_mount, |
577 const SetMountedStateCallback& callback) { | 577 const ChangeCacheStateCallback& callback) { |
578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
579 | 579 |
580 GDataFileError* error = | 580 GDataFileError* error = |
581 new GDataFileError(GDATA_FILE_OK); | 581 new GDataFileError(GDATA_FILE_OK); |
582 FilePath* cache_file_path = new FilePath; | 582 FilePath* cache_file_path = new FilePath; |
583 blocking_task_runner_->PostTaskAndReply( | 583 blocking_task_runner_->PostTaskAndReply( |
584 FROM_HERE, | 584 FROM_HERE, |
585 base::Bind(&GDataCache::SetMountedState, | 585 base::Bind(&GDataCache::SetMountedState, |
586 base::Unretained(this), | 586 base::Unretained(this), |
587 file_path, | 587 file_path, |
588 to_mount, | 588 to_mount, |
589 error, | 589 error, |
590 cache_file_path), | 590 cache_file_path), |
591 base::Bind(&RunSetMountedStateCallback, | 591 base::Bind(&RunChangeCacheStateCallback, |
592 callback, | 592 callback, |
593 base::Owned(error), | 593 base::Owned(error), |
594 base::Owned(cache_file_path))); | 594 base::Owned(cache_file_path))); |
595 } | 595 } |
596 | 596 |
597 void GDataCache::MarkDirtyOnUIThread(const std::string& resource_id, | 597 void GDataCache::MarkDirtyOnUIThread(const std::string& resource_id, |
598 const std::string& md5, | 598 const std::string& md5, |
599 const GetFileFromCacheCallback& callback) { | 599 const GetFileFromCacheCallback& callback) { |
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
601 | 601 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
676 base::Unretained(this), | 676 base::Unretained(this), |
677 resource_id, | 677 resource_id, |
678 error), | 678 error), |
679 base::Bind(&RunCacheOperationCallback, | 679 base::Bind(&RunCacheOperationCallback, |
680 callback, | 680 callback, |
681 base::Owned(error), | 681 base::Owned(error), |
682 resource_id, | 682 resource_id, |
683 "" /* md5 */)); | 683 "" /* md5 */)); |
684 } | 684 } |
685 | 685 |
686 void GDataCache::ClearAllOnUIThread(const ChangeCacheStateCallback& callback) { | |
687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
688 | |
689 GDataFileError* error = new GDataFileError(GDATA_FILE_OK); | |
690 | |
691 blocking_task_runner_->PostTaskAndReply( | |
692 FROM_HERE, | |
693 base::Bind(&GDataCache::ClearAll, | |
694 base::Unretained(this), | |
695 error), | |
696 base::Bind(&RunChangeCacheStateCallback, | |
697 callback, | |
698 base::Owned(error), | |
699 &cache_root_path_)); | |
700 } | |
701 | |
686 void GDataCache::RequestInitializeOnUIThread() { | 702 void GDataCache::RequestInitializeOnUIThread() { |
687 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
688 | 704 |
689 blocking_task_runner_->PostTask( | 705 blocking_task_runner_->PostTask( |
690 FROM_HERE, | 706 FROM_HERE, |
691 base::Bind(&GDataCache::Initialize, base::Unretained(this))); | 707 base::Bind(&GDataCache::Initialize, base::Unretained(this))); |
692 } | 708 } |
693 | 709 |
694 void GDataCache::ForceRescanOnUIThreadForTesting() { | 710 void GDataCache::ForceRescanOnUIThreadForTesting() { |
695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1429 for (size_t i = 0; i < paths_to_delete.size(); ++i) { | 1445 for (size_t i = 0; i < paths_to_delete.size(); ++i) { |
1430 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); | 1446 DeleteFilesSelectively(paths_to_delete[i], path_to_keep); |
1431 } | 1447 } |
1432 | 1448 |
1433 // Now that all file operations have completed, remove from cache map. | 1449 // Now that all file operations have completed, remove from cache map. |
1434 metadata_->RemoveCacheEntry(resource_id); | 1450 metadata_->RemoveCacheEntry(resource_id); |
1435 | 1451 |
1436 *error = GDATA_FILE_OK; | 1452 *error = GDATA_FILE_OK; |
1437 } | 1453 } |
1438 | 1454 |
1455 void GDataCache::ClearAll(GDataFileError* error) { | |
1456 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
satorux1
2012/08/02 01:03:21
Add this instead: AssertOnSequencedWorkerPool();
yoshiki
2012/08/02 07:12:11
Done.
| |
1457 DCHECK(error); | |
1458 | |
1459 file_util::Delete(cache_root_path_, true); | |
satorux1
2012/08/02 01:04:23
Check the return value?
yoshiki
2012/08/02 07:12:11
Done.
| |
1460 Initialize(); | |
1461 *error = GDATA_FILE_OK; | |
1462 } | |
1463 | |
1439 void GDataCache::OnPinned(GDataFileError* error, | 1464 void GDataCache::OnPinned(GDataFileError* error, |
1440 const std::string& resource_id, | 1465 const std::string& resource_id, |
1441 const std::string& md5, | 1466 const std::string& md5, |
1442 const CacheOperationCallback& callback) { | 1467 const CacheOperationCallback& callback) { |
1443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1444 DCHECK(error); | 1469 DCHECK(error); |
1445 | 1470 |
1446 if (!callback.is_null()) | 1471 if (!callback.is_null()) |
1447 callback.Run(*error, resource_id, md5); | 1472 callback.Run(*error, resource_id, md5); |
1448 | 1473 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 const GDataCacheEntry& cache_entry) { | 1573 const GDataCacheEntry& cache_entry) { |
1549 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1574 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1550 } | 1575 } |
1551 | 1576 |
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1577 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1578 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1554 global_free_disk_getter_for_testing = getter; | 1579 global_free_disk_getter_for_testing = getter; |
1555 } | 1580 } |
1556 | 1581 |
1557 } // namespace gdata | 1582 } // namespace gdata |
OLD | NEW |