| 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/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| 11 #include "base/files/file_enumerator.h" | 11 #include "base/files/file_enumerator.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
| 14 #include "base/md5.h" | 14 #include "base/md5.h" |
| 15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
| 16 #include "base/single_thread_task_runner.h" |
| 17 #include "base/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/chromeos/drive/drive.pb.h" | 18 #include "chrome/browser/chromeos/drive/drive.pb.h" |
| 17 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 19 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
| 18 #include "chrome/browser/chromeos/drive/file_system_util.h" | 20 #include "chrome/browser/chromeos/drive/file_system_util.h" |
| 19 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" | 21 #include "chrome/browser/chromeos/drive/resource_metadata_storage.h" |
| 20 #include "chrome/browser/chromeos/drive/test_util.h" | 22 #include "chrome/browser/chromeos/drive/test_util.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "google_apis/drive/test_util.h" | 24 #include "google_apis/drive/test_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 26 |
| 25 namespace drive { | 27 namespace drive { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 37 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 39 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 38 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); | 40 const base::FilePath metadata_dir = temp_dir_.path().AppendASCII("meta"); |
| 39 cache_files_dir_ = temp_dir_.path().AppendASCII(kCacheFileDirectory); | 41 cache_files_dir_ = temp_dir_.path().AppendASCII(kCacheFileDirectory); |
| 40 | 42 |
| 41 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); | 43 ASSERT_TRUE(base::CreateDirectory(metadata_dir)); |
| 42 ASSERT_TRUE(base::CreateDirectory(cache_files_dir_)); | 44 ASSERT_TRUE(base::CreateDirectory(cache_files_dir_)); |
| 43 | 45 |
| 44 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); | 46 fake_free_disk_space_getter_.reset(new FakeFreeDiskSpaceGetter); |
| 45 | 47 |
| 46 metadata_storage_.reset(new ResourceMetadataStorage( | 48 metadata_storage_.reset(new ResourceMetadataStorage( |
| 47 metadata_dir, | 49 metadata_dir, base::ThreadTaskRunnerHandle::Get())); |
| 48 base::MessageLoopProxy::current().get())); | |
| 49 ASSERT_TRUE(metadata_storage_->Initialize()); | 50 ASSERT_TRUE(metadata_storage_->Initialize()); |
| 50 | 51 |
| 51 cache_.reset(new FileCache( | 52 cache_.reset(new FileCache(metadata_storage_.get(), cache_files_dir_, |
| 52 metadata_storage_.get(), | 53 base::ThreadTaskRunnerHandle::Get(), |
| 53 cache_files_dir_, | 54 fake_free_disk_space_getter_.get())); |
| 54 base::MessageLoopProxy::current().get(), | |
| 55 fake_free_disk_space_getter_.get())); | |
| 56 ASSERT_TRUE(cache_->Initialize()); | 55 ASSERT_TRUE(cache_->Initialize()); |
| 57 } | 56 } |
| 58 | 57 |
| 59 static bool RenameCacheFilesToNewFormat(FileCache* cache) { | 58 static bool RenameCacheFilesToNewFormat(FileCache* cache) { |
| 60 return cache->RenameCacheFilesToNewFormat(); | 59 return cache->RenameCacheFilesToNewFormat(); |
| 61 } | 60 } |
| 62 | 61 |
| 63 content::TestBrowserThreadBundle thread_bundle_; | 62 content::TestBrowserThreadBundle thread_bundle_; |
| 64 base::ScopedTempDir temp_dir_; | 63 base::ScopedTempDir temp_dir_; |
| 65 base::FilePath cache_files_dir_; | 64 base::FilePath cache_files_dir_; |
| (...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 | 550 |
| 552 // Clear cache. | 551 // Clear cache. |
| 553 EXPECT_TRUE(cache_->ClearAll()); | 552 EXPECT_TRUE(cache_->ClearAll()); |
| 554 | 553 |
| 555 // Verify that the cache is removed. | 554 // Verify that the cache is removed. |
| 556 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); | 555 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); |
| 557 } | 556 } |
| 558 | 557 |
| 559 } // namespace internal | 558 } // namespace internal |
| 560 } // namespace drive | 559 } // namespace drive |
| OLD | NEW |