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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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. |
242 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, | 242 void RunSetMountedStateCallback(const SetMountedStateCallback& 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 421 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 SetMountedStateCallback& 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(&RunSetMountedStateCallback, |
| 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(error); |
| 1457 file_util::Delete(cache_root_path_, true); |
| 1458 Initialize(); |
| 1459 *error = GDATA_FILE_OK; |
| 1460 } |
| 1461 |
1439 void GDataCache::OnPinned(GDataFileError* error, | 1462 void GDataCache::OnPinned(GDataFileError* error, |
1440 const std::string& resource_id, | 1463 const std::string& resource_id, |
1441 const std::string& md5, | 1464 const std::string& md5, |
1442 const CacheOperationCallback& callback) { | 1465 const CacheOperationCallback& callback) { |
1443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1444 DCHECK(error); | 1467 DCHECK(error); |
1445 | 1468 |
1446 if (!callback.is_null()) | 1469 if (!callback.is_null()) |
1447 callback.Run(*error, resource_id, md5); | 1470 callback.Run(*error, resource_id, md5); |
1448 | 1471 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1548 const GDataCacheEntry& cache_entry) { | 1571 const GDataCacheEntry& cache_entry) { |
1549 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1572 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1550 } | 1573 } |
1551 | 1574 |
1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1575 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1576 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1554 global_free_disk_getter_for_testing = getter; | 1577 global_free_disk_getter_for_testing = getter; |
1555 } | 1578 } |
1556 | 1579 |
1557 } // namespace gdata | 1580 } // namespace gdata |
OLD | NEW |