| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 278     paths_to_verify.push_back(  // Index 1: CACHE_TYPE_PERSISTENT. | 279     paths_to_verify.push_back(  // Index 1: CACHE_TYPE_PERSISTENT. | 
| 279         PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | 280         PathToVerify(cache_->GetCacheFilePath(resource_id, "*", | 
| 280                      FileCache::CACHE_TYPE_PERSISTENT, | 281                      FileCache::CACHE_TYPE_PERSISTENT, | 
| 281                      FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 282                      FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 
| 282     paths_to_verify.push_back(  // Index 2: CACHE_TYPE_OUTGOING. | 283     paths_to_verify.push_back(  // Index 2: CACHE_TYPE_OUTGOING. | 
| 283         PathToVerify(cache_->GetCacheFilePath(resource_id, "", | 284         PathToVerify(cache_->GetCacheFilePath(resource_id, "", | 
| 284                      FileCache::CACHE_TYPE_OUTGOING, | 285                      FileCache::CACHE_TYPE_OUTGOING, | 
| 285                      FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 286                      FileCache::CACHED_FILE_FROM_SERVER), base::FilePath())); | 
| 286     if (!cache_entry_found) { | 287     if (!cache_entry_found) { | 
| 287       for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 288       for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 
| 288         file_util::FileEnumerator enumerator( | 289         base::FileEnumerator enumerator( | 
| 289             paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, | 290             paths_to_verify[i].path_to_scan.DirName(), false /* not recursive*/, | 
| 290             file_util::FileEnumerator::FILES | | 291             base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS, | 
| 291             file_util::FileEnumerator::SHOW_SYM_LINKS, |  | 
| 292             paths_to_verify[i].path_to_scan.BaseName().value()); | 292             paths_to_verify[i].path_to_scan.BaseName().value()); | 
| 293         EXPECT_TRUE(enumerator.Next().empty()); | 293         EXPECT_TRUE(enumerator.Next().empty()); | 
| 294       } | 294       } | 
| 295     } else { | 295     } else { | 
| 296       // Entry is dirty, verify that: | 296       // Entry is dirty, verify that: | 
| 297       // - no files with "<resource_id>.*" exist in tmp dir | 297       // - no files with "<resource_id>.*" exist in tmp dir | 
| 298       // - only 1 "<resource_id>.local" exists in persistent dir | 298       // - only 1 "<resource_id>.local" exists in persistent dir | 
| 299       // - only 1 <resource_id> exists in outgoing dir | 299       // - only 1 <resource_id> exists in outgoing dir | 
| 300       // - if entry is pinned, only 1 <resource_id> exists in pinned dir. | 300       // - if entry is pinned, only 1 <resource_id> exists in pinned dir. | 
| 301 | 301 | 
| 302       // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). | 302       // Change expected_existing_path of CACHE_TYPE_PERSISTENT (index 1). | 
| 303       paths_to_verify[1].expected_existing_path = | 303       paths_to_verify[1].expected_existing_path = | 
| 304           GetCacheFilePath(resource_id, | 304           GetCacheFilePath(resource_id, | 
| 305                            std::string(), | 305                            std::string(), | 
| 306                            FileCache::CACHE_TYPE_PERSISTENT, | 306                            FileCache::CACHE_TYPE_PERSISTENT, | 
| 307                            FileCache::CACHED_FILE_LOCALLY_MODIFIED); | 307                            FileCache::CACHED_FILE_LOCALLY_MODIFIED); | 
| 308 | 308 | 
| 309       // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 2). | 309       // Change expected_existing_path of CACHE_TYPE_OUTGOING (index 2). | 
| 310       paths_to_verify[2].expected_existing_path = | 310       paths_to_verify[2].expected_existing_path = | 
| 311           GetCacheFilePath(resource_id, | 311           GetCacheFilePath(resource_id, | 
| 312                            std::string(), | 312                            std::string(), | 
| 313                            FileCache::CACHE_TYPE_OUTGOING, | 313                            FileCache::CACHE_TYPE_OUTGOING, | 
| 314                            FileCache::CACHED_FILE_FROM_SERVER); | 314                            FileCache::CACHED_FILE_FROM_SERVER); | 
| 315 | 315 | 
| 316       for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 316       for (size_t i = 0; i < paths_to_verify.size(); ++i) { | 
| 317         const struct PathToVerify& verify = paths_to_verify[i]; | 317         const struct PathToVerify& verify = paths_to_verify[i]; | 
| 318         file_util::FileEnumerator enumerator( | 318         base::FileEnumerator enumerator( | 
| 319             verify.path_to_scan.DirName(), false /* not recursive */, | 319             verify.path_to_scan.DirName(), false /* not recursive */, | 
| 320             file_util::FileEnumerator::FILES | | 320             base::FileEnumerator::FILES | base::FileEnumerator::SHOW_SYM_LINKS, | 
| 321             file_util::FileEnumerator::SHOW_SYM_LINKS, |  | 
| 322             verify.path_to_scan.BaseName().value()); | 321             verify.path_to_scan.BaseName().value()); | 
| 323         size_t num_files_found = 0; | 322         size_t num_files_found = 0; | 
| 324         for (base::FilePath current = enumerator.Next(); !current.empty(); | 323         for (base::FilePath current = enumerator.Next(); !current.empty(); | 
| 325              current = enumerator.Next()) { | 324              current = enumerator.Next()) { | 
| 326           ++num_files_found; | 325           ++num_files_found; | 
| 327           EXPECT_EQ(verify.expected_existing_path, current); | 326           EXPECT_EQ(verify.expected_existing_path, current); | 
| 328         } | 327         } | 
| 329         if (verify.expected_existing_path.empty()) | 328         if (verify.expected_existing_path.empty()) | 
| 330           EXPECT_EQ(0U, num_files_found); | 329           EXPECT_EQ(0U, num_files_found); | 
| 331         else | 330         else | 
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 614   // Returns the number of the cache files with name <resource_id>, and Confirm | 613   // Returns the number of the cache files with name <resource_id>, and Confirm | 
| 615   // that they have the <md5>. This should return 1 or 0. | 614   // that they have the <md5>. This should return 1 or 0. | 
| 616   size_t CountCacheFiles(const std::string& resource_id, | 615   size_t CountCacheFiles(const std::string& resource_id, | 
| 617                          const std::string& md5) { | 616                          const std::string& md5) { | 
| 618     base::FilePath path = GetCacheFilePath( | 617     base::FilePath path = GetCacheFilePath( | 
| 619         resource_id, "*", | 618         resource_id, "*", | 
| 620         (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? | 619         (test_util::ToCacheEntry(expected_cache_state_).is_pinned() ? | 
| 621          FileCache::CACHE_TYPE_PERSISTENT : | 620          FileCache::CACHE_TYPE_PERSISTENT : | 
| 622          FileCache::CACHE_TYPE_TMP), | 621          FileCache::CACHE_TYPE_TMP), | 
| 623         FileCache::CACHED_FILE_FROM_SERVER); | 622         FileCache::CACHED_FILE_FROM_SERVER); | 
| 624     file_util::FileEnumerator enumerator(path.DirName(), false, | 623     base::FileEnumerator enumerator(path.DirName(), false, | 
| 625                                          file_util::FileEnumerator::FILES, | 624                                     base::FileEnumerator::FILES, | 
| 626                                          path.BaseName().value()); | 625                                     path.BaseName().value()); | 
| 627     size_t num_files_found = 0; | 626     size_t num_files_found = 0; | 
| 628     for (base::FilePath current = enumerator.Next(); !current.empty(); | 627     for (base::FilePath current = enumerator.Next(); !current.empty(); | 
| 629          current = enumerator.Next()) { | 628          current = enumerator.Next()) { | 
| 630       ++num_files_found; | 629       ++num_files_found; | 
| 631       EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 630       EXPECT_EQ(util::EscapeCacheFileName(resource_id) + | 
| 632                 base::FilePath::kExtensionSeparator + | 631                 base::FilePath::kExtensionSeparator + | 
| 633                 util::EscapeCacheFileName(md5), | 632                 util::EscapeCacheFileName(md5), | 
| 634                 current.BaseName().value()); | 633                 current.BaseName().value()); | 
| 635     } | 634     } | 
| 636     return num_files_found; | 635     return num_files_found; | 
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1405       google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), | 1404       google_apis::test_util::GetTestFilePath("chromeos/gdata/empty_feed.json"), | 
| 1406       FILE_ERROR_OK, | 1405       FILE_ERROR_OK, | 
| 1407       test_util::TEST_CACHE_STATE_PRESENT | | 1406       test_util::TEST_CACHE_STATE_PRESENT | | 
| 1408       test_util::TEST_CACHE_STATE_PINNED | | 1407       test_util::TEST_CACHE_STATE_PINNED | | 
| 1409       test_util::TEST_CACHE_STATE_PERSISTENT, | 1408       test_util::TEST_CACHE_STATE_PERSISTENT, | 
| 1410       FileCache::CACHE_TYPE_PERSISTENT); | 1409       FileCache::CACHE_TYPE_PERSISTENT); | 
| 1411 } | 1410 } | 
| 1412 | 1411 | 
| 1413 }  // namespace internal | 1412 }  // namespace internal | 
| 1414 }  // namespace drive | 1413 }  // namespace drive | 
| OLD | NEW | 
|---|