diff options
Diffstat (limited to 'chromium/content/browser/appcache')
31 files changed, 509 insertions, 247 deletions
diff --git a/chromium/content/browser/appcache/appcache_backend_impl.cc b/chromium/content/browser/appcache/appcache_backend_impl.cc index 84ba55ae3e0..c0dcd76fda6 100644 --- a/chromium/content/browser/appcache/appcache_backend_impl.cc +++ b/chromium/content/browser/appcache/appcache_backend_impl.cc @@ -9,6 +9,7 @@ #include <utility> #include <vector> +#include "base/debug/dump_without_crashing.h" #include "content/browser/appcache/appcache.h" #include "content/browser/appcache/appcache_group.h" #include "content/browser/appcache/appcache_service_impl.h" @@ -20,8 +21,17 @@ namespace content { AppCacheBackendImpl::AppCacheBackendImpl(AppCacheServiceImpl* service, int process_id, int routing_id) - : service_(service), process_id_(process_id), routing_id_(routing_id) { + : service_(service), + process_id_(process_id), + routing_id_(routing_id), + security_policy_handle_( + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + process_id)) { DCHECK(service); + DCHECK(security_policy_handle_.is_valid()); + + if (!security_policy_handle_.is_valid()) + base::debug::DumpWithoutCrashing(); } AppCacheBackendImpl::~AppCacheBackendImpl() = default; @@ -32,6 +42,7 @@ void AppCacheBackendImpl::RegisterHost( const base::UnguessableToken& host_id) { service_->RegisterHost(std::move(host_receiver), std::move(frontend_remote), host_id, routing_id_, process_id_, + security_policy_handle_.Duplicate(), mojo::GetBadMessageCallback()); } diff --git a/chromium/content/browser/appcache/appcache_backend_impl.h b/chromium/content/browser/appcache/appcache_backend_impl.h index 6d759c2117b..bc4cfdbf098 100644 --- a/chromium/content/browser/appcache/appcache_backend_impl.h +++ b/chromium/content/browser/appcache/appcache_backend_impl.h @@ -9,6 +9,7 @@ #include <memory> #include "content/browser/appcache/appcache_host.h" +#include "content/browser/child_process_security_policy_impl.h" #include "content/common/content_export.h" #include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_remote.h" @@ -38,6 +39,7 @@ class CONTENT_EXPORT AppCacheBackendImpl AppCacheServiceImpl* service_; const int process_id_; const int routing_id_; + ChildProcessSecurityPolicyImpl::Handle security_policy_handle_; DISALLOW_COPY_AND_ASSIGN(AppCacheBackendImpl); }; diff --git a/chromium/content/browser/appcache/appcache_browsertest.cc b/chromium/content/browser/appcache/appcache_browsertest.cc index c20d15e6fef..5c96deb7e85 100644 --- a/chromium/content/browser/appcache/appcache_browsertest.cc +++ b/chromium/content/browser/appcache/appcache_browsertest.cc @@ -98,8 +98,9 @@ IN_PROC_BROWSER_TEST_F( } // Regression test for crbug.com/937761. +// Disabled due to flakiness https://crbug.com/1031090. IN_PROC_BROWSER_TEST_F(AppCacheNetworkServiceBrowserTest, - SSLCertificateCachedCorrectly) { + DISABLED_SSLCertificateCachedCorrectly) { net::EmbeddedTestServer embedded_test_server( net::EmbeddedTestServer::TYPE_HTTPS); embedded_test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, @@ -273,8 +274,9 @@ class LoaderFactoryInterceptingBrowserClient : public TestContentBrowserClient { std::vector<std::unique_ptr<PassThroughURLLoaderFactory>> proxies_; }; +// Timeout waiting for "AppCache updated" title (http://crbug.com/1080708). IN_PROC_BROWSER_TEST_F(AppCacheNetworkServiceBrowserTest, - AppCacheRequestsAreProxied) { + DISABLED_AppCacheRequestsAreProxied) { LoaderFactoryInterceptingBrowserClient browser_client; ContentBrowserClient* original_client = SetBrowserClientForTesting(&browser_client); diff --git a/chromium/content/browser/appcache/appcache_cache_test_helper_unittest.cc b/chromium/content/browser/appcache/appcache_cache_test_helper_unittest.cc index 99cdce2c306..c37aee36ce8 100644 --- a/chromium/content/browser/appcache/appcache_cache_test_helper_unittest.cc +++ b/chromium/content/browser/appcache/appcache_cache_test_helper_unittest.cc @@ -19,7 +19,6 @@ #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" -#include "base/task/post_task.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" @@ -31,6 +30,7 @@ #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/storage_partition_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" #include "mojo/public/cpp/bindings/pending_remote.h" @@ -226,8 +226,8 @@ class AppCacheCacheTestHelperTest : public testing::Test { void RunTestOnUIThread(Method method) { base::RunLoop run_loop; test_completed_cb_ = run_loop.QuitClosure(); - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(method, base::Unretained(this))); + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(method, base::Unretained(this))); run_loop.Run(); } @@ -355,6 +355,8 @@ class AppCacheCacheTestHelperTest : public testing::Test { constexpr int kRenderFrameIdForTests = 456; hosts_.push_back(std::make_unique<AppCacheHost>( base::UnguessableToken::Create(), process_id_, kRenderFrameIdForTests, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + process_id_), mojo::NullRemote(), service_.get())); hosts_.back()->set_frontend_for_testing(frontend); return hosts_.back().get(); diff --git a/chromium/content/browser/appcache/appcache_entry.h b/chromium/content/browser/appcache/appcache_entry.h index 7593f731751..f15f7fb30fd 100644 --- a/chromium/content/browser/appcache/appcache_entry.h +++ b/chromium/content/browser/appcache/appcache_entry.h @@ -7,7 +7,7 @@ #include <stdint.h> -#include "base/logging.h" +#include "base/check_op.h" #include "third_party/blink/public/mojom/appcache/appcache_info.mojom-forward.h" namespace content { diff --git a/chromium/content/browser/appcache/appcache_fuzzer.cc b/chromium/content/browser/appcache/appcache_fuzzer.cc index 31c5dc5c153..41f600ff0d8 100644 --- a/chromium/content/browser/appcache/appcache_fuzzer.cc +++ b/chromium/content/browser/appcache/appcache_fuzzer.cc @@ -8,12 +8,12 @@ #include "base/i18n/icu_util.h" #include "base/macros.h" #include "base/no_destructor.h" -#include "base/task/post_task.h" #include "base/test/test_timeouts.h" #include "content/browser/appcache/appcache_fuzzer.pb.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/child_process_security_policy_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" #include "content/test/test_content_browser_client.h" @@ -56,8 +56,8 @@ struct Env { appcache_service = base::MakeRefCounted<ChromeAppCacheService>( /*proxy=*/nullptr, /*partition=*/nullptr); - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&ChromeAppCacheService::Initialize, appcache_service, base::FilePath(), &test_browser_context, /*special_storage_policy=*/nullptr)); diff --git a/chromium/content/browser/appcache/appcache_group_unittest.cc b/chromium/content/browser/appcache/appcache_group_unittest.cc index 41689b58544..60b2e1fd8ec 100644 --- a/chromium/content/browser/appcache/appcache_group_unittest.cc +++ b/chromium/content/browser/appcache/appcache_group_unittest.cc @@ -88,11 +88,14 @@ class TestAppCacheHost : public AppCacheHost { TestAppCacheHost(const base::UnguessableToken& host_id, TestAppCacheFrontend* frontend, AppCacheServiceImpl* service) - : AppCacheHost(host_id, - /*process_id=*/456, - /*render_frame_id=*/789, - frontend->Bind(host_id), - service), + : AppCacheHost( + host_id, + /*process_id=*/456, + /*render_frame_id=*/789, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + /*process_id=*/456), + frontend->Bind(host_id), + service), update_completed_(false) {} void OnUpdateComplete(AppCacheGroup* group) override { @@ -184,13 +187,19 @@ TEST_F(AppCacheGroupTest, CleanupUnusedGroup) { new AppCacheGroup(service.storage(), GURL("http://foo.com"), 111); auto host1_id = base::UnguessableToken::Create(); - AppCacheHost host1(host1_id, - /*process_id=*/1, /*render_frame_id=*/1, - frontend.Bind(host1_id), &service); + const int kMockProcessId1 = 1; + const int kMockProcessId2 = 2; + AppCacheHost host1( + host1_id, kMockProcessId1, /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + frontend.Bind(host1_id), &service); auto host2_id = base::UnguessableToken::Create(); - AppCacheHost host2(host2_id, - /*process_id=*/2, /*render_frame_id=*/2, - frontend.Bind(host2_id), &service); + AppCacheHost host2( + host2_id, kMockProcessId2, /*render_frame_id=*/2, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId2), + frontend.Bind(host2_id), &service); base::Time now = base::Time::Now(); diff --git a/chromium/content/browser/appcache/appcache_host.cc b/chromium/content/browser/appcache/appcache_host.cc index 4268404fba4..91d1cc04c0d 100644 --- a/chromium/content/browser/appcache/appcache_host.cc +++ b/chromium/content/browser/appcache/appcache_host.cc @@ -8,6 +8,7 @@ #include <vector> #include "base/check_op.h" +#include "base/debug/dump_without_crashing.h" #include "base/memory/ptr_util.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -20,6 +21,7 @@ #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/web_contents/web_contents_impl.h" #include "content/common/appcache_interfaces.h" +#include "content/public/browser/browser_thread.h" #include "content/public/common/content_client.h" #include "content/public/common/url_constants.h" #include "net/url_request/url_request.h" @@ -82,10 +84,12 @@ AppCacheHost::AppCacheHost( const base::UnguessableToken& host_id, int process_id, int render_frame_id, + SecurityPolicyHandle security_policy_handle, mojo::PendingRemote<blink::mojom::AppCacheFrontend> frontend_remote, AppCacheServiceImpl* service) : host_id_(host_id), process_id_(process_id), + security_policy_handle_(std::move(security_policy_handle)), pending_main_resource_cache_id_(blink::mojom::kAppCacheNoCacheId), pending_selected_cache_id_(blink::mojom::kAppCacheNoCacheId), was_select_cache_called_(false), @@ -99,10 +103,9 @@ AppCacheHost::AppCacheHost( main_resource_blocked_(false), associated_cache_info_pending_(false) { service_->AddObserver(this); - if (process_id_ != ChildProcessHost::kInvalidUniqueID) { - security_policy_handle_ = - ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( - process_id_); + if (process_id_ != ChildProcessHost::kInvalidUniqueID && + !security_policy_handle_.is_valid()) { + base::debug::DumpWithoutCrashing(); } is_origin_trial_required_ = service_->appcache_policy()->IsOriginTrialRequiredForAppCache(); @@ -633,6 +636,8 @@ void AppCacheHost::SetProcessId(int process_id) { process_id_ = process_id; security_policy_handle_ = ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle(process_id_); + if (!security_policy_handle_.is_valid()) + base::debug::DumpWithoutCrashing(); } base::WeakPtr<AppCacheHost> AppCacheHost::GetWeakPtr() { @@ -728,8 +733,8 @@ void AppCacheHost::OnAppCacheAccessed(const GURL& manifest_url, bool blocked) { // informing WebContents about this access. if (render_frame_id_ != MSG_ROUTING_NONE && BrowserThread::IsThreadInitialized(BrowserThread::UI)) { - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce( [](int process_id, int render_frame_id, const GURL& manifest_url, bool blocked) { diff --git a/chromium/content/browser/appcache/appcache_host.h b/chromium/content/browser/appcache/appcache_host.h index 111775d8c80..ab8fd08c206 100644 --- a/chromium/content/browser/appcache/appcache_host.h +++ b/chromium/content/browser/appcache/appcache_host.h @@ -65,6 +65,8 @@ class CONTENT_EXPORT AppCacheHost : public blink::mojom::AppCacheHost, public AppCacheGroup::UpdateObserver, public AppCacheServiceImpl::Observer { public: + using SecurityPolicyHandle = ChildProcessSecurityPolicyImpl::Handle; + class CONTENT_EXPORT Observer { public: Observer(const Observer&) = delete; @@ -87,6 +89,7 @@ class CONTENT_EXPORT AppCacheHost : public blink::mojom::AppCacheHost, const base::UnguessableToken& host_id, int process_id, int render_frame_id, + SecurityPolicyHandle security_policy_handle, mojo::PendingRemote<blink::mojom::AppCacheFrontend> frontend_remote, AppCacheServiceImpl* service); ~AppCacheHost() override; @@ -180,7 +183,6 @@ class CONTENT_EXPORT AppCacheHost : public blink::mojom::AppCacheHost, return process_id_; } - using SecurityPolicyHandle = ChildProcessSecurityPolicyImpl::Handle; SecurityPolicyHandle* security_policy_handle() { return &security_policy_handle_; } diff --git a/chromium/content/browser/appcache/appcache_host_unittest.cc b/chromium/content/browser/appcache/appcache_host_unittest.cc index b7bb68c212f..cb357740862 100644 --- a/chromium/content/browser/appcache/appcache_host_unittest.cc +++ b/chromium/content/browser/appcache/appcache_host_unittest.cc @@ -28,6 +28,7 @@ #include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/test_support/test_utils.h" #include "net/url_request/url_request.h" +#include "storage/browser/quota/quota_client_type.h" #include "storage/browser/quota/quota_manager.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom.h" @@ -115,7 +116,10 @@ class AppCacheHostTest : public testing::Test { MockQuotaManagerProxy() : QuotaManagerProxy(nullptr, nullptr) {} // Not needed for our tests. - void RegisterClient(scoped_refptr<storage::QuotaClient> client) override {} + void RegisterClient( + scoped_refptr<storage::QuotaClient> client, + storage::QuotaClientType client_type, + const std::vector<blink::mojom::StorageType>& storage_types) override {} void NotifyStorageAccessed(const url::Origin& origin, blink::mojom::StorageType type) override {} void NotifyStorageModified(storage::QuotaClientType client_id, @@ -184,6 +188,8 @@ class AppCacheHostTest : public testing::Test { TEST_F(AppCacheHostTest, Basic) { // Construct a host and test what state it appears to be in. AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); EXPECT_EQ(kHostIdForTest, host.host_id()); @@ -213,11 +219,12 @@ TEST_F(AppCacheHostTest, Basic) { } TEST_F(AppCacheHostTest, SelectNoCache) { - // Lock process to |kProcessLockURL| so we can only accept URLs from - // that site. - const GURL kProcessLockURL("http://whatever/"); - ChildProcessSecurityPolicyImpl::GetInstance()->LockToOrigin( - IsolationContext(&browser_context_), kProcessIdForTest, kProcessLockURL); + // Lock process with |kInitialDocumentURL| so we can only accept URLs that + // generate the same lock as |kInitialDocumentURL|. + const GURL kInitialDocumentURL("http://whatever/document"); + ChildProcessSecurityPolicyImpl::GetInstance()->LockProcessForTesting( + IsolationContext(&browser_context_), kProcessIdForTest, + kInitialDocumentURL); const std::vector<GURL> kDocumentURLs = { GURL("http://whatever/"), @@ -236,8 +243,11 @@ TEST_F(AppCacheHostTest, SelectNoCache) { const url::Origin kOrigin(url::Origin::Create(document_url)); { - AppCacheHost host(kHostIdForTest, kProcessIdForTest, - kRenderFrameIdForTest, mojo::NullRemote(), &service_); + AppCacheHost host( + kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), + mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); { @@ -287,6 +297,8 @@ TEST_F(AppCacheHostTest, ForeignEntry) { cache->AddEntry(kDocumentURL, AppCacheEntry(AppCacheEntry::EXPLICIT)); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); host.MarkAsForeignEntry(kDocumentURL, kCacheId); @@ -320,6 +332,8 @@ TEST_F(AppCacheHostTest, ForeignFallbackEntry) { cache->AddEntry(kFallbackURL, AppCacheEntry(AppCacheEntry::FALLBACK)); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); host.NotifyMainResourceIsNamespaceEntry(kFallbackURL); @@ -341,6 +355,8 @@ TEST_F(AppCacheHostTest, FailedCacheLoad) { blink::mojom::AppCacheStatus::APPCACHE_STATUS_OBSOLETE; AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); EXPECT_FALSE(host.is_selection_pending()); @@ -374,6 +390,8 @@ TEST_F(AppCacheHostTest, FailedCacheLoad) { TEST_F(AppCacheHostTest, FailedGroupLoad) { AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); @@ -406,6 +424,8 @@ TEST_F(AppCacheHostTest, FailedGroupLoad) { TEST_F(AppCacheHostTest, SetSwappableCache) { AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); host.SetSwappableCache(nullptr); @@ -510,8 +530,11 @@ TEST_F(AppCacheHostTest, SelectCacheAllowed) { const url::Origin kOrigin(url::Origin::Create(kDocAndOriginUrl)); const GURL kManifestUrl("http://whatever/cache.manifest"); { - AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, - mojo::NullRemote(), &service_); + AppCacheHost host( + kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), + mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); host.SetSiteForCookiesForTesting( net::SiteForCookies::FromUrl(kDocAndOriginUrl)); @@ -560,8 +583,11 @@ TEST_F(AppCacheHostTest, SelectCacheBlocked) { const url::Origin kOrigin(url::Origin::Create(kDocAndOriginUrl)); const GURL kManifestUrl(GURL("http://whatever/cache.manifest")); { - AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, - mojo::NullRemote(), &service_); + AppCacheHost host( + kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), + mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); host.SetSiteForCookiesForTesting( net::SiteForCookies::FromUrl(kDocAndOriginUrl)); @@ -596,6 +622,8 @@ TEST_F(AppCacheHostTest, SelectCacheBlocked) { TEST_F(AppCacheHostTest, SelectCacheTwice) { const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; @@ -641,6 +669,8 @@ TEST_F(AppCacheHostTest, SelectCacheInvalidCacheId) { const GURL kDocumentURL("http://origin/document"); auto cache = base::MakeRefCounted<AppCache>(service_.storage(), kCacheId); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; @@ -656,13 +686,16 @@ TEST_F(AppCacheHostTest, SelectCacheInvalidCacheId) { } TEST_F(AppCacheHostTest, SelectCacheURLsForWrongSite) { - // Lock process to |kProcessLockURL| so we can only accept URLs from - // that site. - const GURL kProcessLockURL("http://foo.com"); - ChildProcessSecurityPolicyImpl::GetInstance()->LockToOrigin( - IsolationContext(&browser_context_), kProcessIdForTest, kProcessLockURL); + // Lock process with |kInitialDocumentURL| so we can only accept URLs that + // generate the same lock as |kInitialDocumentURL|. + const GURL kInitialDocumentURL("http://foo.com/document"); + ChildProcessSecurityPolicyImpl::GetInstance()->LockProcessForTesting( + IsolationContext(&browser_context_), kProcessIdForTest, + kInitialDocumentURL); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; @@ -670,10 +703,10 @@ TEST_F(AppCacheHostTest, SelectCacheURLsForWrongSite) { // Verify that a document URL from the wrong site triggers a bad message. { - const GURL kDocumentURL("http://whatever/"); + const GURL kWrongSiteDocumentURL("http://whatever/"); mojo::test::BadMessageObserver bad_message_observer; - host_remote->SelectCache(kDocumentURL, blink::mojom::kAppCacheNoCacheId, - GURL()); + host_remote->SelectCache(kWrongSiteDocumentURL, + blink::mojom::kAppCacheNoCacheId, GURL()); EXPECT_EQ("ACH_SELECT_CACHE_DOCUMENT_URL_ACCESS_NOT_ALLOWED", bad_message_observer.WaitForBadMessage()); @@ -682,7 +715,7 @@ TEST_F(AppCacheHostTest, SelectCacheURLsForWrongSite) { // Verify that a document URL with an inner hostname from the wrong site // triggers a bad message. { - const GURL kDocumentURL = kProcessLockURL; + const GURL kDocumentURL = kInitialDocumentURL; mojo::test::BadMessageObserver bad_message_observer; host_remote->SelectCache( kDocumentURL, blink::mojom::kAppCacheNoCacheId, @@ -694,7 +727,7 @@ TEST_F(AppCacheHostTest, SelectCacheURLsForWrongSite) { // Verify that a manifest URL from the wrong site triggers a bad message. { - const GURL kDocumentURL = kProcessLockURL; + const GURL kDocumentURL = kInitialDocumentURL; const GURL kManifestURL("http://whatever/"); mojo::test::BadMessageObserver bad_message_observer; host_remote->SelectCache(kDocumentURL, blink::mojom::kAppCacheNoCacheId, @@ -706,13 +739,16 @@ TEST_F(AppCacheHostTest, SelectCacheURLsForWrongSite) { } TEST_F(AppCacheHostTest, ForeignEntryForWrongSite) { - // Lock process to |kProcessLockURL| so we can only accept URLs from - // that site. - const GURL kProcessLockURL("http://foo.com"); - ChildProcessSecurityPolicyImpl::GetInstance()->LockToOrigin( - IsolationContext(&browser_context_), kProcessIdForTest, kProcessLockURL); + // Lock process with |kInitialDocumentURL| so we can only accept URLs that + // generate the same lock as |kInitialDocumentURL|. + const GURL kInitialDocumentURL("http://foo.com"); + ChildProcessSecurityPolicyImpl::GetInstance()->LockProcessForTesting( + IsolationContext(&browser_context_), kProcessIdForTest, + kInitialDocumentURL); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; @@ -720,9 +756,9 @@ TEST_F(AppCacheHostTest, ForeignEntryForWrongSite) { // Verify that a document URL from the wrong site triggers a bad message. { - const GURL kDocumentURL("http://origin/document"); + const GURL kWrongSiteDocumentURL("http://origin/document"); mojo::test::BadMessageObserver bad_message_observer; - host_remote->MarkAsForeignEntry(kDocumentURL, + host_remote->MarkAsForeignEntry(kWrongSiteDocumentURL, blink::mojom::kAppCacheNoCacheId); EXPECT_EQ("ACH_MARK_AS_FOREIGN_ENTRY_DOCUMENT_URL_ACCESS_NOT_ALLOWED", bad_message_observer.WaitForBadMessage()); @@ -730,17 +766,18 @@ TEST_F(AppCacheHostTest, ForeignEntryForWrongSite) { } TEST_F(AppCacheHostTest, SelectCacheAfterProcessCleanup) { - // Lock process to |kProcessLockURL| so we can only accept URLs from - // that site. - const GURL kProcessLockURL("http://foo.com"); + // Lock process with |kDocumentURL| so we can only accept URLs that + // generate the same lock as |kDocumentURL|. const GURL kDocumentURL("http://foo.com/document"); const GURL kManifestURL("http://foo.com/manifest"); auto* security_policy = ChildProcessSecurityPolicyImpl::GetInstance(); - security_policy->LockToOrigin(IsolationContext(&browser_context_), - kProcessIdForTest, kProcessLockURL); + security_policy->LockProcessForTesting(IsolationContext(&browser_context_), + kProcessIdForTest, kDocumentURL); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; @@ -783,16 +820,17 @@ TEST_F(AppCacheHostTest, SelectCacheAfterProcessCleanup) { } TEST_F(AppCacheHostTest, ForeignEntryAfterProcessCleanup) { - // Lock process to |kProcessLockURL| so we can only accept URLs from - // that site. - const GURL kProcessLockURL("http://foo.com"); + // Lock process with |kDocumentURL| so we can only accept URLs that + // generate the same lock as |kDocumentURL|. const GURL kDocumentURL("http://foo.com/document"); auto* security_policy = ChildProcessSecurityPolicyImpl::GetInstance(); - security_policy->LockToOrigin(IsolationContext(&browser_context_), - kProcessIdForTest, kProcessLockURL); + security_policy->LockProcessForTesting(IsolationContext(&browser_context_), + kProcessIdForTest, kDocumentURL); AppCacheHost host(kHostIdForTest, kProcessIdForTest, kRenderFrameIdForTest, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kProcessIdForTest), mojo::NullRemote(), &service_); host.set_frontend_for_testing(&mock_frontend_); mojo::Remote<blink::mojom::AppCacheHost> host_remote; diff --git a/chromium/content/browser/appcache/appcache_internals_ui.cc b/chromium/content/browser/appcache/appcache_internals_ui.cc index af801a08a1a..ab51766fd69 100644 --- a/chromium/content/browser/appcache/appcache_internals_ui.cc +++ b/chromium/content/browser/appcache/appcache_internals_ui.cc @@ -15,7 +15,6 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "base/task/post_task.h" #include "base/threading/platform_thread.h" #include "base/values.h" #include "content/browser/appcache/appcache.h" @@ -32,6 +31,7 @@ #include "net/base/escape.h" #include "net/http/http_response_headers.h" #include "net/url_request/view_cache_helper.h" +#include "services/network/public/mojom/content_security_policy.mojom.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom.h" #include "third_party/blink/public/mojom/appcache/appcache_info.mojom.h" @@ -171,8 +171,8 @@ AppCacheInternalsUI::Proxy::Proxy( void AppCacheInternalsUI::Proxy::Initialize( const scoped_refptr<ChromeAppCacheService>& chrome_appcache_service) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&Proxy::Initialize, this, chrome_appcache_service)); return; } @@ -187,8 +187,8 @@ AppCacheInternalsUI::Proxy::~Proxy() { void AppCacheInternalsUI::Proxy::Shutdown() { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(&Proxy::Shutdown, this)); + GetUIThreadTaskRunner({})->PostTask(FROM_HERE, + base::BindOnce(&Proxy::Shutdown, this)); return; } shutdown_called_ = true; @@ -201,8 +201,8 @@ void AppCacheInternalsUI::Proxy::Shutdown() { void AppCacheInternalsUI::Proxy::RequestAllAppCacheInfo() { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(&Proxy::RequestAllAppCacheInfo, this)); + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&Proxy::RequestAllAppCacheInfo, this)); return; } if (appcache_service_) { @@ -223,8 +223,8 @@ void AppCacheInternalsUI::Proxy::OnAllAppCacheInfoReady( void AppCacheInternalsUI::Proxy::DeleteAppCache( const std::string& manifest_url) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(&Proxy::DeleteAppCache, this, manifest_url)); + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&Proxy::DeleteAppCache, this, manifest_url)); return; } if (appcache_service_) { @@ -244,8 +244,8 @@ void AppCacheInternalsUI::Proxy::OnAppCacheInfoDeleted( void AppCacheInternalsUI::Proxy::RequestAppCacheDetails( const std::string& manifest_url) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&Proxy::RequestAppCacheDetails, this, manifest_url)); return; } @@ -273,8 +273,8 @@ void AppCacheInternalsUI::Proxy::OnGroupLoaded(AppCacheGroup* appcache_group, void AppCacheInternalsUI::Proxy::RequestFileDetails( const ProxyResponseEnquiry& response_enquiry) { if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&Proxy::RequestFileDetails, this, response_enquiry)); return; } @@ -362,7 +362,8 @@ AppCacheInternalsUI::AppCacheInternalsUI(WebUI* web_ui) WebUIDataSource* source = WebUIDataSource::Create(kChromeUIAppCacheInternalsHost); - source->OverrideContentSecurityPolicyScriptSrc( + source->OverrideContentSecurityPolicy( + network::mojom::CSPDirectiveName::ScriptSrc, "script-src chrome://resources 'self' 'unsafe-eval';"); source->UseStringsJs(); diff --git a/chromium/content/browser/appcache/appcache_navigation_handle.cc b/chromium/content/browser/appcache/appcache_navigation_handle.cc index 8cf16667d23..b529cc9abed 100644 --- a/chromium/content/browser/appcache/appcache_navigation_handle.cc +++ b/chromium/content/browser/appcache/appcache_navigation_handle.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/lazy_instance.h" #include "content/browser/appcache/chrome_appcache_service.h" +#include "content/browser/child_process_security_policy_impl.h" #include "content/public/browser/browser_thread.h" namespace content { @@ -31,8 +32,9 @@ AppCacheNavigationHandle::AppCacheNavigationHandle( DCHECK_CURRENTLY_ON(BrowserThread::UI); precreated_host_ = std::make_unique<AppCacheHost>( - appcache_host_id_, process_id, MSG_ROUTING_NONE, mojo::NullRemote(), - static_cast<AppCacheServiceImpl*>(appcache_service)); + appcache_host_id_, process_id, MSG_ROUTING_NONE, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle(process_id), + mojo::NullRemote(), static_cast<AppCacheServiceImpl*>(appcache_service)); DCHECK(g_appcache_handle_map.Get().find(appcache_host_id_) == g_appcache_handle_map.Get().end()); diff --git a/chromium/content/browser/appcache/appcache_quota_client.cc b/chromium/content/browser/appcache/appcache_quota_client.cc index c49dac61143..e428255be48 100644 --- a/chromium/content/browser/appcache/appcache_quota_client.cc +++ b/chromium/content/browser/appcache/appcache_quota_client.cc @@ -14,7 +14,9 @@ #include "base/task/post_task.h" #include "content/browser/appcache/appcache_service_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "storage/browser/quota/quota_client_type.h" +#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h" #include "third_party/blink/public/mojom/quota/quota_types.mojom.h" using blink::mojom::StorageType; @@ -56,10 +58,6 @@ AppCacheQuotaClient::~AppCacheQuotaClient() { DCHECK(current_delete_request_callback_.is_null()); } -storage::QuotaClientType AppCacheQuotaClient::type() const { - return storage::QuotaClientType::kAppcache; -} - void AppCacheQuotaClient::OnQuotaManagerDestroyed() { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DeletePendingRequests(); @@ -73,6 +71,7 @@ void AppCacheQuotaClient::GetOriginUsage(const url::Origin& origin, StorageType type, GetUsageCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_EQ(type, blink::mojom::StorageType::kTemporary); DCHECK(!callback.is_null()); if (service_is_destroyed_) { @@ -87,13 +86,8 @@ void AppCacheQuotaClient::GetOriginUsage(const url::Origin& origin, return; } - if (type != StorageType::kTemporary) { - std::move(callback).Run(0); - return; - } - - base::PostTaskAndReplyWithResult( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTaskAndReplyWithResult( + FROM_HERE, base::BindOnce( [](base::WeakPtr<AppCacheServiceImpl> service, const url::Origin& origin) -> int64_t { @@ -115,25 +109,32 @@ void AppCacheQuotaClient::GetOriginUsage(const url::Origin& origin, void AppCacheQuotaClient::GetOriginsForType(StorageType type, GetOriginsCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - GetOriginsHelper(type, std::string(), std::move(callback)); + DCHECK_EQ(type, blink::mojom::StorageType::kTemporary); + DCHECK(!callback.is_null()); + + GetOriginsHelper(std::string(), std::move(callback)); } void AppCacheQuotaClient::GetOriginsForHost(StorageType type, const std::string& host, GetOriginsCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_EQ(type, blink::mojom::StorageType::kTemporary); DCHECK(!callback.is_null()); + if (host.empty()) { std::move(callback).Run(std::set<url::Origin>()); return; } - GetOriginsHelper(type, host, std::move(callback)); + GetOriginsHelper(host, std::move(callback)); } void AppCacheQuotaClient::DeleteOriginData(const url::Origin& origin, StorageType type, DeletionCallback callback) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + DCHECK_EQ(type, blink::mojom::StorageType::kTemporary); + DCHECK(!callback.is_null()); if (service_is_destroyed_) { std::move(callback).Run(blink::mojom::QuotaStatusCode::kErrorAbort); @@ -153,8 +154,8 @@ void AppCacheQuotaClient::DeleteOriginData(const url::Origin& origin, return; } - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&AppCacheServiceImpl::DeleteAppCachesForOrigin, service_, origin, base::BindOnce(&RunDeleteOnIO, FROM_HERE, @@ -163,12 +164,11 @@ void AppCacheQuotaClient::DeleteOriginData(const url::Origin& origin, void AppCacheQuotaClient::PerformStorageCleanup(blink::mojom::StorageType type, base::OnceClosure callback) { - std::move(callback).Run(); -} - -bool AppCacheQuotaClient::DoesSupport(StorageType type) const { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - return type == StorageType::kTemporary; + DCHECK_EQ(type, blink::mojom::StorageType::kTemporary); + DCHECK(!callback.is_null()); + + std::move(callback).Run(); } void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { @@ -182,8 +182,7 @@ void AppCacheQuotaClient::DidDeleteAppCachesForOrigin(int rv) { RunFront(&pending_serial_requests_); } -void AppCacheQuotaClient::GetOriginsHelper(StorageType type, - const std::string& opt_host, +void AppCacheQuotaClient::GetOriginsHelper(const std::string& opt_host, GetOriginsCallback callback) { DCHECK(!callback.is_null()); @@ -193,19 +192,14 @@ void AppCacheQuotaClient::GetOriginsHelper(StorageType type, } if (!appcache_is_ready_) { - pending_batch_requests_.push_back(base::BindOnce( - &AppCacheQuotaClient::GetOriginsHelper, base::RetainedRef(this), type, - opt_host, std::move(callback))); - return; - } - - if (type != StorageType::kTemporary) { - std::move(callback).Run(std::set<url::Origin>()); + pending_batch_requests_.push_back( + base::BindOnce(&AppCacheQuotaClient::GetOriginsHelper, + base::RetainedRef(this), opt_host, std::move(callback))); return; } - base::PostTaskAndReplyWithResult( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTaskAndReplyWithResult( + FROM_HERE, base::BindOnce( [](base::WeakPtr<AppCacheServiceImpl> service, const std::string& opt_host) { diff --git a/chromium/content/browser/appcache/appcache_quota_client.h b/chromium/content/browser/appcache/appcache_quota_client.h index 41ad80d8b59..9a1206391e1 100644 --- a/chromium/content/browser/appcache/appcache_quota_client.h +++ b/chromium/content/browser/appcache/appcache_quota_client.h @@ -40,7 +40,6 @@ class AppCacheQuotaClient : public storage::QuotaClient { explicit AppCacheQuotaClient(base::WeakPtr<AppCacheServiceImpl> service); // QuotaClient method overrides - storage::QuotaClientType type() const override; void OnQuotaManagerDestroyed() override; void GetOriginUsage(const url::Origin& origin, blink::mojom::StorageType type, @@ -55,7 +54,6 @@ class AppCacheQuotaClient : public storage::QuotaClient { DeletionCallback callback) override; void PerformStorageCleanup(blink::mojom::StorageType type, base::OnceClosure callback) override; - bool DoesSupport(blink::mojom::StorageType type) const override; private: friend class content::AppCacheQuotaClientTest; @@ -65,8 +63,7 @@ class AppCacheQuotaClient : public storage::QuotaClient { ~AppCacheQuotaClient() override; void DidDeleteAppCachesForOrigin(int rv); - void GetOriginsHelper(blink::mojom::StorageType type, - const std::string& opt_host, + void GetOriginsHelper(const std::string& opt_host, GetOriginsCallback callback); void ProcessPendingRequests(); void DeletePendingRequests(); @@ -77,7 +74,7 @@ class AppCacheQuotaClient : public storage::QuotaClient { CONTENT_EXPORT void NotifyAppCacheDestroyed(); // Prior to appcache service being ready, we have to queue - // up reqeusts and defer acting on them until we're ready. + // up requests and defer acting on them until we're ready. RequestQueue pending_batch_requests_; RequestQueue pending_serial_requests_; diff --git a/chromium/content/browser/appcache/appcache_quota_client_unittest.cc b/chromium/content/browser/appcache/appcache_quota_client_unittest.cc index 9f3c6251e62..e639074d050 100644 --- a/chromium/content/browser/appcache/appcache_quota_client_unittest.cc +++ b/chromium/content/browser/appcache/appcache_quota_client_unittest.cc @@ -21,7 +21,6 @@ using blink::mojom::StorageType; // Declared to shorten the line lengths. static const StorageType kTemp = StorageType::kTemporary; -static const StorageType kPerm = StorageType::kPersistent; // Base class for our test fixtures. class AppCacheQuotaClientTest : public testing::Test { @@ -192,15 +191,10 @@ TEST_F(AppCacheQuotaClientTest, EmptyService) { Call_NotifyAppCacheReady(client); EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kTemp)); - EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kPerm)); EXPECT_TRUE(GetOriginsForType(client, kTemp).empty()); - EXPECT_TRUE(GetOriginsForType(client, kPerm).empty()); EXPECT_TRUE(GetOriginsForHost(client, kTemp, kOriginA.host()).empty()); - EXPECT_TRUE(GetOriginsForHost(client, kPerm, kOriginA.host()).empty()); EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, DeleteOriginData(client, kTemp, kOriginA)); - EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, - DeleteOriginData(client, kPerm, kOriginA)); Call_NotifyAppCacheDestroyed(client); Call_OnQuotaManagerDestroyed(client); @@ -212,15 +206,10 @@ TEST_F(AppCacheQuotaClientTest, NoService) { Call_NotifyAppCacheDestroyed(client); EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kTemp)); - EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kPerm)); EXPECT_TRUE(GetOriginsForType(client, kTemp).empty()); - EXPECT_TRUE(GetOriginsForType(client, kPerm).empty()); EXPECT_TRUE(GetOriginsForHost(client, kTemp, kOriginA.host()).empty()); - EXPECT_TRUE(GetOriginsForHost(client, kPerm, kOriginA.host()).empty()); EXPECT_EQ(blink::mojom::QuotaStatusCode::kErrorAbort, DeleteOriginData(client, kTemp, kOriginA)); - EXPECT_EQ(blink::mojom::QuotaStatusCode::kErrorAbort, - DeleteOriginData(client, kPerm, kOriginA)); Call_OnQuotaManagerDestroyed(client); } @@ -231,7 +220,7 @@ TEST_F(AppCacheQuotaClientTest, GetOriginUsage) { SetUsageMapEntry(kOriginA, 1000); EXPECT_EQ(1000, GetOriginUsage(client, kOriginA, kTemp)); - EXPECT_EQ(0, GetOriginUsage(client, kOriginA, kPerm)); + EXPECT_EQ(0, GetOriginUsage(client, kOriginB, kTemp)); Call_NotifyAppCacheDestroyed(client); Call_OnQuotaManagerDestroyed(client); @@ -261,9 +250,6 @@ TEST_F(AppCacheQuotaClientTest, GetOriginsForHost) { EXPECT_EQ(1ul, origins.size()); EXPECT_TRUE(origins.find(kOriginOther) != origins.end()); - origins = GetOriginsForHost(client, kPerm, kOriginA.host()); - EXPECT_TRUE(origins.empty()); - Call_NotifyAppCacheDestroyed(client); Call_OnQuotaManagerDestroyed(client); } @@ -273,7 +259,6 @@ TEST_F(AppCacheQuotaClientTest, GetOriginsForType) { Call_NotifyAppCacheReady(client); EXPECT_TRUE(GetOriginsForType(client, kTemp).empty()); - EXPECT_TRUE(GetOriginsForType(client, kPerm).empty()); SetUsageMapEntry(kOriginA, 1000); SetUsageMapEntry(kOriginB, 10); @@ -283,8 +268,6 @@ TEST_F(AppCacheQuotaClientTest, GetOriginsForType) { EXPECT_TRUE(origins.find(kOriginA) != origins.end()); EXPECT_TRUE(origins.find(kOriginB) != origins.end()); - EXPECT_TRUE(GetOriginsForType(client, kPerm).empty()); - Call_NotifyAppCacheDestroyed(client); Call_OnQuotaManagerDestroyed(client); } @@ -293,12 +276,6 @@ TEST_F(AppCacheQuotaClientTest, DeleteOriginData) { auto client = CreateClient(); Call_NotifyAppCacheReady(client); - // Perm deletions are short circuited in the Client and - // should not reach the AppCacheServiceImpl. - EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, - DeleteOriginData(client, kPerm, kOriginA)); - EXPECT_EQ(0, mock_service_.delete_called_count()); - EXPECT_EQ(blink::mojom::QuotaStatusCode::kOk, DeleteOriginData(client, kTemp, kOriginA)); EXPECT_EQ(1, mock_service_.delete_called_count()); @@ -320,15 +297,14 @@ TEST_F(AppCacheQuotaClientTest, PendingRequests) { SetUsageMapEntry(kOriginB, 10); SetUsageMapEntry(kOriginOther, 500); - // Queue up some reqeusts. - AsyncGetOriginUsage(client, kOriginA, kPerm); + // Queue up some requests. + AsyncGetOriginUsage(client, kOriginA, kTemp); AsyncGetOriginUsage(client, kOriginB, kTemp); - AsyncGetOriginsForType(client, kPerm); + AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForHost(client, kTemp, kOriginA.host()); AsyncGetOriginsForHost(client, kTemp, kOriginOther.host()); AsyncDeleteOriginData(client, kTemp, kOriginA); - AsyncDeleteOriginData(client, kPerm, kOriginA); AsyncDeleteOriginData(client, kTemp, kOriginB); EXPECT_EQ(0, num_get_origin_usage_completions_); @@ -344,7 +320,7 @@ TEST_F(AppCacheQuotaClientTest, PendingRequests) { base::RunLoop().RunUntilIdle(); EXPECT_EQ(2, num_get_origin_usage_completions_); EXPECT_EQ(4, num_get_origins_completions_); - EXPECT_EQ(3, num_delete_origins_completions_); + EXPECT_EQ(2, num_delete_origins_completions_); // They should be serviced in order requested. EXPECT_EQ(10, usage_); @@ -362,15 +338,14 @@ TEST_F(AppCacheQuotaClientTest, DestroyServiceWithPending) { SetUsageMapEntry(kOriginB, 10); SetUsageMapEntry(kOriginOther, 500); - // Queue up some reqeusts prior to being ready. - AsyncGetOriginUsage(client, kOriginA, kPerm); + // Queue up some requests prior to being ready. + AsyncGetOriginUsage(client, kOriginA, kTemp); AsyncGetOriginUsage(client, kOriginB, kTemp); - AsyncGetOriginsForType(client, kPerm); + AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForHost(client, kTemp, kOriginA.host()); AsyncGetOriginsForHost(client, kTemp, kOriginOther.host()); AsyncDeleteOriginData(client, kTemp, kOriginA); - AsyncDeleteOriginData(client, kPerm, kOriginA); AsyncDeleteOriginData(client, kTemp, kOriginB); base::RunLoop().RunUntilIdle(); EXPECT_EQ(0, num_get_origin_usage_completions_); @@ -383,7 +358,7 @@ TEST_F(AppCacheQuotaClientTest, DestroyServiceWithPending) { // All should have been aborted and called completion. EXPECT_EQ(2, num_get_origin_usage_completions_); EXPECT_EQ(4, num_get_origins_completions_); - EXPECT_EQ(3, num_delete_origins_completions_); + EXPECT_EQ(2, num_delete_origins_completions_); EXPECT_EQ(0, usage_); EXPECT_TRUE(origins_.empty()); EXPECT_EQ(blink::mojom::QuotaStatusCode::kErrorAbort, delete_status_); @@ -398,15 +373,14 @@ TEST_F(AppCacheQuotaClientTest, DestroyQuotaManagerWithPending) { SetUsageMapEntry(kOriginB, 10); SetUsageMapEntry(kOriginOther, 500); - // Queue up some reqeusts prior to being ready. - AsyncGetOriginUsage(client, kOriginA, kPerm); + // Queue up some requests prior to being ready. + AsyncGetOriginUsage(client, kOriginA, kTemp); AsyncGetOriginUsage(client, kOriginB, kTemp); - AsyncGetOriginsForType(client, kPerm); + AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForType(client, kTemp); AsyncGetOriginsForHost(client, kTemp, kOriginA.host()); AsyncGetOriginsForHost(client, kTemp, kOriginOther.host()); AsyncDeleteOriginData(client, kTemp, kOriginA); - AsyncDeleteOriginData(client, kPerm, kOriginA); AsyncDeleteOriginData(client, kTemp, kOriginB); base::RunLoop().RunUntilIdle(); EXPECT_EQ(0, num_get_origin_usage_completions_); diff --git a/chromium/content/browser/appcache/appcache_request_handler_unittest.cc b/chromium/content/browser/appcache/appcache_request_handler_unittest.cc index e7ebb5ba082..d4e8e4b0735 100644 --- a/chromium/content/browser/appcache/appcache_request_handler_unittest.cc +++ b/chromium/content/browser/appcache/appcache_request_handler_unittest.cc @@ -21,7 +21,6 @@ #include "base/stl_util.h" #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" -#include "base/task/post_task.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "content/browser/appcache/appcache.h" @@ -31,6 +30,7 @@ #include "content/browser/appcache/mock_appcache_policy.h" #include "content/browser/appcache/mock_appcache_service.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_task_environment.h" #include "mojo/public/cpp/bindings/pending_remote.h" #include "net/base/net_errors.h" @@ -75,8 +75,8 @@ class AppCacheRequestHandlerTest : public ::testing::Test { void RunTestOnUIThread(Method method) { base::RunLoop run_loop; test_finished_cb_ = run_loop.QuitClosure(); - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&AppCacheRequestHandlerTest::MethodWrapper<Method>, base::Unretained(this), method)); run_loop.Run(); @@ -92,7 +92,10 @@ class AppCacheRequestHandlerTest : public ::testing::Test { ignore_result(frontend_remote.InitWithNewPipeAndPassReceiver()); mock_service_->RegisterHost( host_remote_.BindNewPipeAndPassReceiver(), std::move(frontend_remote), - kHostId, kRenderFrameId, kMockProcessId, GetBadMessageCallback()); + kHostId, kRenderFrameId, kMockProcessId, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId), + GetBadMessageCallback()); host_ = mock_service_->GetHost(kHostId); } diff --git a/chromium/content/browser/appcache/appcache_service_impl.cc b/chromium/content/browser/appcache/appcache_service_impl.cc index 27a5bfb3a96..886b9221c65 100644 --- a/chromium/content/browser/appcache/appcache_service_impl.cc +++ b/chromium/content/browser/appcache/appcache_service_impl.cc @@ -16,7 +16,6 @@ #include "base/macros.h" #include "base/memory/ptr_util.h" #include "base/single_thread_task_runner.h" -#include "base/task/post_task.h" #include "base/task/thread_pool.h" #include "base/threading/sequenced_task_runner_handle.h" #include "content/browser/appcache/appcache.h" @@ -31,8 +30,10 @@ #include "content/browser/appcache/appcache_storage_impl.h" #include "content/browser/loader/navigation_url_loader_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "net/base/completion_once_callback.h" #include "net/base/io_buffer.h" +#include "storage/browser/quota/quota_client_type.h" #include "storage/browser/quota/special_storage_policy.h" #include "third_party/blink/public/mojom/appcache/appcache_info.mojom.h" @@ -387,7 +388,9 @@ AppCacheServiceImpl::AppCacheServiceImpl( partition_(std::move(partition)) { if (quota_manager_proxy_.get()) { quota_client_ = base::MakeRefCounted<AppCacheQuotaClient>(AsWeakPtr()); - quota_manager_proxy_->RegisterClient(quota_client_); + quota_manager_proxy_->RegisterClient( + quota_client_, storage::QuotaClientType::kAppcache, + {blink::mojom::StorageType::kTemporary}); } } @@ -399,8 +402,8 @@ AppCacheServiceImpl::~AppCacheServiceImpl() { helper.first->Cancel(); pending_helpers_.clear(); if (quota_client_) { - base::PostTask(FROM_HERE, {BrowserThread::IO}, - base::BindOnce(&AppCacheQuotaClient::NotifyAppCacheDestroyed, + GetIOThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&AppCacheQuotaClient::NotifyAppCacheDestroyed, std::move(quota_client_))); } @@ -522,6 +525,7 @@ void AppCacheServiceImpl::RegisterHost( const base::UnguessableToken& host_id, int32_t render_frame_id, int process_id, + ChildProcessSecurityPolicyImpl::Handle security_policy_handle, mojo::ReportBadMessageCallback bad_message_callback) { DCHECK_CURRENTLY_ON(BrowserThread::UI); if (GetHost(host_id)) { @@ -539,6 +543,7 @@ void AppCacheServiceImpl::RegisterHost( host->set_frontend(std::move(frontend_remote), render_frame_id); } else { host = std::make_unique<AppCacheHost>(host_id, process_id, render_frame_id, + std::move(security_policy_handle), std::move(frontend_remote), this); } diff --git a/chromium/content/browser/appcache/appcache_service_impl.h b/chromium/content/browser/appcache/appcache_service_impl.h index f6125b82cbc..cb75a7636f2 100644 --- a/chromium/content/browser/appcache/appcache_service_impl.h +++ b/chromium/content/browser/appcache/appcache_service_impl.h @@ -18,6 +18,7 @@ #include "base/time/time.h" #include "base/timer/timer.h" #include "content/browser/appcache/appcache_quota_client.h" +#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/url_loader_factory_getter.h" #include "content/common/appcache_interfaces.h" #include "content/common/content_export.h" @@ -169,6 +170,7 @@ class CONTENT_EXPORT AppCacheServiceImpl : public AppCacheService { const base::UnguessableToken& host_id, int32_t render_frame_id, int process_id, + ChildProcessSecurityPolicyImpl::Handle security_policy_handle, mojo::ReportBadMessageCallback bad_message_callback); protected: diff --git a/chromium/content/browser/appcache/appcache_storage_impl.cc b/chromium/content/browser/appcache/appcache_storage_impl.cc index a11ce32c276..9cd7edd52c2 100644 --- a/chromium/content/browser/appcache/appcache_storage_impl.cc +++ b/chromium/content/browser/appcache/appcache_storage_impl.cc @@ -20,7 +20,6 @@ #include "base/single_thread_task_runner.h" #include "base/stl_util.h" #include "base/strings/string_util.h" -#include "base/task/post_task.h" #include "base/threading/sequenced_task_runner_handle.h" #include "content/browser/appcache/appcache.h" #include "content/browser/appcache/appcache_database.h" @@ -33,6 +32,7 @@ #include "content/browser/appcache/appcache_response_info.h" #include "content/browser/appcache/appcache_service_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "net/base/cache_type.h" #include "net/base/net_errors.h" #include "sql/database.h" @@ -309,8 +309,8 @@ void AppCacheStorageImpl::InitTask::RunCompleted() { } if (storage_->service()->quota_client()) { - base::PostTask( - FROM_HERE, {BrowserThread::IO}, + GetIOThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&AppCacheQuotaClient::NotifyAppCacheReady, base::RetainedRef(storage_->service()->quota_client()))); } @@ -353,8 +353,8 @@ void AppCacheStorageImpl::GetAllInfoTask::Run() { std::set<url::Origin> origins; database_->FindOriginsWithGroups(&origins); for (const url::Origin& origin : origins) { - std::vector<blink::mojom::AppCacheInfo>& infos = - info_collection_->infos_by_origin[origin]; + std::vector<blink::mojom::AppCacheInfo> infos; + std::vector<AppCacheDatabase::GroupRecord> groups; database_->FindGroupsForOrigin(origin, &groups); for (const auto& group : groups) { @@ -378,6 +378,13 @@ void AppCacheStorageImpl::GetAllInfoTask::Run() { info.manifest_scope = cache_record.manifest_scope; infos.push_back(info); } + + // It's possible that all the origins have a group that is invalid due to + // the origin trial. Ignore these. + if (infos.empty()) + continue; + + info_collection_->infos_by_origin[origin] = std::move(infos); } } @@ -1398,15 +1405,7 @@ void AppCacheStorageImpl::UpdateEvictionTimesTask::Run() { // AppCacheStorageImpl --------------------------------------------------- AppCacheStorageImpl::AppCacheStorageImpl(AppCacheServiceImpl* service) - : AppCacheStorage(service), - is_incognito_(false), - is_response_deletion_scheduled_(false), - did_start_deleting_responses_(false), - last_deletable_response_rowid_(0), - database_(nullptr), - is_disabled_(false), - delete_and_start_over_pending_(false), - expecting_cleanup_complete_on_disable_(false) {} + : AppCacheStorage(service) {} AppCacheStorageImpl::~AppCacheStorageImpl() { for (StoreGroupAndCacheTask* task : pending_quota_queries_) @@ -1414,13 +1413,12 @@ AppCacheStorageImpl::~AppCacheStorageImpl() { for (DatabaseTask* task : scheduled_database_tasks_) task->CancelCompletion(); - if (database_ && - !db_task_runner_->PostTask( - FROM_HERE, - base::BindOnce( - &ClearSessionOnlyOrigins, std::move(database_), - base::WrapRefCounted(service_->special_storage_policy()), - service()->force_keep_session_state()))) { + if (database_) { + db_task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&ClearSessionOnlyOrigins, std::move(database_), + base::WrapRefCounted(service_->special_storage_policy()), + service()->force_keep_session_state())); } } @@ -1937,8 +1935,8 @@ void AppCacheStorageImpl::OnDiskCacheCleanupComplete() { delete_and_start_over_pending_ = false; db_task_runner_->PostTaskAndReply( FROM_HERE, - base::BindOnce(base::IgnoreResult(&base::DeleteFile), cache_directory_, - true), + base::BindOnce(base::GetDeletePathRecursivelyCallback(), + cache_directory_), base::BindOnce(&AppCacheStorageImpl::CallScheduleReinitialize, weak_factory_.GetWeakPtr())); } diff --git a/chromium/content/browser/appcache/appcache_storage_impl.h b/chromium/content/browser/appcache/appcache_storage_impl.h index 27ed1a955a6..4a6890fb192 100644 --- a/chromium/content/browser/appcache/appcache_storage_impl.h +++ b/chromium/content/browser/appcache/appcache_storage_impl.h @@ -162,7 +162,7 @@ class AppCacheStorageImpl : public AppCacheStorage { // The directory in which we place files in the file system. base::FilePath cache_directory_; - bool is_incognito_; + bool is_incognito_ = false; // This class operates primarily on the IO thread, but schedules // its DatabaseTasks on the db thread. @@ -178,24 +178,24 @@ class AppCacheStorageImpl : public AppCacheStorage { // Structures to keep track of lazy response deletion. base::circular_deque<int64_t> deletable_response_ids_; std::vector<int64_t> deleted_response_ids_; - bool is_response_deletion_scheduled_; - bool did_start_deleting_responses_; - int64_t last_deletable_response_rowid_; + bool is_response_deletion_scheduled_ = false; + bool did_start_deleting_responses_ = false; + int64_t last_deletable_response_rowid_ = 0; // Created on the IO thread, but only used on the DB thread. std::unique_ptr<AppCacheDatabase> database_; // Set if we discover a fatal error like a corrupt SQL database or // disk cache and cannot continue. - bool is_disabled_; + bool is_disabled_ = false; // This is set when we want to use the post-cleanup callback to initiate // directory deletion. - bool delete_and_start_over_pending_; + bool delete_and_start_over_pending_ = false; // This is set when we know that a call to Disable() will result in // OnDiskCacheCleanupComplete() eventually called. - bool expecting_cleanup_complete_on_disable_; + bool expecting_cleanup_complete_on_disable_ = false; std::unique_ptr<AppCacheDiskCache> disk_cache_; base::OneShotTimer lazy_commit_timer_; diff --git a/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc b/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc index f519c0e099f..455c1422d58 100644 --- a/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc +++ b/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc @@ -22,7 +22,6 @@ #include "base/single_thread_task_runner.h" #include "base/stl_util.h" #include "base/synchronization/waitable_event.h" -#include "base/task/post_task.h" #include "base/test/bind_test_util.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" @@ -40,6 +39,7 @@ #include "content/browser/child_process_security_policy_impl.h" #include "content/browser/storage_partition_impl.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" #include "content/public/test/url_loader_interceptor.h" @@ -51,12 +51,14 @@ #include "net/http/http_response_headers.h" #include "services/network/test/test_utils.h" #include "sql/test/test_helpers.h" +#include "storage/browser/quota/quota_client_type.h" #include "storage/browser/quota/quota_manager.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/blink/public/common/features.h" #include "third_party/blink/public/mojom/appcache/appcache.mojom.h" #include "third_party/blink/public/mojom/appcache/appcache_info.mojom.h" #include "third_party/blink/public/mojom/devtools/console_message.mojom.h" +#include "third_party/blink/public/mojom/quota/quota_types.mojom-shared.h" #include "url/gurl.h" #include "url/origin.h" @@ -197,7 +199,10 @@ class AppCacheStorageImplTest : public testing::Test { } // Not needed for our tests. - void RegisterClient(scoped_refptr<storage::QuotaClient> client) override {} + void RegisterClient( + scoped_refptr<storage::QuotaClient> client, + storage::QuotaClientType quota_client_type, + const std::vector<blink::mojom::StorageType>& storage_types) override {} void NotifyOriginInUse(const url::Origin& origin) override {} void NotifyOriginNoLongerInUse(const url::Origin& origin) override {} void SetUsageCacheEnabled(storage::QuotaClientType client_id, @@ -285,8 +290,8 @@ class AppCacheStorageImplTest : public testing::Test { void RunTestOnUIThread(Method method) { base::RunLoop run_loop; test_finished_cb_ = run_loop.QuitClosure(); - base::PostTask( - FROM_HERE, {BrowserThread::UI}, + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(&AppCacheStorageImplTest::MethodWrapper<Method>, base::Unretained(this), method)); run_loop.Run(); @@ -1616,9 +1621,12 @@ class AppCacheStorageImplTest : public testing::Test { // Try to create a new appcache, the resulting update job will // eventually fail when it gets to disk cache initialization. host1_id_ = base::UnguessableToken::Create(); - service_->RegisterHost(host_remote_.BindNewPipeAndPassReceiver(), - BindFrontend(), host1_id_, kMockRenderFrameId, - kMockProcessId, GetBadMessageCallback()); + service_->RegisterHost( + host_remote_.BindNewPipeAndPassReceiver(), BindFrontend(), host1_id_, + kMockRenderFrameId, kMockProcessId, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId), + GetBadMessageCallback()); AppCacheHost* host1 = service_->GetHost(host1_id_); const GURL kEmptyPageUrl(GetMockUrl("empty.html")); host1->SetSiteForCookiesForTesting( @@ -1631,9 +1639,12 @@ class AppCacheStorageImplTest : public testing::Test { // The URLRequestJob will eventually fail when it gets to disk // cache initialization. host2_id_ = base::UnguessableToken::Create(); - service_->RegisterHost(host_remote_.BindNewPipeAndPassReceiver(), - BindFrontend(), host2_id_, kMockRenderFrameId, - kMockProcessId, GetBadMessageCallback()); + service_->RegisterHost( + host_remote_.BindNewPipeAndPassReceiver(), BindFrontend(), host2_id_, + kMockRenderFrameId, kMockProcessId, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId), + GetBadMessageCallback()); AppCacheHost* host2 = service_->GetHost(host2_id_); network::ResourceRequest request; request.url = GetMockUrl("manifest"); diff --git a/chromium/content/browser/appcache/appcache_test_helper.cc b/chromium/content/browser/appcache/appcache_test_helper.cc new file mode 100644 index 00000000000..b0cbec0cc06 --- /dev/null +++ b/chromium/content/browser/appcache/appcache_test_helper.cc @@ -0,0 +1,74 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/browser/appcache/appcache_test_helper.h" + +#include "base/bind.h" +#include "base/bind_helpers.h" +#include "base/run_loop.h" +#include "content/browser/appcache/appcache.h" +#include "content/browser/appcache/appcache_entry.h" +#include "content/browser/appcache/appcache_group.h" +#include "content/browser/appcache/appcache_service_impl.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace content { + +AppCacheTestHelper::AppCacheTestHelper() + : group_id_(0), appcache_id_(0), response_id_(0), origins_(nullptr) {} + +AppCacheTestHelper::~AppCacheTestHelper() {} + +void AppCacheTestHelper::OnGroupAndNewestCacheStored( + AppCacheGroup* /*group*/, + AppCache* /*newest_cache*/, + bool success, + bool /*would_exceed_quota*/) { + ASSERT_TRUE(success); + base::RunLoop::QuitCurrentWhenIdleDeprecated(); +} + +void AppCacheTestHelper::AddGroupAndCache(AppCacheServiceImpl* appcache_service, + const GURL& manifest_url) { + AppCacheGroup* appcache_group = + new AppCacheGroup(appcache_service->storage(), manifest_url, ++group_id_); + AppCache* appcache = + new AppCache(appcache_service->storage(), ++appcache_id_); + appcache->set_manifest_parser_version(0); + appcache->set_manifest_scope("/"); + appcache->set_token_expires(base::Time::Now() + + base::TimeDelta::FromDays(10)); + AppCacheEntry entry(AppCacheEntry::MANIFEST, ++response_id_); + appcache->AddEntry(manifest_url, entry); + appcache->set_complete(true); + appcache_group->AddCache(appcache); + appcache_service->storage()->StoreGroupAndNewestCache(appcache_group, + appcache, this); + // OnGroupAndNewestCacheStored will quit the message loop. + base::RunLoop().Run(); +} + +void AppCacheTestHelper::GetOriginsWithCaches( + AppCacheServiceImpl* appcache_service, + std::set<url::Origin>* origins) { + appcache_info_ = new AppCacheInfoCollection; + origins_ = origins; + appcache_service->GetAllAppCacheInfo( + appcache_info_.get(), + base::BindOnce(&AppCacheTestHelper::OnGotAppCacheInfo, + base::Unretained(this))); + + // OnGotAppCacheInfo will quit the message loop. + base::RunLoop().Run(); +} + +void AppCacheTestHelper::OnGotAppCacheInfo(int rv) { + origins_->clear(); + for (const auto& kvp : appcache_info_->infos_by_origin) + origins_->insert(kvp.first); + + base::RunLoop::QuitCurrentWhenIdleDeprecated(); +} + +} // namespace content diff --git a/chromium/content/browser/appcache/appcache_test_helper.h b/chromium/content/browser/appcache/appcache_test_helper.h new file mode 100644 index 00000000000..784731f49bb --- /dev/null +++ b/chromium/content/browser/appcache/appcache_test_helper.h @@ -0,0 +1,49 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_TEST_HELPER_H_ +#define CONTENT_BROWSER_APPCACHE_APPCACHE_TEST_HELPER_H_ + +#include <set> + +#include "base/macros.h" +#include "content/browser/appcache/appcache_storage.h" + +namespace content { +class AppCacheServiceImpl; +} + +namespace content { + +// Helper class for inserting data into a ChromeAppCacheService and reading it +// back. +class AppCacheTestHelper : public AppCacheStorage::Delegate { + public: + AppCacheTestHelper(); + ~AppCacheTestHelper() override; + void AddGroupAndCache(AppCacheServiceImpl* appcache_service, + const GURL& manifest_url); + + void GetOriginsWithCaches(AppCacheServiceImpl* appcache_service, + std::set<url::Origin>* origins); + + private: + void OnGroupAndNewestCacheStored(AppCacheGroup* group, + AppCache* newest_cache, + bool success, + bool would_exceed_quota) override; + void OnGotAppCacheInfo(int rv); + + int group_id_; + int appcache_id_; + int response_id_; + scoped_refptr<AppCacheInfoCollection> appcache_info_; + std::set<url::Origin>* origins_; // not owned + + DISALLOW_COPY_AND_ASSIGN(AppCacheTestHelper); +}; + +} // namespace content + +#endif // CONTENT_BROWSER_APPCACHE_APPCACHE_TEST_HELPER_H_ diff --git a/chromium/content/browser/appcache/appcache_unittest.cc b/chromium/content/browser/appcache/appcache_unittest.cc index 8fcfc54df73..19753c49ffd 100644 --- a/chromium/content/browser/appcache/appcache_unittest.cc +++ b/chromium/content/browser/appcache/appcache_unittest.cc @@ -35,15 +35,23 @@ TEST_F(AppCacheTest, CleanupUnusedCache) { mojo::PendingRemote<blink::mojom::AppCacheFrontend> frontend1; ignore_result(frontend1.InitWithNewPipeAndPassReceiver()); - AppCacheHost host1(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, - std::move(frontend1), &service); + const int kMockProcessId1 = 1; + const int kMockProcessId2 = 2; + AppCacheHost host1( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId1, + /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + std::move(frontend1), &service); mojo::PendingRemote<blink::mojom::AppCacheFrontend> frontend2; ignore_result(frontend2.InitWithNewPipeAndPassReceiver()); - AppCacheHost host2(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/2, /*render_frame_id=*/2, - std::move(frontend2), &service); + AppCacheHost host2( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId2, + /*render_frame_id=*/2, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId2), + std::move(frontend2), &service); host1.AssociateCompleteCache(cache.get()); host2.AssociateCompleteCache(cache.get()); diff --git a/chromium/content/browser/appcache/appcache_update_job.cc b/chromium/content/browser/appcache/appcache_update_job.cc index 0680e53423b..ed937c17e3e 100644 --- a/chromium/content/browser/appcache/appcache_update_job.cc +++ b/chromium/content/browser/appcache/appcache_update_job.cc @@ -160,7 +160,7 @@ ResourceCheck CanUseExistingResource( // Record the max age / expiry value on this entry in days. net::HttpResponseHeaders::FreshnessLifetimes lifetimes = http_info->headers->GetFreshnessLifetimes(response_time); - base::UmaHistogramCounts10000("appcache.UpdateJobResourceFreshness", + base::UmaHistogramCounts10000("appcache.UpdateJob.ResourceFreshness", lifetimes.freshness.InDays()); // Check HTTP caching semantics based on max-age and expiration headers. diff --git a/chromium/content/browser/appcache/appcache_update_job_unittest.cc b/chromium/content/browser/appcache/appcache_update_job_unittest.cc index 6e9dd515471..ef7707b07a6 100644 --- a/chromium/content/browser/appcache/appcache_update_job_unittest.cc +++ b/chromium/content/browser/appcache/appcache_update_job_unittest.cc @@ -20,7 +20,6 @@ #include "base/strings/strcat.h" #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" -#include "base/task/post_task.h" #include "base/test/scoped_feature_list.h" #include "base/test/task_environment.h" #include "base/threading/thread_task_runner_handle.h" @@ -36,6 +35,7 @@ #include "content/browser/storage_partition_impl.h" #include "content/browser/url_loader_factory_getter.h" #include "content/public/browser/browser_task_traits.h" +#include "content/public/browser/browser_thread.h" #include "content/public/common/origin_util.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" @@ -762,8 +762,8 @@ class AppCacheUpdateJobTest : public testing::Test, void RunTestOnUIThread(Method method) { base::RunLoop run_loop; test_completed_cb_ = run_loop.QuitClosure(); - base::PostTask(FROM_HERE, {BrowserThread::UI}, - base::BindOnce(method, base::Unretained(this))); + GetUIThreadTaskRunner({})->PostTask( + FROM_HERE, base::BindOnce(method, base::Unretained(this))); run_loop.Run(); } @@ -778,9 +778,13 @@ class AppCacheUpdateJobTest : public testing::Test, group_->update_job_ = update; MockFrontend mock_frontend; - AppCacheHost host(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, - mojo::NullRemote(), service_.get()); + const int kMockProcessId1 = 1; + AppCacheHost host( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId1, + /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + mojo::NullRemote(), service_.get()); host.set_frontend_for_testing(&mock_frontend); update->StartUpdate(&host, GURL()); @@ -819,27 +823,43 @@ class AppCacheUpdateJobTest : public testing::Test, MockFrontend mock_frontend3; MockFrontend mock_frontend4; - AppCacheHost host1(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, - mojo::NullRemote(), service_.get()); + const int kMockProcessId1 = 1; + const int kMockProcessId2 = 2; + const int kMockProcessId3 = 3; + const int kMockProcessId4 = 4; + AppCacheHost host1( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId1, + /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + mojo::NullRemote(), service_.get()); host1.set_frontend_for_testing(&mock_frontend1); host1.AssociateCompleteCache(cache1); - AppCacheHost host2(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/2, /*render_frame_id=*/2, - mojo::NullRemote(), service_.get()); + AppCacheHost host2( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId2, + /*render_frame_id=*/2, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId2), + mojo::NullRemote(), service_.get()); host2.set_frontend_for_testing(&mock_frontend2); host2.AssociateCompleteCache(cache2); - AppCacheHost host3(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/3, /*render_frame_id=*/3, - mojo::NullRemote(), service_.get()); + AppCacheHost host3( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId3, + /*render_frame_id=*/3, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId3), + mojo::NullRemote(), service_.get()); host3.set_frontend_for_testing(&mock_frontend3); host3.AssociateCompleteCache(cache1); - AppCacheHost host4(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/4, /*render_frame_id=*/4, - mojo::NullRemote(), service_.get()); + AppCacheHost host4( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId4, + /*render_frame_id=*/4, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId4), + mojo::NullRemote(), service_.get()); host4.set_frontend_for_testing(&mock_frontend4); AppCacheUpdateJob* update = @@ -1040,7 +1060,7 @@ class AppCacheUpdateJobTest : public testing::Test, WaitForUpdateToFinish(); } - void ManifestGoneTest() { + void ManifestGoneFetchTest() { MakeService(); group_ = base::MakeRefCounted<AppCacheGroup>( service_->storage(), MockHttpServer::GetMockUrl("files/gone"), @@ -1063,6 +1083,36 @@ class AppCacheUpdateJobTest : public testing::Test, WaitForUpdateToFinish(); } + void ManifestGoneUpgradeTest() { + MakeService(); + group_ = base::MakeRefCounted<AppCacheGroup>( + service_->storage(), MockHttpServer::GetMockUrl("files/gone"), + service_->storage()->NewGroupId()); + AppCacheUpdateJob* update = + new AppCacheUpdateJob(service_.get(), group_.get()); + group_->update_job_ = update; + + MockFrontend* frontend = MakeMockFrontend(); + AppCacheHost* host = MakeHost(frontend); + + AppCache* cache = MakeCacheForGroup(1, 111); + host->AssociateCompleteCache(cache); + + update->StartUpdate(nullptr, GURL()); + + // Set up checks for when update job finishes. + do_checks_after_update_finished_ = true; + expect_group_obsolete_ = true; + expect_group_has_cache_ = true; + expect_newest_cache_ = cache; // newest cache unaffected by update + frontend->AddExpectedEvent( + blink::mojom::AppCacheEventID::APPCACHE_CHECKING_EVENT); + frontend->AddExpectedEvent( + blink::mojom::AppCacheEventID::APPCACHE_OBSOLETE_EVENT); + + WaitForUpdateToFinish(); + } + void CacheAttemptNotModifiedTest() { MakeService(); group_ = base::MakeRefCounted<AppCacheGroup>( @@ -3306,9 +3356,13 @@ class AppCacheUpdateJobTest : public testing::Test, group_->manifest_url(), std::make_unique<HttpHeadersRequestTestJob>( std::string(), std::string())); MockFrontend mock_frontend; - AppCacheHost host(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, - mojo::NullRemote(), service_.get()); + const int kMockProcessId1 = 1; + AppCacheHost host( + /*host_id=*/base::UnguessableToken::Create(), kMockProcessId1, + /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + mojo::NullRemote(), service_.get()); host.set_frontend_for_testing(&mock_frontend); update->StartUpdate(&host, GURL()); @@ -4225,6 +4279,8 @@ class AppCacheUpdateJobTest : public testing::Test, constexpr int kRenderFrameIdForTests = 456; hosts_.push_back(std::make_unique<AppCacheHost>( base::UnguessableToken::Create(), process_id_, kRenderFrameIdForTests, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + process_id_), mojo::NullRemote(), service_.get())); hosts_.back()->set_frontend_for_testing(frontend); return hosts_.back().get(); @@ -5065,9 +5121,12 @@ TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { EXPECT_EQ(AppCacheGroup::CHECKING, group->update_status()); MockFrontend mock_frontend; + const int kMockProcessId1 = 1; AppCacheHost host(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, mojo::NullRemote(), - &service); + kMockProcessId1, /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + mojo::NullRemote(), &service); host.set_frontend_for_testing(&mock_frontend); update.StartUpdate(&host, GURL()); @@ -5093,9 +5152,12 @@ TEST_F(AppCacheUpdateJobTest, AlreadyDownloading) { EXPECT_EQ(AppCacheGroup::DOWNLOADING, group->update_status()); MockFrontend mock_frontend; + const int kMockProcessId1 = 1; AppCacheHost host(/*host_id=*/base::UnguessableToken::Create(), - /*process_id=*/1, /*render_frame_id=*/1, mojo::NullRemote(), - &service); + kMockProcessId1, /*render_frame_id=*/1, + ChildProcessSecurityPolicyImpl::GetInstance()->CreateHandle( + kMockProcessId1), + mojo::NullRemote(), &service); host.set_frontend_for_testing(&mock_frontend); update.StartUpdate(&host, GURL()); @@ -5133,11 +5195,21 @@ TEST_F(AppCacheUpdateJobTest, ManifestMissingMimeTypeTest) { } TEST_F(AppCacheUpdateJobTest, ManifestNotFound) { + base::test::ScopedFeatureList f; + f.InitAndEnableFeature(blink::features::kAppCacheRequireOriginTrial); RunTestOnUIThread(&AppCacheUpdateJobTest::ManifestNotFoundTest); } -TEST_F(AppCacheUpdateJobTest, ManifestGone) { - RunTestOnUIThread(&AppCacheUpdateJobTest::ManifestGoneTest); +TEST_F(AppCacheUpdateJobTest, ManifestGoneFetch) { + base::test::ScopedFeatureList f; + f.InitAndEnableFeature(blink::features::kAppCacheRequireOriginTrial); + RunTestOnUIThread(&AppCacheUpdateJobTest::ManifestGoneFetchTest); +} + +TEST_F(AppCacheUpdateJobTest, ManifestGoneUpgrade) { + base::test::ScopedFeatureList f; + f.InitAndEnableFeature(blink::features::kAppCacheRequireOriginTrial); + RunTestOnUIThread(&AppCacheUpdateJobTest::ManifestGoneUpgradeTest); } TEST_F(AppCacheUpdateJobTest, CacheAttemptNotModified) { @@ -5343,6 +5415,8 @@ TEST_F(AppCacheUpdateJobTest, UpgradeFailStoreNewestCache) { } TEST_F(AppCacheUpdateJobTest, UpgradeFailMakeGroupObsolete) { + base::test::ScopedFeatureList f; + f.InitAndEnableFeature(blink::features::kAppCacheRequireOriginTrial); RunTestOnUIThread(&AppCacheUpdateJobTest::UpgradeFailMakeGroupObsoleteTest); } diff --git a/chromium/content/browser/appcache/appcache_update_metrics_recorder.h b/chromium/content/browser/appcache/appcache_update_metrics_recorder.h index 1da467dec4e..29f20cfe488 100644 --- a/chromium/content/browser/appcache/appcache_update_metrics_recorder.h +++ b/chromium/content/browser/appcache/appcache_update_metrics_recorder.h @@ -5,7 +5,7 @@ #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_METRICS_RECORDER_H_ #define CONTENT_BROWSER_APPCACHE_APPCACHE_UPDATE_METRICS_RECORDER_H_ -#include "base/logging.h" +#include "base/check_op.h" #include "content/browser/appcache/appcache_update_job_state.h" #include "content/common/content_export.h" diff --git a/chromium/content/browser/appcache/appcache_update_url_fetcher.h b/chromium/content/browser/appcache/appcache_update_url_fetcher.h index 3cb61c84339..b0e80e39c99 100644 --- a/chromium/content/browser/appcache/appcache_update_url_fetcher.h +++ b/chromium/content/browser/appcache/appcache_update_url_fetcher.h @@ -8,7 +8,7 @@ #include <stddef.h> #include <stdint.h> -#include "base/logging.h" +#include "base/check.h" #include "content/browser/appcache/appcache_update_job.h" #include "net/base/io_buffer.h" #include "url/gurl.h" diff --git a/chromium/content/browser/appcache/appcache_url_loader.h b/chromium/content/browser/appcache/appcache_url_loader.h index 8e1fa3b9dda..4bc53074c5e 100644 --- a/chromium/content/browser/appcache/appcache_url_loader.h +++ b/chromium/content/browser/appcache/appcache_url_loader.h @@ -7,7 +7,7 @@ #include <memory> -#include "base/logging.h" +#include "base/check.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" #include "base/sequence_checker.h" diff --git a/chromium/content/browser/appcache/chrome_appcache_service.cc b/chromium/content/browser/appcache/chrome_appcache_service.cc index c098e0d26d5..1cf85702775 100644 --- a/chromium/content/browser/appcache/chrome_appcache_service.cc +++ b/chromium/content/browser/appcache/chrome_appcache_service.cc @@ -7,7 +7,6 @@ #include <utility> #include "base/files/file_path.h" -#include "base/task/post_task.h" #include "content/browser/appcache/appcache_storage_impl.h" #include "content/browser/loader/navigation_url_loader_impl.h" #include "content/public/browser/browser_context.h" @@ -88,7 +87,7 @@ void ChromeAppCacheService::DeleteOnCorrectThread() const { return; } if (BrowserThread::IsThreadInitialized(BrowserThread::UI)) { - base::DeleteSoon(FROM_HERE, {BrowserThread::UI}, this); + GetUIThreadTaskRunner({})->DeleteSoon(FROM_HERE, this); return; } // Better to leak than crash on shutdown. diff --git a/chromium/content/browser/appcache/chrome_appcache_service_unittest.cc b/chromium/content/browser/appcache/chrome_appcache_service_unittest.cc index dfd5644fe05..7b52d3809e4 100644 --- a/chromium/content/browser/appcache/chrome_appcache_service_unittest.cc +++ b/chromium/content/browser/appcache/chrome_appcache_service_unittest.cc @@ -16,12 +16,12 @@ #include "base/threading/thread_task_runner_handle.h" #include "content/browser/appcache/appcache_database.h" #include "content/browser/appcache/appcache_storage_impl.h" +#include "content/browser/appcache/appcache_test_helper.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" #include "content/public/test/browser_task_environment.h" #include "content/public/test/test_browser_context.h" -#include "content/test/appcache_test_helper.h" #include "net/url_request/url_request_context_getter.h" #include "storage/browser/test/mock_special_storage_policy.h" #include "testing/gtest/include/gtest/gtest.h" |