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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 callback.Run(*success, *cache_entry); | 317 callback.Run(*success, *cache_entry); |
318 } | 318 } |
319 | 319 |
320 } // namespace | 320 } // namespace |
321 | 321 |
322 GDataCache::GDataCache(const FilePath& cache_root_path, | 322 GDataCache::GDataCache(const FilePath& cache_root_path, |
323 base::SequencedTaskRunner* blocking_task_runner) | 323 base::SequencedTaskRunner* blocking_task_runner) |
324 : cache_root_path_(cache_root_path), | 324 : cache_root_path_(cache_root_path), |
325 cache_paths_(GetCachePaths(cache_root_path_)), | 325 cache_paths_(GetCachePaths(cache_root_path_)), |
326 blocking_task_runner_(blocking_task_runner), | 326 blocking_task_runner_(blocking_task_runner), |
327 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 327 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 328 force_metadata_map_for_testing_(false) { |
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
329 } | 330 } |
330 | 331 |
331 GDataCache::~GDataCache() { | 332 GDataCache::~GDataCache() { |
332 AssertOnSequencedWorkerPool(); | 333 AssertOnSequencedWorkerPool(); |
333 } | 334 } |
334 | 335 |
335 FilePath GDataCache::GetCacheDirectoryPath( | 336 FilePath GDataCache::GetCacheDirectoryPath( |
336 CacheSubDirectoryType sub_dir_type) const { | 337 CacheSubDirectoryType sub_dir_type) const { |
337 DCHECK_LE(0, sub_dir_type); | 338 DCHECK_LE(0, sub_dir_type); |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 FROM_HERE, | 742 FROM_HERE, |
742 base::Bind(&GDataCache::Destroy, | 743 base::Bind(&GDataCache::Destroy, |
743 base::Unretained(this))); | 744 base::Unretained(this))); |
744 } | 745 } |
745 | 746 |
746 void GDataCache::Initialize() { | 747 void GDataCache::Initialize() { |
747 AssertOnSequencedWorkerPool(); | 748 AssertOnSequencedWorkerPool(); |
748 | 749 |
749 InitCachePaths(cache_paths_); | 750 InitCachePaths(cache_paths_); |
750 metadata_ = GDataCacheMetadata::CreateGDataCacheMetadata( | 751 metadata_ = GDataCacheMetadata::CreateGDataCacheMetadata( |
751 blocking_task_runner_).Pass(); | 752 blocking_task_runner_, force_metadata_map_for_testing_).Pass(); |
752 metadata_->Initialize(cache_paths_); | 753 metadata_->Initialize(cache_paths_); |
753 } | 754 } |
754 | 755 |
755 void GDataCache::Destroy() { | 756 void GDataCache::Destroy() { |
756 AssertOnSequencedWorkerPool(); | 757 AssertOnSequencedWorkerPool(); |
757 delete this; | 758 delete this; |
758 } | 759 } |
759 | 760 |
760 void GDataCache::ForceRescanForTesting() { | 761 void GDataCache::ForceRescanForTesting() { |
761 AssertOnSequencedWorkerPool(); | 762 AssertOnSequencedWorkerPool(); |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 const std::string& md5, | 1518 const std::string& md5, |
1518 bool* success, | 1519 bool* success, |
1519 GDataCacheEntry* cache_entry) { | 1520 GDataCacheEntry* cache_entry) { |
1520 AssertOnSequencedWorkerPool(); | 1521 AssertOnSequencedWorkerPool(); |
1521 DCHECK(success); | 1522 DCHECK(success); |
1522 DCHECK(cache_entry); | 1523 DCHECK(cache_entry); |
1523 | 1524 |
1524 *success = GetCacheEntry(resource_id, md5, cache_entry); | 1525 *success = GetCacheEntry(resource_id, md5, cache_entry); |
1525 } | 1526 } |
1526 | 1527 |
| 1528 void GDataCache::ForceMetadataMapForTesting() { |
| 1529 force_metadata_map_for_testing_ = true; |
| 1530 } |
| 1531 |
1527 // static | 1532 // static |
1528 FilePath GDataCache::GetCacheRootPath(Profile* profile) { | 1533 FilePath GDataCache::GetCacheRootPath(Profile* profile) { |
1529 FilePath cache_base_path; | 1534 FilePath cache_base_path; |
1530 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); | 1535 chrome::GetUserCacheDirectory(profile->GetPath(), &cache_base_path); |
1531 FilePath cache_root_path = | 1536 FilePath cache_root_path = |
1532 cache_base_path.Append(chrome::kGDataCacheDirname); | 1537 cache_base_path.Append(chrome::kGDataCacheDirname); |
1533 return cache_root_path.Append(kGDataCacheVersionDir); | 1538 return cache_root_path.Append(kGDataCacheVersionDir); |
1534 } | 1539 } |
1535 | 1540 |
1536 // static | 1541 // static |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 const GDataCacheEntry& cache_entry) { | 1578 const GDataCacheEntry& cache_entry) { |
1574 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; | 1579 return cache_entry.is_persistent() ? CACHE_TYPE_PERSISTENT : CACHE_TYPE_TMP; |
1575 } | 1580 } |
1576 | 1581 |
1577 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { | 1582 void SetFreeDiskSpaceGetterForTesting(FreeDiskSpaceGetterInterface* getter) { |
1578 delete global_free_disk_getter_for_testing; // Safe to delete NULL; | 1583 delete global_free_disk_getter_for_testing; // Safe to delete NULL; |
1579 global_free_disk_getter_for_testing = getter; | 1584 global_free_disk_getter_for_testing = getter; |
1580 } | 1585 } |
1581 | 1586 |
1582 } // namespace gdata | 1587 } // namespace gdata |
OLD | NEW |