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/drive/file_cache.h" | 5 #include "chrome/browser/chromeos/drive/file_cache.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_enumerator.h" |
11 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
14 #include "chrome/browser/chromeos/drive/drive.pb.h" | 15 #include "chrome/browser/chromeos/drive/drive.pb.h" |
15 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 16 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
16 #include "chrome/browser/chromeos/drive/file_system_util.h" | 17 #include "chrome/browser/chromeos/drive/file_system_util.h" |
17 #include "chrome/browser/chromeos/drive/mock_file_cache_observer.h" | 18 #include "chrome/browser/chromeos/drive/mock_file_cache_observer.h" |
18 #include "chrome/browser/chromeos/drive/test_util.h" | 19 #include "chrome/browser/chromeos/drive/test_util.h" |
19 #include "chrome/browser/google_apis/test_util.h" | 20 #include "chrome/browser/google_apis/test_util.h" |
20 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 cache_->RemoveOnUIThread( | 156 cache_->RemoveOnUIThread( |
156 resource_id, | 157 resource_id, |
157 google_apis::test_util::CreateCopyResultCallback(&error)); | 158 google_apis::test_util::CreateCopyResultCallback(&error)); |
158 google_apis::test_util::RunBlockingPoolTask(); | 159 google_apis::test_util::RunBlockingPoolTask(); |
159 VerifyRemoveFromCache(error, resource_id, ""); | 160 VerifyRemoveFromCache(error, resource_id, ""); |
160 } | 161 } |
161 | 162 |
162 // Returns number of files matching to |path_pattern|. | 163 // Returns number of files matching to |path_pattern|. |
163 int CountFilesWithPathPattern(const base::FilePath& path_pattern) { | 164 int CountFilesWithPathPattern(const base::FilePath& path_pattern) { |
164 int result = 0; | 165 int result = 0; |
165 file_util::FileEnumerator enumerator( | 166 base::FileEnumerator enumerator( |
166 path_pattern.DirName(), false /* not recursive*/, | 167 path_pattern.DirName(), false /* not recursive*/, |
167 file_util::FileEnumerator::FILES, | 168 base::FileEnumerator::FILES, |
168 path_pattern.BaseName().value()); | 169 path_pattern.BaseName().value()); |
169 for (base::FilePath current = enumerator.Next(); !current.empty(); | 170 for (base::FilePath current = enumerator.Next(); !current.empty(); |
170 current = enumerator.Next()) | 171 current = enumerator.Next()) |
171 ++result; | 172 ++result; |
172 return result; | 173 return result; |
173 } | 174 } |
174 | 175 |
175 void VerifyRemoveFromCache(FileError error, | 176 void VerifyRemoveFromCache(FileError error, |
176 const std::string& resource_id, | 177 const std::string& resource_id, |
177 const std::string& md5) { | 178 const std::string& md5) { |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 // Returns the number of the cache files with name <resource_id>, and Confirm | 475 // Returns the number of the cache files with name <resource_id>, and Confirm |
475 // that they have the <md5>. This should return 1 or 0. | 476 // that they have the <md5>. This should return 1 or 0. |
476 size_t CountCacheFiles(const std::string& resource_id, | 477 size_t CountCacheFiles(const std::string& resource_id, |
477 const std::string& md5) { | 478 const std::string& md5) { |
478 base::FilePath path = GetCacheFilePath( | 479 base::FilePath path = GetCacheFilePath( |
479 resource_id, "*", | 480 resource_id, "*", |
480 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? | 481 (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? |
481 FileCache::CACHE_TYPE_PERSISTENT : | 482 FileCache::CACHE_TYPE_PERSISTENT : |
482 FileCache::CACHE_TYPE_TMP), | 483 FileCache::CACHE_TYPE_TMP), |
483 FileCache::CACHED_FILE_FROM_SERVER); | 484 FileCache::CACHED_FILE_FROM_SERVER); |
484 file_util::FileEnumerator enumerator(path.DirName(), false, | 485 base::FileEnumerator enumerator(path.DirName(), false, |
485 file_util::FileEnumerator::FILES, | 486 base::FileEnumerator::FILES, |
486 path.BaseName().value()); | 487 path.BaseName().value()); |
487 size_t num_files_found = 0; | 488 size_t num_files_found = 0; |
488 for (base::FilePath current = enumerator.Next(); !current.empty(); | 489 for (base::FilePath current = enumerator.Next(); !current.empty(); |
489 current = enumerator.Next()) { | 490 current = enumerator.Next()) { |
490 ++num_files_found; | 491 ++num_files_found; |
491 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 492 EXPECT_EQ(util::EscapeCacheFileName(resource_id) + |
492 base::FilePath::kExtensionSeparator + | 493 base::FilePath::kExtensionSeparator + |
493 util::EscapeCacheFileName(md5), | 494 util::EscapeCacheFileName(md5), |
494 current.BaseName().value()); | 495 current.BaseName().value()); |
495 } | 496 } |
496 return num_files_found; | 497 return num_files_found; |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1308 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); | 1309 EXPECT_TRUE(cache_->GetCacheEntry(resource_id_pinned, md5_pinned, &entry)); |
1309 EXPECT_TRUE(file_util::PathExists(pinned_path)); | 1310 EXPECT_TRUE(file_util::PathExists(pinned_path)); |
1310 | 1311 |
1311 // Returns false when disk space cannot be freed. | 1312 // Returns false when disk space cannot be freed. |
1312 fake_free_disk_space_getter_->set_default_value(0); | 1313 fake_free_disk_space_getter_->set_default_value(0); |
1313 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); | 1314 EXPECT_FALSE(cache_->FreeDiskSpaceIfNeededFor(kNeededBytes)); |
1314 } | 1315 } |
1315 | 1316 |
1316 } // namespace internal | 1317 } // namespace internal |
1317 } // namespace drive | 1318 } // namespace drive |
OLD | NEW |