| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/cache_storage/cache_storage_manager.h" | 5 #include "content/browser/cache_storage/cache_storage_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.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/guid.h" | 14 #include "base/guid.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
| 17 #include "base/sha1.h" | 17 #include "base/sha1.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
| 21 #include "content/browser/cache_storage/cache_storage.pb.h" | 21 #include "content/browser/cache_storage/cache_storage.pb.h" |
| 22 #include "content/browser/cache_storage/cache_storage_quota_client.h" | 22 #include "content/browser/cache_storage/cache_storage_quota_client.h" |
| 23 #include "content/browser/fileapi/chrome_blob_storage_context.h" | 23 #include "content/browser/fileapi/chrome_blob_storage_context.h" |
| 24 #include "content/browser/quota/mock_quota_manager_proxy.h" | 24 #include "content/browser/quota/mock_quota_manager_proxy.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/cache_storage_usage_info.h" | 26 #include "content/public/browser/cache_storage_usage_info.h" |
| 27 #include "content/public/test/mock_special_storage_policy.h" |
| 27 #include "content/public/test/test_browser_context.h" | 28 #include "content/public/test/test_browser_context.h" |
| 28 #include "content/public/test/test_browser_thread_bundle.h" | 29 #include "content/public/test/test_browser_thread_bundle.h" |
| 29 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 30 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
| 31 #include "net/url_request/url_request_job_factory_impl.h" | 32 #include "net/url_request/url_request_job_factory_impl.h" |
| 32 #include "storage/browser/blob/blob_data_builder.h" | 33 #include "storage/browser/blob/blob_data_builder.h" |
| 33 #include "storage/browser/blob/blob_data_handle.h" | 34 #include "storage/browser/blob/blob_data_handle.h" |
| 34 #include "storage/browser/blob/blob_storage_context.h" | 35 #include "storage/browser/blob/blob_storage_context.h" |
| 35 #include "storage/browser/blob/blob_url_request_job_factory.h" | 36 #include "storage/browser/blob/blob_url_request_job_factory.h" |
| 36 #include "storage/browser/quota/quota_manager_proxy.h" | 37 #include "storage/browser/quota/quota_manager_proxy.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 69 |
| 69 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); | 70 url_request_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
| 70 url_request_job_factory_->SetProtocolHandler( | 71 url_request_job_factory_->SetProtocolHandler( |
| 71 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); | 72 "blob", CreateMockBlobProtocolHandler(blob_storage_context->context())); |
| 72 | 73 |
| 73 net::URLRequestContext* url_request_context = | 74 net::URLRequestContext* url_request_context = |
| 74 browser_context_.GetRequestContext()->GetURLRequestContext(); | 75 browser_context_.GetRequestContext()->GetURLRequestContext(); |
| 75 | 76 |
| 76 url_request_context->set_job_factory(url_request_job_factory_.get()); | 77 url_request_context->set_job_factory(url_request_job_factory_.get()); |
| 77 | 78 |
| 79 if (!MemoryOnly()) |
| 80 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 81 |
| 82 quota_policy_ = new MockSpecialStoragePolicy; |
| 83 mock_quota_manager_ = new MockQuotaManager( |
| 84 MemoryOnly() /* is incognito */, temp_dir_.path(), |
| 85 base::ThreadTaskRunnerHandle::Get().get(), |
| 86 base::ThreadTaskRunnerHandle::Get().get(), quota_policy_.get()); |
| 87 mock_quota_manager_->SetQuota( |
| 88 GURL(origin1_), storage::kStorageTypeTemporary, 1024 * 1024 * 100); |
| 89 mock_quota_manager_->SetQuota( |
| 90 GURL(origin2_), storage::kStorageTypeTemporary, 1024 * 1024 * 100); |
| 91 |
| 78 quota_manager_proxy_ = new MockQuotaManagerProxy( | 92 quota_manager_proxy_ = new MockQuotaManagerProxy( |
| 79 nullptr, base::ThreadTaskRunnerHandle::Get().get()); | 93 mock_quota_manager_.get(), base::ThreadTaskRunnerHandle::Get().get()); |
| 80 | 94 |
| 81 if (MemoryOnly()) { | 95 cache_manager_ = CacheStorageManager::Create( |
| 82 cache_manager_ = CacheStorageManager::Create( | 96 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), |
| 83 base::FilePath(), base::ThreadTaskRunnerHandle::Get(), | 97 quota_manager_proxy_); |
| 84 quota_manager_proxy_); | |
| 85 } else { | |
| 86 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 87 cache_manager_ = CacheStorageManager::Create( | |
| 88 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), | |
| 89 quota_manager_proxy_); | |
| 90 } | |
| 91 | 98 |
| 92 cache_manager_->SetBlobParametersForCache( | 99 cache_manager_->SetBlobParametersForCache( |
| 93 browser_context_.GetRequestContext(), | 100 browser_context_.GetRequestContext(), |
| 94 blob_storage_context->context()->AsWeakPtr()); | 101 blob_storage_context->context()->AsWeakPtr()); |
| 95 } | 102 } |
| 96 | 103 |
| 97 void TearDown() override { | 104 void TearDown() override { |
| 98 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); | 105 quota_manager_proxy_->SimulateQuotaManagerDestroyed(); |
| 99 base::RunLoop().RunUntilIdle(); | 106 base::RunLoop().RunUntilIdle(); |
| 100 } | 107 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 307 |
| 301 protected: | 308 protected: |
| 302 // Temporary directory must be allocated first so as to be destroyed last. | 309 // Temporary directory must be allocated first so as to be destroyed last. |
| 303 base::ScopedTempDir temp_dir_; | 310 base::ScopedTempDir temp_dir_; |
| 304 | 311 |
| 305 TestBrowserContext browser_context_; | 312 TestBrowserContext browser_context_; |
| 306 TestBrowserThreadBundle browser_thread_bundle_; | 313 TestBrowserThreadBundle browser_thread_bundle_; |
| 307 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; | 314 scoped_ptr<net::URLRequestJobFactoryImpl> url_request_job_factory_; |
| 308 storage::BlobStorageContext* blob_storage_context_; | 315 storage::BlobStorageContext* blob_storage_context_; |
| 309 | 316 |
| 317 scoped_refptr<MockSpecialStoragePolicy> quota_policy_; |
| 318 scoped_refptr<MockQuotaManager> mock_quota_manager_; |
| 310 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; | 319 scoped_refptr<MockQuotaManagerProxy> quota_manager_proxy_; |
| 311 scoped_ptr<CacheStorageManager> cache_manager_; | 320 scoped_ptr<CacheStorageManager> cache_manager_; |
| 312 | 321 |
| 313 scoped_refptr<CacheStorageCache> callback_cache_; | 322 scoped_refptr<CacheStorageCache> callback_cache_; |
| 314 int callback_bool_; | 323 int callback_bool_; |
| 315 CacheStorageError callback_error_; | 324 CacheStorageError callback_error_; |
| 316 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; | 325 scoped_ptr<ServiceWorkerResponse> callback_cache_response_; |
| 317 scoped_ptr<storage::BlobDataHandle> callback_data_handle_; | 326 scoped_ptr<storage::BlobDataHandle> callback_data_handle_; |
| 318 std::vector<std::string> callback_strings_; | 327 std::vector<std::string> callback_strings_; |
| 319 | 328 |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 | 1004 |
| 996 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, | 1005 INSTANTIATE_TEST_CASE_P(CacheStorageManagerTests, |
| 997 CacheStorageManagerTestP, | 1006 CacheStorageManagerTestP, |
| 998 ::testing::Values(false, true)); | 1007 ::testing::Values(false, true)); |
| 999 | 1008 |
| 1000 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, | 1009 INSTANTIATE_TEST_CASE_P(CacheStorageQuotaClientTests, |
| 1001 CacheStorageQuotaClientTestP, | 1010 CacheStorageQuotaClientTestP, |
| 1002 ::testing::Values(false, true)); | 1011 ::testing::Values(false, true)); |
| 1003 | 1012 |
| 1004 } // namespace content | 1013 } // namespace content |
| OLD | NEW |