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 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 // present (cached locally). | 221 // present (cached locally). |
222 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids, | 222 void CollectExistingPinnedFile(std::vector<std::string>* resource_ids, |
223 const std::string& resource_id, | 223 const std::string& resource_id, |
224 const GDataCacheEntry& cache_entry) { | 224 const GDataCacheEntry& cache_entry) { |
225 DCHECK(resource_ids); | 225 DCHECK(resource_ids); |
226 | 226 |
227 if (cache_entry.is_pinned() && cache_entry.is_present()) | 227 if (cache_entry.is_pinned() && cache_entry.is_present()) |
228 resource_ids->push_back(resource_id); | 228 resource_ids->push_back(resource_id); |
229 } | 229 } |
230 | 230 |
| 231 // Appends |resource_id| ID to |resource_ids| unconditionally. |
| 232 void CollectAnyFile(std::vector<std::string>* resource_ids, |
| 233 const std::string& resource_id, |
| 234 const GDataCacheEntry& /* cache_entry */) { |
| 235 DCHECK(resource_ids); |
| 236 |
| 237 resource_ids->push_back(resource_id); |
| 238 } |
| 239 |
231 // Runs callback with pointers dereferenced. | 240 // Runs callback with pointers dereferenced. |
232 // Used to implement SetMountedStateOnUIThread. | 241 // Used to implement SetMountedStateOnUIThread. |
233 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, | 242 void RunSetMountedStateCallback(const SetMountedStateCallback& callback, |
234 GDataFileError* error, | 243 GDataFileError* error, |
235 FilePath* cache_file_path) { | 244 FilePath* cache_file_path) { |
236 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
237 DCHECK(error); | 246 DCHECK(error); |
238 DCHECK(cache_file_path); | 247 DCHECK(cache_file_path); |
239 | 248 |
240 if (!callback.is_null()) | 249 if (!callback.is_null()) |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 blocking_task_runner_->PostTaskAndReply( | 435 blocking_task_runner_->PostTaskAndReply( |
427 FROM_HERE, | 436 FROM_HERE, |
428 base::Bind(&GDataCache::GetResourceIdsOfExistingPinnedFiles, | 437 base::Bind(&GDataCache::GetResourceIdsOfExistingPinnedFiles, |
429 base::Unretained(this), | 438 base::Unretained(this), |
430 resource_ids), | 439 resource_ids), |
431 base::Bind(&RunGetResourceIdsCallback, | 440 base::Bind(&RunGetResourceIdsCallback, |
432 callback, | 441 callback, |
433 base::Owned(resource_ids))); | 442 base::Owned(resource_ids))); |
434 } | 443 } |
435 | 444 |
| 445 void GDataCache::GetResourceIdsOfAllFilesOnUIThread( |
| 446 const GetResourceIdsCallback& callback) { |
| 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 448 |
| 449 std::vector<std::string>* resource_ids = new std::vector<std::string>; |
| 450 blocking_task_runner_->PostTaskAndReply( |
| 451 FROM_HERE, |
| 452 base::Bind(&GDataCache::GetResourceIdsOfAllFiles, |
| 453 base::Unretained(this), |
| 454 resource_ids), |
| 455 base::Bind(&RunGetResourceIdsCallback, |
| 456 callback, |
| 457 base::Owned(resource_ids))); |
| 458 } |
| 459 |
436 void GDataCache::FreeDiskSpaceIfNeededFor(int64 num_bytes, | 460 void GDataCache::FreeDiskSpaceIfNeededFor(int64 num_bytes, |
437 bool* has_enough_space) { | 461 bool* has_enough_space) { |
438 AssertOnSequencedWorkerPool(); | 462 AssertOnSequencedWorkerPool(); |
439 | 463 |
440 // Do nothing and return if we have enough space. | 464 // Do nothing and return if we have enough space. |
441 *has_enough_space = HasEnoughSpaceFor(num_bytes); | 465 *has_enough_space = HasEnoughSpaceFor(num_bytes); |
442 if (*has_enough_space) | 466 if (*has_enough_space) |
443 return; | 467 return; |
444 | 468 |
445 // Otherwise, try to free up the disk space. | 469 // Otherwise, try to free up the disk space. |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 } | 758 } |
735 | 759 |
736 void GDataCache::GetResourceIdsOfExistingPinnedFiles( | 760 void GDataCache::GetResourceIdsOfExistingPinnedFiles( |
737 std::vector<std::string>* resource_ids) { | 761 std::vector<std::string>* resource_ids) { |
738 AssertOnSequencedWorkerPool(); | 762 AssertOnSequencedWorkerPool(); |
739 DCHECK(resource_ids); | 763 DCHECK(resource_ids); |
740 | 764 |
741 metadata_->Iterate(base::Bind(&CollectExistingPinnedFile, resource_ids)); | 765 metadata_->Iterate(base::Bind(&CollectExistingPinnedFile, resource_ids)); |
742 } | 766 } |
743 | 767 |
| 768 void GDataCache::GetResourceIdsOfAllFiles( |
| 769 std::vector<std::string>* resource_ids) { |
| 770 AssertOnSequencedWorkerPool(); |
| 771 DCHECK(resource_ids); |
| 772 |
| 773 metadata_->Iterate(base::Bind(&CollectAnyFile, resource_ids)); |
| 774 } |
| 775 |
744 void GDataCache::GetFile(const std::string& resource_id, | 776 void GDataCache::GetFile(const std::string& resource_id, |
745 const std::string& md5, | 777 const std::string& md5, |
746 GDataFileError* error, | 778 GDataFileError* error, |
747 FilePath* cache_file_path) { | 779 FilePath* cache_file_path) { |
748 AssertOnSequencedWorkerPool(); | 780 AssertOnSequencedWorkerPool(); |
749 DCHECK(error); | 781 DCHECK(error); |
750 DCHECK(cache_file_path); | 782 DCHECK(cache_file_path); |
751 | 783 |
752 GDataCacheEntry cache_entry; | 784 GDataCacheEntry cache_entry; |
753 if (GetCacheEntry(resource_id, md5, &cache_entry) && | 785 if (GetCacheEntry(resource_id, md5, &cache_entry) && |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 const GDataCacheEntry& cache_entry) { | 1548 const GDataCacheEntry& cache_entry) { |
1517 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1549 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1518 } | 1550 } |
1519 | 1551 |
1520 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1552 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1521 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1553 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1522 global_free_disk_getter_for_testing = getter; | 1554 global_free_disk_getter_for_testing = getter; |
1523 } | 1555 } |
1524 | 1556 |
1525 } // namespace gdata | 1557 } // namespace gdata |
OLD | NEW |