diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-28 15:28:34 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2018-08-28 13:54:51 +0000 |
commit | 2a19c63448c84c1805fb1a585c3651318bb86ca7 (patch) | |
tree | eb17888e8531aa6ee5e85721bd553b832a7e5156 /chromium/content/browser/appcache | |
parent | b014812705fc80bff0a5c120dfcef88f349816dc (diff) | |
download | qtwebengine-chromium-2a19c63448c84c1805fb1a585c3651318bb86ca7.tar.gz |
BASELINE: Update Chromium to 69.0.3497.70
Change-Id: I2b7b56e4e7a8b26656930def0d4575dc32b900a0
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/content/browser/appcache')
28 files changed, 189 insertions, 238 deletions
diff --git a/chromium/content/browser/appcache/appcache_backend_impl.cc b/chromium/content/browser/appcache/appcache_backend_impl.cc index f0150fb78aa..c2d1dee5f0e 100644 --- a/chromium/content/browser/appcache/appcache_backend_impl.cc +++ b/chromium/content/browser/appcache/appcache_backend_impl.cc @@ -126,39 +126,8 @@ void AppCacheBackendImpl::GetResourceList( host->GetResourceList(resource_infos); } -std::unique_ptr<AppCacheHost> AppCacheBackendImpl::TransferHostOut( - int host_id) { - auto found = hosts_.find(host_id); - if (found == hosts_.end()) { - NOTREACHED(); - return std::unique_ptr<AppCacheHost>(); - } - - std::unique_ptr<AppCacheHost> transferree = std::move(found->second); - - // Put a new empty host in its place. - found->second = std::make_unique<AppCacheHost>(host_id, frontend_, service_); - - // We give up ownership. - transferree->PrepareForTransfer(); - return transferree; -} - -void AppCacheBackendImpl::TransferHostIn(int new_host_id, - std::unique_ptr<AppCacheHost> host) { - auto found = hosts_.find(new_host_id); - if (found == hosts_.end()) { - NOTREACHED(); - return; - } - - host->CompleteTransfer(new_host_id, frontend_); - found->second = std::move(host); -} - void AppCacheBackendImpl::RegisterPrecreatedHost( std::unique_ptr<AppCacheHost> host) { - DCHECK(IsBrowserSideNavigationEnabled()); DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK(host.get()); diff --git a/chromium/content/browser/appcache/appcache_backend_impl.h b/chromium/content/browser/appcache/appcache_backend_impl.h index cf6d4352546..cf5b8e8e737 100644 --- a/chromium/content/browser/appcache/appcache_backend_impl.h +++ b/chromium/content/browser/appcache/appcache_backend_impl.h @@ -59,13 +59,6 @@ class CONTENT_EXPORT AppCacheBackendImpl { using HostMap = base::hash_map<int, std::unique_ptr<AppCacheHost>>; const HostMap& hosts() { return hosts_; } - // Methods to support cross site navigations. Hosts are transferred - // from process to process accordingly, deparented from the old - // processes backend and reparented to the new. - std::unique_ptr<AppCacheHost> TransferHostOut(int host_id); - void TransferHostIn(int new_host_id, std::unique_ptr<AppCacheHost> host); - - // PlzNavigate // The AppCacheHost is precreated by the AppCacheNavigationHandleCore class // when a navigation is initiated. We register the host with the backend in // this function and ignore registrations for this host id from the renderer. diff --git a/chromium/content/browser/appcache/appcache_database.cc b/chromium/content/browser/appcache/appcache_database.cc index 8e21b82f900..0f747557abb 100644 --- a/chromium/content/browser/appcache/appcache_database.cc +++ b/chromium/content/browser/appcache/appcache_database.cc @@ -250,8 +250,7 @@ bool AppCacheDatabase::FindOriginsWithGroups(std::set<url::Origin>* origins) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "SELECT DISTINCT(origin) FROM Groups"; + static const char kSql[] = "SELECT DISTINCT(origin) FROM Groups"; sql::Statement statement(db_->GetUniqueStatement(kSql)); @@ -277,13 +276,13 @@ bool AppCacheDatabase::FindLastStorageIds( if (!LazyOpen(kDontCreate)) return false; - const char kMaxGroupIdSql[] = "SELECT MAX(group_id) FROM Groups"; - const char kMaxCacheIdSql[] = "SELECT MAX(cache_id) FROM Caches"; - const char kMaxResponseIdFromEntriesSql[] = + static const char kMaxGroupIdSql[] = "SELECT MAX(group_id) FROM Groups"; + static const char kMaxCacheIdSql[] = "SELECT MAX(cache_id) FROM Caches"; + static const char kMaxResponseIdFromEntriesSql[] = "SELECT MAX(response_id) FROM Entries"; - const char kMaxResponseIdFromDeletablesSql[] = + static const char kMaxResponseIdFromDeletablesSql[] = "SELECT MAX(response_id) FROM DeletableResponseIds"; - const char kMaxDeletableResponseRowIdSql[] = + static const char kMaxDeletableResponseRowIdSql[] = "SELECT MAX(rowid) FROM DeletableResponseIds"; int64_t max_group_id; int64_t max_cache_id; @@ -314,7 +313,7 @@ bool AppCacheDatabase::FindGroup(int64_t group_id, GroupRecord* record) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT group_id, origin, manifest_url," " creation_time, last_access_time," " last_full_update_check_time," @@ -338,7 +337,7 @@ bool AppCacheDatabase::FindGroupForManifestUrl( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT group_id, origin, manifest_url," " creation_time, last_access_time," " last_full_update_check_time," @@ -362,7 +361,7 @@ bool AppCacheDatabase::FindGroupsForOrigin(const url::Origin& origin, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT group_id, origin, manifest_url," " creation_time, last_access_time," " last_full_update_check_time," @@ -387,7 +386,7 @@ bool AppCacheDatabase::FindGroupForCache(int64_t cache_id, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT g.group_id, g.origin, g.manifest_url," " g.creation_time, g.last_access_time," " g.last_full_update_check_time," @@ -409,7 +408,7 @@ bool AppCacheDatabase::InsertGroup(const GroupRecord* record) { if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "INSERT INTO Groups" " (group_id, origin, manifest_url, creation_time, last_access_time," " last_full_update_check_time, first_evictable_error_time)" @@ -429,8 +428,7 @@ bool AppCacheDatabase::DeleteGroup(int64_t group_id) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "DELETE FROM Groups WHERE group_id = ?"; + static const char kSql[] = "DELETE FROM Groups WHERE group_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, group_id); return statement.Run(); @@ -460,7 +458,7 @@ bool AppCacheDatabase::CommitLazyLastAccessTimes() { if (!transaction.Begin()) return false; for (const auto& pair : lazy_last_access_times_) { - const char kSql[] = + static const char kSql[] = "UPDATE Groups SET last_access_time = ? WHERE group_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, pair.second.ToInternalValue()); // time @@ -478,7 +476,7 @@ bool AppCacheDatabase::UpdateEvictionTimes( if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "UPDATE Groups" " SET last_full_update_check_time = ?, first_evictable_error_time = ?" " WHERE group_id = ?"; @@ -494,7 +492,7 @@ bool AppCacheDatabase::FindCache(int64_t cache_id, CacheRecord* record) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" " FROM Caches WHERE cache_id = ?"; @@ -514,7 +512,7 @@ bool AppCacheDatabase::FindCacheForGroup(int64_t group_id, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, group_id, online_wildcard, update_time, cache_size" " FROM Caches WHERE group_id = ?"; @@ -547,7 +545,7 @@ bool AppCacheDatabase::InsertCache(const CacheRecord* record) { if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "INSERT INTO Caches (cache_id, group_id, online_wildcard," " update_time, cache_size)" " VALUES(?, ?, ?, ?, ?)"; @@ -566,8 +564,7 @@ bool AppCacheDatabase::DeleteCache(int64_t cache_id) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "DELETE FROM Caches WHERE cache_id = ?"; + static const char kSql[] = "DELETE FROM Caches WHERE cache_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, cache_id); @@ -581,7 +578,7 @@ bool AppCacheDatabase::FindEntriesForCache(int64_t cache_id, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, url, flags, response_id, response_size FROM Entries" " WHERE cache_id = ?"; @@ -603,7 +600,7 @@ bool AppCacheDatabase::FindEntriesForUrl( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, url, flags, response_id, response_size FROM Entries" " WHERE url = ?"; @@ -626,7 +623,7 @@ bool AppCacheDatabase::FindEntry(int64_t cache_id, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, url, flags, response_id, response_size FROM Entries" " WHERE cache_id = ? AND url = ?"; @@ -647,7 +644,7 @@ bool AppCacheDatabase::InsertEntry(const EntryRecord* record) { if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "INSERT INTO Entries (cache_id, url, flags, response_id, response_size)" " VALUES(?, ?, ?, ?, ?)"; @@ -679,8 +676,7 @@ bool AppCacheDatabase::DeleteEntriesForCache(int64_t cache_id) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "DELETE FROM Entries WHERE cache_id = ?"; + static const char kSql[] = "DELETE FROM Entries WHERE cache_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, cache_id); @@ -694,7 +690,7 @@ bool AppCacheDatabase::AddEntryFlags(const GURL& entry_url, if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "UPDATE Entries SET flags = flags | ? WHERE cache_id = ? AND url = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); @@ -714,7 +710,7 @@ bool AppCacheDatabase::FindNamespacesForOrigin( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" " FROM Namespaces WHERE origin = ?"; @@ -735,7 +731,7 @@ bool AppCacheDatabase::FindNamespacesForCache( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, origin, type, namespace_url, target_url, is_pattern" " FROM Namespaces WHERE cache_id = ?"; @@ -752,7 +748,7 @@ bool AppCacheDatabase::InsertNamespace( if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "INSERT INTO Namespaces" " (cache_id, origin, type, namespace_url, target_url, is_pattern)" " VALUES (?, ?, ?, ?, ?, ?)"; @@ -785,8 +781,7 @@ bool AppCacheDatabase::DeleteNamespacesForCache(int64_t cache_id) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "DELETE FROM Namespaces WHERE cache_id = ?"; + static const char kSql[] = "DELETE FROM Namespaces WHERE cache_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, cache_id); @@ -801,7 +796,7 @@ bool AppCacheDatabase::FindOnlineWhiteListForCache( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT cache_id, namespace_url, is_pattern FROM OnlineWhiteLists" " WHERE cache_id = ?"; @@ -821,7 +816,7 @@ bool AppCacheDatabase::InsertOnlineWhiteList( if (!LazyOpen(kCreateIfNeeded)) return false; - const char kSql[] = + static const char kSql[] = "INSERT INTO OnlineWhiteLists (cache_id, namespace_url, is_pattern)" " VALUES (?, ?, ?)"; @@ -851,8 +846,7 @@ bool AppCacheDatabase::DeleteOnlineWhiteListForCache(int64_t cache_id) { if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = - "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; + static const char kSql[] = "DELETE FROM OnlineWhiteLists WHERE cache_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); statement.BindInt64(0, cache_id); @@ -867,7 +861,7 @@ bool AppCacheDatabase::GetDeletableResponseIds( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT response_id FROM DeletableResponseIds " " WHERE rowid <= ?" " LIMIT ?"; @@ -883,20 +877,20 @@ bool AppCacheDatabase::GetDeletableResponseIds( bool AppCacheDatabase::InsertDeletableResponseIds( const std::vector<int64_t>& response_ids) { - const char kSql[] = + static const char kSql[] = "INSERT INTO DeletableResponseIds (response_id) VALUES (?)"; return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); } bool AppCacheDatabase::DeleteDeletableResponseIds( const std::vector<int64_t>& response_ids) { - const char kSql[] = + static const char kSql[] = "DELETE FROM DeletableResponseIds WHERE response_id = ?"; return RunCachedStatementWithIds(SQL_FROM_HERE, kSql, response_ids); } bool AppCacheDatabase::RunCachedStatementWithIds( - const sql::StatementID& statement_id, + sql::StatementID statement_id, const char* sql, const std::vector<int64_t>& ids) { DCHECK(sql); @@ -939,7 +933,7 @@ bool AppCacheDatabase::FindResponseIdsForCacheHelper( if (!LazyOpen(kDontCreate)) return false; - const char kSql[] = + static const char kSql[] = "SELECT response_id FROM Entries WHERE cache_id = ?"; sql::Statement statement(db_->GetCachedStatement(SQL_FROM_HERE, kSql)); diff --git a/chromium/content/browser/appcache/appcache_database.h b/chromium/content/browser/appcache/appcache_database.h index 1150724619e..164f6b58772 100644 --- a/chromium/content/browser/appcache/appcache_database.h +++ b/chromium/content/browser/appcache/appcache_database.h @@ -18,6 +18,7 @@ #include "base/time/time.h" #include "content/common/appcache_interfaces.h" #include "content/common/content_export.h" +#include "sql/statement_id.h" #include "url/gurl.h" #include "url/origin.h" @@ -25,7 +26,6 @@ namespace sql { class Connection; class MetaTable; class Statement; -class StatementID; } namespace content { @@ -196,7 +196,7 @@ class CONTENT_EXPORT AppCacheDatabase { } private: - bool RunCachedStatementWithIds(const sql::StatementID& statement_id, + bool RunCachedStatementWithIds(sql::StatementID statement_id, const char* sql, const std::vector<int64_t>& ids); bool RunUniqueStatementWithInt64Result(const char* sql, int64_t* result); diff --git a/chromium/content/browser/appcache/appcache_disk_cache.cc b/chromium/content/browser/appcache/appcache_disk_cache.cc index d718034f704..8c28d1862d7 100644 --- a/chromium/content/browser/appcache/appcache_disk_cache.cc +++ b/chromium/content/browser/appcache/appcache_disk_cache.cc @@ -126,7 +126,7 @@ class AppCacheDiskCache::ActiveCall scoped_refptr<ActiveCall> active_call( new ActiveCall(owner, entry, callback)); int rv = owner->disk_cache()->CreateEntry( - base::Int64ToString(key), &active_call->entry_ptr_, + base::Int64ToString(key), net::HIGHEST, &active_call->entry_ptr_, base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); return active_call->HandleImmediateReturnValue(rv); } @@ -138,7 +138,7 @@ class AppCacheDiskCache::ActiveCall scoped_refptr<ActiveCall> active_call( new ActiveCall(owner, entry, callback)); int rv = owner->disk_cache()->OpenEntry( - base::Int64ToString(key), &active_call->entry_ptr_, + base::Int64ToString(key), net::HIGHEST, &active_call->entry_ptr_, base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); return active_call->HandleImmediateReturnValue(rv); } @@ -149,7 +149,7 @@ class AppCacheDiskCache::ActiveCall scoped_refptr<ActiveCall> active_call( new ActiveCall(owner, nullptr, callback)); int rv = owner->disk_cache()->DoomEntry( - base::Int64ToString(key), + base::Int64ToString(key), net::HIGHEST, base::Bind(&ActiveCall::OnAsyncCompletion, active_call)); return active_call->HandleImmediateReturnValue(rv); } diff --git a/chromium/content/browser/appcache/appcache_dispatcher_host.cc b/chromium/content/browser/appcache/appcache_dispatcher_host.cc index d5c6a6f1266..966ab0e1271 100644 --- a/chromium/content/browser/appcache/appcache_dispatcher_host.cc +++ b/chromium/content/browser/appcache/appcache_dispatcher_host.cc @@ -32,24 +32,30 @@ AppCacheDispatcherHost::~AppCacheDispatcherHost() = default; void AppCacheDispatcherHost::Create(ChromeAppCacheService* appcache_service, int process_id, mojom::AppCacheBackendRequest request) { + // The process_id is the id of the RenderProcessHost, which can be reused for + // a new renderer process if the previous renderer process was shutdown. + // It can take some time after shutdown for the pipe error to propagate + // and unregister the previous backend. Since the AppCacheService assumes + // that there is one backend per process_id, we need to ensure that the + // previous backend is unregistered by eagerly unbinding the pipe. + appcache_service->Unbind(process_id); + appcache_service->Bind( std::make_unique<AppCacheDispatcherHost>(appcache_service, process_id), - std::move(request)); + std::move(request), process_id); } void AppCacheDispatcherHost::RegisterHost(int32_t host_id) { if (appcache_service_) { - // PlzNavigate // The AppCacheHost could have been precreated in which case we want to // register it with the backend here. - if (IsBrowserSideNavigationEnabled()) { - std::unique_ptr<content::AppCacheHost> host = - AppCacheNavigationHandleCore::GetPrecreatedHost(host_id); - if (host.get()) { - backend_impl_.RegisterPrecreatedHost(std::move(host)); - return; - } + std::unique_ptr<content::AppCacheHost> host = + AppCacheNavigationHandleCore::GetPrecreatedHost(host_id); + if (host.get()) { + backend_impl_.RegisterPrecreatedHost(std::move(host)); + return; } + if (!backend_impl_.RegisterHost(host_id)) { mojo::ReportBadMessage("ACDH_REGISTER"); } diff --git a/chromium/content/browser/appcache/appcache_host.cc b/chromium/content/browser/appcache/appcache_host.cc index eb88a3b00d8..2b27d83d316 100644 --- a/chromium/content/browser/appcache/appcache_host.cc +++ b/chromium/content/browser/appcache/appcache_host.cc @@ -509,20 +509,6 @@ void AppCacheHost::NotifyMainResourceBlocked(const GURL& manifest_url) { blocked_manifest_url_ = manifest_url; } -void AppCacheHost::PrepareForTransfer() { - // This can only happen prior to the document having been loaded. - DCHECK(!associated_cache()); - DCHECK(!is_selection_pending()); - DCHECK(!group_being_updated_.get()); - host_id_ = kAppCacheNoHostId; - frontend_ = nullptr; -} - -void AppCacheHost::CompleteTransfer(int host_id, AppCacheFrontend* frontend) { - host_id_ = host_id; - frontend_ = frontend; -} - base::WeakPtr<AppCacheHost> AppCacheHost::GetWeakPtr() { return weak_factory_.GetWeakPtr(); } @@ -539,7 +525,8 @@ void AppCacheHost::MaybePassSubresourceFactory() { network::mojom::URLLoaderFactoryPtr factory_ptr = nullptr; AppCacheSubresourceURLFactory::CreateURLLoaderFactory( - service()->url_loader_factory_getter(), GetWeakPtr(), &factory_ptr); + service()->url_loader_factory_getter()->GetNetworkFactory(), GetWeakPtr(), + &factory_ptr); frontend_->OnSetSubresourceFactory(host_id(), std::move(factory_ptr)); } diff --git a/chromium/content/browser/appcache/appcache_host.h b/chromium/content/browser/appcache/appcache_host.h index 7da6f38ede7..e5d29763fda 100644 --- a/chromium/content/browser/appcache/appcache_host.h +++ b/chromium/content/browser/appcache/appcache_host.h @@ -191,10 +191,6 @@ class CONTENT_EXPORT AppCacheHost const GURL& first_party_url() const { return first_party_url_; } - // Methods to support cross site navigations. - void PrepareForTransfer(); - void CompleteTransfer(int host_id, AppCacheFrontend* frontend); - // Returns a weak pointer reference to the host. base::WeakPtr<AppCacheHost> GetWeakPtr(); diff --git a/chromium/content/browser/appcache/appcache_internals_ui.cc b/chromium/content/browser/appcache/appcache_internals_ui.cc index 3a34269fbc0..f33713440f4 100644 --- a/chromium/content/browser/appcache/appcache_internals_ui.cc +++ b/chromium/content/browser/appcache/appcache_internals_ui.cc @@ -350,6 +350,8 @@ AppCacheInternalsUI::AppCacheInternalsUI(WebUI* web_ui) WebUIDataSource* source = WebUIDataSource::Create(kChromeUIAppCacheInternalsHost); + source->OverrideContentSecurityPolicyScriptSrc( + "script-src chrome://resources 'self' 'unsafe-eval';"); source->SetJsonPath("strings.js"); source->AddResourcePath("appcache_internals.js", IDR_APPCACHE_INTERNALS_JS); diff --git a/chromium/content/browser/appcache/appcache_navigation_handle.cc b/chromium/content/browser/appcache/appcache_navigation_handle.cc index 6c47bf8a415..b6bf5de3d8f 100644 --- a/chromium/content/browser/appcache/appcache_navigation_handle.cc +++ b/chromium/content/browser/appcache/appcache_navigation_handle.cc @@ -8,11 +8,10 @@ #include "content/browser/appcache/appcache_navigation_handle_core.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/public/browser/browser_thread.h" -#include "content/public/common/appcache_info.h" namespace { -// PlzNavigate: Used to generate the host id for a navigation initiated by the -// browser. Starts at -2 and keeps going down. +// Used to generate the host id for a navigation initiated by the browser. +// Starts at -1 and keeps going down. static int g_next_appcache_host_id = -1; } @@ -20,13 +19,10 @@ namespace content { AppCacheNavigationHandle::AppCacheNavigationHandle( ChromeAppCacheService* appcache_service) - : appcache_host_id_(kAppCacheNoHostId), - core_(nullptr), - weak_factory_(this) { + : appcache_host_id_(g_next_appcache_host_id--), + core_(std::make_unique<AppCacheNavigationHandleCore>(appcache_service, + appcache_host_id_)) { DCHECK_CURRENTLY_ON(BrowserThread::UI); - appcache_host_id_ = g_next_appcache_host_id--; - core_.reset(new AppCacheNavigationHandleCore( - weak_factory_.GetWeakPtr(), appcache_service, appcache_host_id_)); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, base::BindOnce(&AppCacheNavigationHandleCore::Initialize, diff --git a/chromium/content/browser/appcache/appcache_navigation_handle.h b/chromium/content/browser/appcache/appcache_navigation_handle.h index 535849a7144..0b910604307 100644 --- a/chromium/content/browser/appcache/appcache_navigation_handle.h +++ b/chromium/content/browser/appcache/appcache_navigation_handle.h @@ -7,8 +7,6 @@ #include <memory> #include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" namespace content { @@ -42,7 +40,7 @@ class ChromeAppCacheService; // update the RequestNavigationParams based on the id from the // AppCacheNavigationHandle. // -// 6. The commit leads to AppCache registrations happening from the renderer. +// 6) The commit leads to AppCache registrations happening from the renderer. // This is via the IPC message AppCacheHostMsg_RegisterHost. The // AppCacheDispatcherHost class which handles these IPCs will be informed // about these hosts when the navigation commits. It will ignore the @@ -52,24 +50,19 @@ class ChromeAppCacheService; // 7) When the navigation finishes, the AppCacheNavigationHandle is // destroyed. The destructor of the AppCacheNavigationHandle posts a -// task to destroy the AppacheNavigationHandleCore on the IO thread. +// task to destroy the AppCacheNavigationHandleCore on the IO thread. class AppCacheNavigationHandle { public: - AppCacheNavigationHandle(ChromeAppCacheService* appcache_service); + explicit AppCacheNavigationHandle(ChromeAppCacheService* appcache_service); ~AppCacheNavigationHandle(); int appcache_host_id() const { return appcache_host_id_; } AppCacheNavigationHandleCore* core() const { return core_.get(); } - // Called when a navigation is committed. The |process_id| parameter is - // is the process id of the renderer. - void CommitNavigation(int process_id); - private: - int appcache_host_id_; + const int appcache_host_id_; std::unique_ptr<AppCacheNavigationHandleCore> core_; - base::WeakPtrFactory<AppCacheNavigationHandle> weak_factory_; DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationHandle); }; diff --git a/chromium/content/browser/appcache/appcache_navigation_handle_core.cc b/chromium/content/browser/appcache/appcache_navigation_handle_core.cc index 1121e40975e..0c20a8fd7a7 100644 --- a/chromium/content/browser/appcache/appcache_navigation_handle_core.cc +++ b/chromium/content/browser/appcache/appcache_navigation_handle_core.cc @@ -28,14 +28,10 @@ base::LazyInstance<AppCacheHandleMap>::DestructorAtExit g_appcache_handle_map = namespace content { - AppCacheNavigationHandleCore::AppCacheNavigationHandleCore( - base::WeakPtr<AppCacheNavigationHandle> ui_handle, ChromeAppCacheService* appcache_service, int appcache_host_id) - : appcache_service_(appcache_service), - appcache_host_id_(appcache_host_id), - ui_handle_(ui_handle) { + : appcache_service_(appcache_service), appcache_host_id_(appcache_host_id) { // The AppCacheNavigationHandleCore is created on the UI thread but // should only be accessed from the IO thread afterwards. DCHECK_CURRENTLY_ON(BrowserThread::UI); diff --git a/chromium/content/browser/appcache/appcache_navigation_handle_core.h b/chromium/content/browser/appcache/appcache_navigation_handle_core.h index 93561916a65..b50429269f8 100644 --- a/chromium/content/browser/appcache/appcache_navigation_handle_core.h +++ b/chromium/content/browser/appcache/appcache_navigation_handle_core.h @@ -29,7 +29,6 @@ class ChromeAppCacheService; class AppCacheNavigationHandleCore : public AppCacheFrontend { public: AppCacheNavigationHandleCore( - base::WeakPtr<AppCacheNavigationHandle> ui_handle, ChromeAppCacheService* appcache_service, int appcache_host_id); ~AppCacheNavigationHandleCore() override; @@ -73,7 +72,6 @@ class AppCacheNavigationHandleCore : public AppCacheFrontend { std::unique_ptr<AppCacheHost> precreated_host_; scoped_refptr<ChromeAppCacheService> appcache_service_; int appcache_host_id_; - base::WeakPtr<AppCacheNavigationHandle> ui_handle_; DISALLOW_COPY_AND_ASSIGN(AppCacheNavigationHandleCore); }; diff --git a/chromium/content/browser/appcache/appcache_request_handler.cc b/chromium/content/browser/appcache/appcache_request_handler.cc index 07d2b0573e4..7f291f904b0 100644 --- a/chromium/content/browser/appcache/appcache_request_handler.cc +++ b/chromium/content/browser/appcache/appcache_request_handler.cc @@ -225,13 +225,13 @@ std::unique_ptr<AppCacheRequestHandler> AppCacheRequestHandler::InitializeForNavigationNetworkService( const network::ResourceRequest& request, AppCacheNavigationHandleCore* appcache_handle_core, - URLLoaderFactoryGetter* url_loader_factory_getter) { + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory) { std::unique_ptr<AppCacheRequestHandler> handler = appcache_handle_core->host()->CreateRequestHandler( AppCacheURLLoaderRequest::Create(request), static_cast<ResourceType>(request.resource_type), request.should_reset_appcache); - handler->network_url_loader_factory_getter_ = url_loader_factory_getter; + handler->network_loader_factory_ = std::move(network_loader_factory); handler->appcache_host_ = appcache_handle_core->host()->GetWeakPtr(); return handler; } @@ -600,7 +600,7 @@ AppCacheRequestHandler::MaybeCreateSubresourceLoaderParams() { // The factory is destroyed when the renderer drops the connection. network::mojom::URLLoaderFactoryPtr factory_ptr; AppCacheSubresourceURLFactory::CreateURLLoaderFactory( - network_url_loader_factory_getter_.get(), appcache_host_, &factory_ptr); + network_loader_factory_, appcache_host_, &factory_ptr); SubresourceLoaderParams params; params.loader_factory_info = factory_ptr.PassInterface(); diff --git a/chromium/content/browser/appcache/appcache_request_handler.h b/chromium/content/browser/appcache/appcache_request_handler.h index cea61697ba8..b8b82668b0e 100644 --- a/chromium/content/browser/appcache/appcache_request_handler.h +++ b/chromium/content/browser/appcache/appcache_request_handler.h @@ -18,9 +18,9 @@ #include "content/browser/appcache/appcache_request_handler.h" #include "content/browser/appcache/appcache_service_impl.h" #include "content/browser/loader/navigation_loader_interceptor.h" -#include "content/browser/url_loader_factory_getter.h" #include "content/common/content_export.h" #include "content/public/common/resource_type.h" +#include "services/network/public/cpp/shared_url_loader_factory.h" namespace net { class NetworkDelegate; @@ -109,7 +109,7 @@ class CONTENT_EXPORT AppCacheRequestHandler InitializeForNavigationNetworkService( const network::ResourceRequest& request, AppCacheNavigationHandleCore* appcache_handle_core, - URLLoaderFactoryGetter* url_loader_factory_getter); + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory); static bool IsMainResourceType(ResourceType type) { return IsResourceTypeFrame(type) || type == RESOURCE_TYPE_SHARED_WORKER; @@ -257,8 +257,8 @@ class CONTENT_EXPORT AppCacheRequestHandler // RequestHandler for non-error cases. bool should_create_subresource_loader_ = false; - // Points to the getter for the network URL loader. - scoped_refptr<URLLoaderFactoryGetter> network_url_loader_factory_getter_; + // The network URL loader factory. + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory_; // The AppCache host instance. We pass this to the // AppCacheSubresourceURLFactory instance on creation. diff --git a/chromium/content/browser/appcache/appcache_request_handler_unittest.cc b/chromium/content/browser/appcache/appcache_request_handler_unittest.cc index 3e742cdca67..bd3494c4aa9 100644 --- a/chromium/content/browser/appcache/appcache_request_handler_unittest.cc +++ b/chromium/content/browser/appcache/appcache_request_handler_unittest.cc @@ -22,7 +22,6 @@ #include "base/strings/stringprintf.h" #include "base/synchronization/waitable_event.h" #include "base/test/scoped_feature_list.h" -#include "base/test/scoped_task_environment.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" #include "content/browser/appcache/appcache.h" @@ -34,6 +33,7 @@ #include "content/browser/appcache/appcache_url_request_job.h" #include "content/browser/appcache/mock_appcache_policy.h" #include "content/browser/appcache/mock_appcache_service.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "net/base/net_errors.h" #include "net/base/request_priority.h" #include "net/http/http_response_headers.h" @@ -202,15 +202,14 @@ class AppCacheRequestHandlerTest }; static void SetUpTestCase() { - scoped_task_environment_.reset(new base::test::ScopedTaskEnvironment); - io_thread_.reset(new base::Thread("AppCacheRequestHandlerTest Thread")); - base::Thread::Options options(base::MessageLoop::TYPE_IO, 0); - io_thread_->StartWithOptions(options); + thread_bundle_.reset( + new TestBrowserThreadBundle(TestBrowserThreadBundle::REAL_IO_THREAD)); + io_task_runner_ = BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); } static void TearDownTestCase() { - io_thread_.reset(); - scoped_task_environment_.reset(); + thread_bundle_.reset(); + io_task_runner_ = nullptr; } // Test harness -------------------------------------------------- @@ -231,7 +230,7 @@ class AppCacheRequestHandlerTest test_finished_event_.reset(new base::WaitableEvent( base::WaitableEvent::ResetPolicy::AUTOMATIC, base::WaitableEvent::InitialState::NOT_SIGNALED)); - io_thread_->task_runner()->PostTask( + io_task_runner_->PostTask( FROM_HERE, base::BindOnce(&AppCacheRequestHandlerTest::MethodWrapper<Method>, base::Unretained(this), method)); @@ -239,7 +238,7 @@ class AppCacheRequestHandlerTest } void SetUpTest() { - DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); mock_service_.reset(new MockAppCacheService); // Initializes URLRequestContext on the IO thread. empty_context_.reset(new net::URLRequestContext); @@ -258,7 +257,7 @@ class AppCacheRequestHandlerTest } void TearDownTest() { - DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); appcache_url_request_job_.reset(); appcache_url_loader_job_.reset(); handler_.reset(); @@ -276,7 +275,7 @@ class AppCacheRequestHandlerTest void TestFinished() { // We unwind the stack prior to finishing up to let stack // based objects get deleted. - DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); base::ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, base::BindOnce(&AppCacheRequestHandlerTest::TestFinishedUnwound, @@ -293,7 +292,7 @@ class AppCacheRequestHandlerTest } void ScheduleNextTask() { - DCHECK(io_thread_->task_runner()->BelongsToCurrentThread()); + DCHECK(io_task_runner_->BelongsToCurrentThread()); if (task_stack_.empty()) { TestFinished(); return; @@ -969,18 +968,18 @@ class AppCacheRequestHandlerTest std::unique_ptr<AppCacheURLRequestJob> appcache_url_request_job_; base::WeakPtr<AppCacheURLLoaderJob> appcache_url_loader_job_; - static std::unique_ptr<base::Thread> io_thread_; - static std::unique_ptr<base::test::ScopedTaskEnvironment> - scoped_task_environment_; + static std::unique_ptr<TestBrowserThreadBundle> thread_bundle_; + static scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; RequestHandlerType request_handler_type_; base::test::ScopedFeatureList feature_list_; }; // static -std::unique_ptr<base::Thread> AppCacheRequestHandlerTest::io_thread_; -std::unique_ptr<base::test::ScopedTaskEnvironment> - AppCacheRequestHandlerTest::scoped_task_environment_; +std::unique_ptr<TestBrowserThreadBundle> + AppCacheRequestHandlerTest::thread_bundle_; +scoped_refptr<base::SingleThreadTaskRunner> + AppCacheRequestHandlerTest::io_task_runner_; TEST_P(AppCacheRequestHandlerTest, MainResource_Miss) { RunTestOnIOThread(&AppCacheRequestHandlerTest::MainResource_Miss); diff --git a/chromium/content/browser/appcache/appcache_service_impl.h b/chromium/content/browser/appcache/appcache_service_impl.h index ff3bcd5153d..bf6fabe30ff 100644 --- a/chromium/content/browser/appcache/appcache_service_impl.h +++ b/chromium/content/browser/appcache/appcache_service_impl.h @@ -153,7 +153,7 @@ class CONTENT_EXPORT AppCacheServiceImpl // Each child process in chrome uses a distinct backend instance. // See chrome/browser/AppCacheDispatcherHost. void RegisterBackend(AppCacheBackendImpl* backend_impl); - void UnregisterBackend(AppCacheBackendImpl* backend_impl); + virtual void UnregisterBackend(AppCacheBackendImpl* backend_impl); AppCacheBackendImpl* GetBackend(int id) const { BackendMap::const_iterator it = backends_.find(id); return (it != backends_.end()) ? it->second : NULL; diff --git a/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc b/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc index 43400a1f726..03237c227d3 100644 --- a/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc +++ b/chromium/content/browser/appcache/appcache_storage_impl_unittest.cc @@ -375,7 +375,9 @@ class AppCacheStorageImplTest : public testing::Test { // Test harness -------------------------------------------------- - AppCacheStorageImplTest() { request_delegate_.set_quit_on_complete(false); } + AppCacheStorageImplTest() { + request_delegate_.set_on_complete(base::DoNothing()); + } template <class Method> void RunTestOnIOThread(Method method) { diff --git a/chromium/content/browser/appcache/appcache_subresource_url_factory.cc b/chromium/content/browser/appcache/appcache_subresource_url_factory.cc index 72bb381ee93..08336328e4e 100644 --- a/chromium/content/browser/appcache/appcache_subresource_url_factory.cc +++ b/chromium/content/browser/appcache/appcache_subresource_url_factory.cc @@ -10,7 +10,6 @@ #include "content/browser/appcache/appcache_request_handler.h" #include "content/browser/appcache/appcache_url_loader_job.h" #include "content/browser/appcache/appcache_url_loader_request.h" -#include "content/browser/url_loader_factory_getter.h" #include "content/public/browser/browser_thread.h" #include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding_set.h" @@ -38,15 +37,16 @@ namespace { class SubresourceLoader : public network::mojom::URLLoader, public network::mojom::URLLoaderClient { public: - SubresourceLoader(network::mojom::URLLoaderRequest url_loader_request, - int32_t routing_id, - int32_t request_id, - uint32_t options, - const network::ResourceRequest& request, - network::mojom::URLLoaderClientPtr client, - const net::MutableNetworkTrafficAnnotationTag& annotation, - base::WeakPtr<AppCacheHost> appcache_host, - scoped_refptr<URLLoaderFactoryGetter> net_factory_getter) + SubresourceLoader( + network::mojom::URLLoaderRequest url_loader_request, + int32_t routing_id, + int32_t request_id, + uint32_t options, + const network::ResourceRequest& request, + network::mojom::URLLoaderClientPtr client, + const net::MutableNetworkTrafficAnnotationTag& annotation, + base::WeakPtr<AppCacheHost> appcache_host, + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory) : remote_binding_(this, std::move(url_loader_request)), remote_client_(std::move(client)), request_(request), @@ -54,7 +54,7 @@ class SubresourceLoader : public network::mojom::URLLoader, request_id_(request_id), options_(options), traffic_annotation_(annotation), - network_loader_factory_(std::move(net_factory_getter)), + network_loader_factory_(std::move(network_loader_factory)), local_client_binding_(this), host_(appcache_host), weak_factory_(this) { @@ -116,7 +116,7 @@ class SubresourceLoader : public network::mojom::URLLoader, DCHECK(!appcache_loader_); network::mojom::URLLoaderClientPtr client_ptr; local_client_binding_.Bind(mojo::MakeRequest(&client_ptr)); - network_loader_factory_->GetNetworkFactory()->CreateLoaderAndStart( + network_loader_factory_->CreateLoaderAndStart( mojo::MakeRequest(&network_loader_), routing_id_, request_id_, options_, request_, std::move(client_ptr), traffic_annotation_); if (has_set_priority_) @@ -127,13 +127,15 @@ class SubresourceLoader : public network::mojom::URLLoader, // network::mojom::URLLoader implementation // Called by the remote client in the renderer. - void FollowRedirect(const base::Optional<net::HttpRequestHeaders>& + void FollowRedirect(const base::Optional<std::vector<std::string>>& + to_be_removed_request_headers, + const base::Optional<net::HttpRequestHeaders>& modified_request_headers) override { DCHECK(!modified_request_headers.has_value()) << "Redirect with modified headers was not supported yet. " "crbug.com/845683"; if (!handler_) { - network_loader_->FollowRedirect(base::nullopt); + network_loader_->FollowRedirect(base::nullopt, base::nullopt); return; } DCHECK(network_loader_); @@ -152,7 +154,7 @@ class SubresourceLoader : public network::mojom::URLLoader, if (handler) CreateAndStartAppCacheLoader(std::move(handler)); else - network_loader_->FollowRedirect(base::nullopt); + network_loader_->FollowRedirect(base::nullopt, base::nullopt); } void SetPriority(net::RequestPriority priority, @@ -179,12 +181,10 @@ class SubresourceLoader : public network::mojom::URLLoader, // network::mojom::URLLoaderClient implementation // Called by either the appcache or network loader, whichever is in use. void OnReceiveResponse( - const network::ResourceResponseHead& response_head, - network::mojom::DownloadedTempFilePtr downloaded_file) override { + const network::ResourceResponseHead& response_head) override { // Don't MaybeFallback for appcache produced responses. if (appcache_loader_ || !handler_) { - remote_client_->OnReceiveResponse(response_head, - std::move(downloaded_file)); + remote_client_->OnReceiveResponse(response_head); return; } @@ -192,19 +192,16 @@ class SubresourceLoader : public network::mojom::URLLoader, handler_->MaybeFallbackForSubresourceResponse( response_head, base::BindOnce(&SubresourceLoader::ContinueOnReceiveResponse, - weak_factory_.GetWeakPtr(), response_head, - std::move(downloaded_file))); + weak_factory_.GetWeakPtr(), response_head)); } void ContinueOnReceiveResponse( const network::ResourceResponseHead& response_head, - network::mojom::DownloadedTempFilePtr downloaded_file, SingleRequestURLLoaderFactory::RequestHandler handler) { if (handler) { CreateAndStartAppCacheLoader(std::move(handler)); } else { - remote_client_->OnReceiveResponse(response_head, - std::move(downloaded_file)); + remote_client_->OnReceiveResponse(response_head); } } @@ -237,10 +234,6 @@ class SubresourceLoader : public network::mojom::URLLoader, remote_client_->OnReceiveRedirect(redirect_info_, response_head); } - void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override { - remote_client_->OnDataDownloaded(data_len, encoded_data_len); - } - void OnUploadProgress(int64_t current_position, int64_t total_size, OnUploadProgressCallback ack_callback) override { @@ -291,7 +284,7 @@ class SubresourceLoader : public network::mojom::URLLoader, int32_t request_id_; uint32_t options_; net::MutableNetworkTrafficAnnotationTag traffic_annotation_; - scoped_refptr<URLLoaderFactoryGetter> network_loader_factory_; + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory_; net::RedirectInfo redirect_info_; int redirect_limit_ = net::URLRequest::kMaxRedirects; bool did_receive_network_response_ = false; @@ -319,9 +312,9 @@ class SubresourceLoader : public network::mojom::URLLoader, // Implements the URLLoaderFactory mojom for AppCache requests. AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory( - URLLoaderFactoryGetter* default_url_loader_factory_getter, + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory, base::WeakPtr<AppCacheHost> host) - : default_url_loader_factory_getter_(default_url_loader_factory_getter), + : network_loader_factory_(std::move(network_loader_factory)), appcache_host_(host), weak_factory_(this) { bindings_.set_connection_error_handler( @@ -333,7 +326,7 @@ AppCacheSubresourceURLFactory::~AppCacheSubresourceURLFactory() {} // static void AppCacheSubresourceURLFactory::CreateURLLoaderFactory( - URLLoaderFactoryGetter* default_url_loader_factory_getter, + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory, base::WeakPtr<AppCacheHost> host, network::mojom::URLLoaderFactoryPtr* loader_factory) { DCHECK(host.get()); @@ -341,7 +334,7 @@ void AppCacheSubresourceURLFactory::CreateURLLoaderFactory( // to it and will get deleted when all clients drop their connections. // Please see OnConnectionError() for details. auto* impl = new AppCacheSubresourceURLFactory( - default_url_loader_factory_getter, host); + std::move(network_loader_factory), host); impl->Clone(mojo::MakeRequest(loader_factory)); // Save the factory in the host to ensure that we don't create it again when @@ -360,7 +353,7 @@ void AppCacheSubresourceURLFactory::CreateLoaderAndStart( DCHECK_CURRENTLY_ON(BrowserThread::IO); new SubresourceLoader(std::move(url_loader_request), routing_id, request_id, options, request, std::move(client), traffic_annotation, - appcache_host_, default_url_loader_factory_getter_); + appcache_host_, network_loader_factory_); } void AppCacheSubresourceURLFactory::Clone( diff --git a/chromium/content/browser/appcache/appcache_subresource_url_factory.h b/chromium/content/browser/appcache/appcache_subresource_url_factory.h index 9ed9fc82161..c2ecf3420cd 100644 --- a/chromium/content/browser/appcache/appcache_subresource_url_factory.h +++ b/chromium/content/browser/appcache/appcache_subresource_url_factory.h @@ -13,13 +13,16 @@ #include "services/network/public/mojom/url_loader_factory.mojom.h" #include "url/gurl.h" +namespace network { +class SharedURLLoaderFactory; +} + namespace content { class AppCacheHost; class AppCacheJob; class AppCacheRequestHandler; class AppCacheServiceImpl; -class URLLoaderFactoryGetter; // Implements the URLLoaderFactory mojom for AppCache subresource requests. class CONTENT_EXPORT AppCacheSubresourceURLFactory @@ -28,13 +31,12 @@ class CONTENT_EXPORT AppCacheSubresourceURLFactory ~AppCacheSubresourceURLFactory() override; // Factory function to create an instance of the factory. - // 1. The |factory_getter| parameter is used to query the network service - // to pass network requests to. - // 2. The |host| parameter contains the appcache host instance. This is used - // to create the AppCacheRequestHandler instances for handling subresource - // requests. + // The |host| parameter contains the appcache host instance. This is used + // to create the AppCacheRequestHandler instances for handling subresource + // requests. + // |network_loader_factory| is a factory to the Network Service. static void CreateURLLoaderFactory( - URLLoaderFactoryGetter* factory_getter, + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory, base::WeakPtr<AppCacheHost> host, network::mojom::URLLoaderFactoryPtr* loader_factory); @@ -56,12 +58,13 @@ class CONTENT_EXPORT AppCacheSubresourceURLFactory // TODO(michaeln): Declare SubresourceLoader here and add unittests. - AppCacheSubresourceURLFactory(URLLoaderFactoryGetter* factory_getter, - base::WeakPtr<AppCacheHost> host); + AppCacheSubresourceURLFactory( + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory, + base::WeakPtr<AppCacheHost> host); void OnConnectionError(); mojo::BindingSet<network::mojom::URLLoaderFactory> bindings_; - scoped_refptr<URLLoaderFactoryGetter> default_url_loader_factory_getter_; + scoped_refptr<network::SharedURLLoaderFactory> network_loader_factory_; base::WeakPtr<AppCacheHost> appcache_host_; base::WeakPtrFactory<AppCacheSubresourceURLFactory> weak_factory_; DISALLOW_COPY_AND_ASSIGN(AppCacheSubresourceURLFactory); diff --git a/chromium/content/browser/appcache/appcache_update_job_unittest.cc b/chromium/content/browser/appcache/appcache_update_job_unittest.cc index c02b0f17956..d801ffce9a4 100644 --- a/chromium/content/browser/appcache/appcache_update_job_unittest.cc +++ b/chromium/content/browser/appcache/appcache_update_job_unittest.cc @@ -624,7 +624,7 @@ class MockURLLoaderFactory : public network::mojom::URLLoaderFactory { response.headers = info.headers; response.headers->GetMimeType(&response.mime_type); - client->OnReceiveResponse(response, nullptr); + client->OnReceiveResponse(response); mojo::DataPipe data_pipe; @@ -831,10 +831,8 @@ class AppCacheUpdateJobTest : public testing::TestWithParam<RequestHandlerType>, expected = 2; // 2 hosts using frontend1 EXPECT_EQ(expected, events[0].first.size()); MockFrontend::HostIds& host_ids = events[0].first; - EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host1.host_id()) - != host_ids.end()); - EXPECT_TRUE(std::find(host_ids.begin(), host_ids.end(), host3.host_id()) - != host_ids.end()); + EXPECT_TRUE(base::ContainsValue(host_ids, host1.host_id())); + EXPECT_TRUE(base::ContainsValue(host_ids, host3.host_id())); EXPECT_EQ(AppCacheEventID::APPCACHE_CHECKING_EVENT, events[0].second); events = mock_frontend2.raised_events_; @@ -3644,8 +3642,7 @@ class AppCacheUpdateJobTest : public testing::TestWithParam<RequestHandlerType>, for (size_t k = 0; k < expected_ids.size(); ++k) { int id = expected_ids[k]; - EXPECT_TRUE(std::find(actual_ids.begin(), actual_ids.end(), id) != - actual_ids.end()); + EXPECT_TRUE(base::ContainsValue(actual_ids, id)); } } diff --git a/chromium/content/browser/appcache/appcache_update_url_loader_request.cc b/chromium/content/browser/appcache/appcache_update_url_loader_request.cc index 321e4fad8ba..3f5051c2d8c 100644 --- a/chromium/content/browser/appcache/appcache_update_url_loader_request.cc +++ b/chromium/content/browser/appcache/appcache_update_url_loader_request.cc @@ -94,8 +94,7 @@ int AppCacheUpdateJob::UpdateURLLoaderRequest::Cancel() { } void AppCacheUpdateJob::UpdateURLLoaderRequest::OnReceiveResponse( - const network::ResourceResponseHead& response_head, - network::mojom::DownloadedTempFilePtr downloaded_file) { + const network::ResourceResponseHead& response_head) { response_ = response_head; // TODO(ananta/michaeln) @@ -123,12 +122,6 @@ void AppCacheUpdateJob::UpdateURLLoaderRequest::OnReceiveRedirect( fetcher_->OnReceivedRedirect(redirect_info); } -void AppCacheUpdateJob::UpdateURLLoaderRequest::OnDataDownloaded( - int64_t data_len, - int64_t encoded_data_len) { - NOTIMPLEMENTED(); -} - void AppCacheUpdateJob::UpdateURLLoaderRequest::OnUploadProgress( int64_t current_position, int64_t total_size, diff --git a/chromium/content/browser/appcache/appcache_update_url_loader_request.h b/chromium/content/browser/appcache/appcache_update_url_loader_request.h index e7279f62572..d826fc30fa4 100644 --- a/chromium/content/browser/appcache/appcache_update_url_loader_request.h +++ b/chromium/content/browser/appcache/appcache_update_url_loader_request.h @@ -54,12 +54,10 @@ class AppCacheUpdateJob::UpdateURLLoaderRequest // network::mojom::URLLoaderClient implementation. // These methods are called by the network loader. void OnReceiveResponse( - const network::ResourceResponseHead& response_head, - network::mojom::DownloadedTempFilePtr downloaded_file) override; + const network::ResourceResponseHead& response_head) override; void OnReceiveRedirect( const net::RedirectInfo& redirect_info, const network::ResourceResponseHead& response_head) override; - void OnDataDownloaded(int64_t data_len, int64_t encoded_data_len) override; void OnUploadProgress(int64_t current_position, int64_t total_size, OnUploadProgressCallback ack_callback) override; diff --git a/chromium/content/browser/appcache/appcache_url_loader_job.cc b/chromium/content/browser/appcache/appcache_url_loader_job.cc index b3969898ae2..1455c9f3f23 100644 --- a/chromium/content/browser/appcache/appcache_url_loader_job.cc +++ b/chromium/content/browser/appcache/appcache_url_loader_job.cc @@ -106,6 +106,8 @@ base::WeakPtr<AppCacheURLLoaderJob> AppCacheURLLoaderJob::GetDerivedWeakPtr() { } void AppCacheURLLoaderJob::FollowRedirect( + const base::Optional<std::vector<std::string>>& + to_be_removed_request_headers, const base::Optional<net::HttpRequestHeaders>& modified_request_headers) { NOTREACHED() << "appcache never produces redirects"; } @@ -287,8 +289,7 @@ void AppCacheURLLoaderJob::SendResponseInfo() { response_head.ssl_info = http_info->ssl_info; response_head.load_timing = load_timing_info_; - client_->OnReceiveResponse(response_head, - network::mojom::DownloadedTempFilePtr()); + client_->OnReceiveResponse(response_head); client_->OnStartLoadingResponseBody(std::move(data_pipe_.consumer_handle)); } diff --git a/chromium/content/browser/appcache/appcache_url_loader_job.h b/chromium/content/browser/appcache/appcache_url_loader_job.h index d116c91d890..1cc9ae22816 100644 --- a/chromium/content/browser/appcache/appcache_url_loader_job.h +++ b/chromium/content/browser/appcache/appcache_url_loader_job.h @@ -55,7 +55,9 @@ class CONTENT_EXPORT AppCacheURLLoaderJob : public AppCacheJob, base::WeakPtr<AppCacheURLLoaderJob> GetDerivedWeakPtr(); // network::mojom::URLLoader implementation: - void FollowRedirect(const base::Optional<net::HttpRequestHeaders>& + void FollowRedirect(const base::Optional<std::vector<std::string>>& + to_be_removed_request_headers, + const base::Optional<net::HttpRequestHeaders>& modified_request_headers) override; void ProceedWithResponse() override; void SetPriority(net::RequestPriority priority, diff --git a/chromium/content/browser/appcache/appcache_url_loader_request.cc b/chromium/content/browser/appcache/appcache_url_loader_request.cc index 68b55a93369..03e37c05688 100644 --- a/chromium/content/browser/appcache/appcache_url_loader_request.cc +++ b/chromium/content/browser/appcache/appcache_url_loader_request.cc @@ -77,9 +77,10 @@ base::WeakPtr<AppCacheURLLoaderRequest> AppCacheURLLoaderRequest::GetWeakPtr() { void AppCacheURLLoaderRequest::UpdateWithRedirectInfo( const net::RedirectInfo& redirect_info) { bool not_used_clear_body; - net::RedirectUtil::UpdateHttpRequest(request_.url, request_.method, - redirect_info, &request_.headers, - ¬_used_clear_body); + net::RedirectUtil::UpdateHttpRequest( + request_.url, request_.method, redirect_info, + base::nullopt /* modified_request_headers */, &request_.headers, + ¬_used_clear_body); request_.url = redirect_info.new_url; request_.method = redirect_info.new_method; request_.referrer = GURL(redirect_info.new_referrer); diff --git a/chromium/content/browser/appcache/chrome_appcache_service.cc b/chromium/content/browser/appcache/chrome_appcache_service.cc index 89ccb9a8250..5c95cb9ee21 100644 --- a/chromium/content/browser/appcache/chrome_appcache_service.cc +++ b/chromium/content/browser/appcache/chrome_appcache_service.cc @@ -45,8 +45,26 @@ void ChromeAppCacheService::InitializeOnIOThread( void ChromeAppCacheService::Bind( std::unique_ptr<mojom::AppCacheBackend> backend, - mojom::AppCacheBackendRequest request) { - bindings_.AddBinding(std::move(backend), std::move(request)); + mojom::AppCacheBackendRequest request, + int process_id) { + DCHECK(process_bindings_.find(process_id) == process_bindings_.end()); + process_bindings_[process_id] = + bindings_.AddBinding(std::move(backend), std::move(request)); +} + +void ChromeAppCacheService::Unbind(int process_id) { + auto it = process_bindings_.find(process_id); + if (it != process_bindings_.end()) { + bindings_.RemoveBinding(it->second); + DCHECK(process_bindings_.find(process_id) == process_bindings_.end()); + } +} + +void ChromeAppCacheService::UnregisterBackend( + AppCacheBackendImpl* backend_impl) { + int process_id = backend_impl->process_id(); + process_bindings_.erase(process_bindings_.find(process_id)); + AppCacheServiceImpl::UnregisterBackend(backend_impl); } void ChromeAppCacheService::Shutdown() { diff --git a/chromium/content/browser/appcache/chrome_appcache_service.h b/chromium/content/browser/appcache/chrome_appcache_service.h index 7845936ea43..316f2c4c83d 100644 --- a/chromium/content/browser/appcache/chrome_appcache_service.h +++ b/chromium/content/browser/appcache/chrome_appcache_service.h @@ -9,6 +9,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/sequenced_task_runner_helpers.h" +#include "content/browser/appcache/appcache_backend_impl.h" #include "content/browser/appcache/appcache_policy.h" #include "content/browser/appcache/appcache_service_impl.h" #include "content/common/appcache.mojom.h" @@ -56,7 +57,14 @@ class CONTENT_EXPORT ChromeAppCacheService scoped_refptr<storage::SpecialStoragePolicy> special_storage_policy); void Bind(std::unique_ptr<mojom::AppCacheBackend> backend, - mojom::AppCacheBackendRequest request); + mojom::AppCacheBackendRequest request, + int process_id); + // Unbinds the pipe corresponding to the given process_id. Unbinding + // unregisters and destroys the existing backend for that process_id. + // The function must be called before a new backend is created for the given + // process_id to ensure that there is at most one backend per process_id. + // The function does nothing if no pipe was bound. + void Unbind(int process_id); void Shutdown(); @@ -66,6 +74,9 @@ class CONTENT_EXPORT ChromeAppCacheService bool CanCreateAppCache(const GURL& manifest_url, const GURL& first_party) override; + // AppCacheServiceImpl override + void UnregisterBackend(AppCacheBackendImpl* backend_impl) override; + protected: ~ChromeAppCacheService() override; @@ -81,6 +92,9 @@ class CONTENT_EXPORT ChromeAppCacheService base::FilePath cache_path_; mojo::StrongBindingSet<mojom::AppCacheBackend> bindings_; + // A map from a process_id to a binding_id. + std::map<int, mojo::BindingId> process_bindings_; + DISALLOW_COPY_AND_ASSIGN(ChromeAppCacheService); }; |