Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7047)

Unified Diff: content/browser/appcache/appcache_dispatcher_host.cc

Issue 2501343003: PlzNavigate: AppCache support. (Closed)
Patch Set: Fix content_browsertests rednesss Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/appcache/appcache_dispatcher_host.cc
diff --git a/content/browser/appcache/appcache_dispatcher_host.cc b/content/browser/appcache/appcache_dispatcher_host.cc
index 2eb90dd5189e5630c4b3baadc6cb9d40995e4791..f3be3707a2e018c3ca5cca70913691a7e45c99b5 100644
--- a/content/browser/appcache/appcache_dispatcher_host.cc
+++ b/content/browser/appcache/appcache_dispatcher_host.cc
@@ -4,12 +4,22 @@
#include "content/browser/appcache/appcache_dispatcher_host.h"
+#include <map>
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "content/browser/appcache/chrome_appcache_service.h"
#include "content/browser/bad_message.h"
#include "content/common/appcache_messages.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.h"
+#include "content/public/common/browser_side_navigation_policy.h"
+
+namespace {
+
+using ProcessIdToHostMap = std::map < int, content::AppCacheDispatcherHost* >;
+base::LazyInstance<ProcessIdToHostMap> g_process_id_host_map;
+
+} // namespace
namespace content {
@@ -21,22 +31,21 @@ AppCacheDispatcherHost::AppCacheDispatcherHost(
frontend_proxy_(this),
process_id_(process_id),
weak_factory_(this) {
+ g_process_id_host_map.Get()[process_id] = this;
michaeln 2016/12/05 21:52:54 ok, we have to do something about accessing this m
ananta 2016/12/06 01:24:38 Done. Thanks for the tip. PTAL
}
void AppCacheDispatcherHost::OnChannelConnected(int32_t peer_pid) {
- if (appcache_service_.get()) {
- backend_impl_.Initialize(
- appcache_service_.get(), &frontend_proxy_, process_id_);
- get_status_callback_ =
- base::Bind(&AppCacheDispatcherHost::GetStatusCallback,
- weak_factory_.GetWeakPtr());
- start_update_callback_ =
- base::Bind(&AppCacheDispatcherHost::StartUpdateCallback,
- weak_factory_.GetWeakPtr());
- swap_cache_callback_ =
- base::Bind(&AppCacheDispatcherHost::SwapCacheCallback,
- weak_factory_.GetWeakPtr());
- }
+ if (!appcache_service_.get())
+ return;
+
+ backend_impl_.Initialize(appcache_service_.get(), &frontend_proxy_,
+ process_id_);
+ get_status_callback_ = base::Bind(&AppCacheDispatcherHost::GetStatusCallback,
+ weak_factory_.GetWeakPtr());
+ start_update_callback_ = base::Bind(
+ &AppCacheDispatcherHost::StartUpdateCallback, weak_factory_.GetWeakPtr());
+ swap_cache_callback_ = base::Bind(&AppCacheDispatcherHost::SwapCacheCallback,
+ weak_factory_.GetWeakPtr());
}
bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) {
@@ -62,7 +71,19 @@ bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-AppCacheDispatcherHost::~AppCacheDispatcherHost() {}
+AppCacheDispatcherHost::~AppCacheDispatcherHost() {
+ ProcessIdToHostMap::iterator index =
+ g_process_id_host_map.Get().find(process_id_);
+ if ((index != g_process_id_host_map.Get().end()) && index->second == this)
+ g_process_id_host_map.Get().erase(index);
+}
+
+void AppCacheDispatcherHost::RegisterPrecreatedHost(
+ std::unique_ptr<AppCacheHost> host) {
+ DCHECK(host.get());
+ DCHECK(IsBrowserSideNavigationEnabled());
+ backend_impl_.RegisterPrecreatedHost(std::move(host));
+}
void AppCacheDispatcherHost::OnRegisterHost(int host_id) {
if (appcache_service_.get()) {
@@ -94,8 +115,7 @@ void AppCacheDispatcherHost::OnSelectCache(
int64_t cache_document_was_loaded_from,
const GURL& opt_manifest_url) {
if (appcache_service_.get()) {
- if (!backend_impl_.SelectCache(host_id,
- document_url,
+ if (!backend_impl_.SelectCache(host_id, document_url,
cache_document_was_loaded_from,
opt_manifest_url)) {
bad_message::ReceivedBadMessage(this, bad_message::ACDH_SELECT_CACHE);
@@ -108,8 +128,8 @@ void AppCacheDispatcherHost::OnSelectCache(
void AppCacheDispatcherHost::OnSelectCacheForWorker(
int host_id, int parent_process_id, int parent_host_id) {
if (appcache_service_.get()) {
- if (!backend_impl_.SelectCacheForWorker(
- host_id, parent_process_id, parent_host_id)) {
+ if (!backend_impl_.SelectCacheForWorker(host_id, parent_process_id,
+ parent_host_id)) {
bad_message::ReceivedBadMessage(
this, bad_message::ACDH_SELECT_CACHE_FOR_WORKER);
}
@@ -134,8 +154,8 @@ void AppCacheDispatcherHost::OnMarkAsForeignEntry(
const GURL& document_url,
int64_t cache_document_was_loaded_from) {
if (appcache_service_.get()) {
- if (!backend_impl_.MarkAsForeignEntry(
- host_id, document_url, cache_document_was_loaded_from)) {
+ if (!backend_impl_.MarkAsForeignEntry(host_id, document_url,
+ cache_document_was_loaded_from)) {
bad_message::ReceivedBadMessage(this,
bad_message::ACDH_MARK_AS_FOREIGN_ENTRY);
}
@@ -158,8 +178,8 @@ void AppCacheDispatcherHost::OnGetStatus(int host_id, IPC::Message* reply_msg) {
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.GetStatusWithCallback(
- host_id, get_status_callback_, reply_msg)) {
+ if (!backend_impl_.GetStatusWithCallback(host_id, get_status_callback_,
+ reply_msg)) {
bad_message::ReceivedBadMessage(this, bad_message::ACDH_GET_STATUS);
}
return;
@@ -179,8 +199,8 @@ void AppCacheDispatcherHost::OnStartUpdate(int host_id,
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.StartUpdateWithCallback(
- host_id, start_update_callback_, reply_msg)) {
+ if (!backend_impl_.StartUpdateWithCallback(host_id, start_update_callback_,
+ reply_msg)) {
bad_message::ReceivedBadMessage(this, bad_message::ACDH_START_UPDATE);
}
return;
@@ -199,8 +219,8 @@ void AppCacheDispatcherHost::OnSwapCache(int host_id, IPC::Message* reply_msg) {
pending_reply_msg_.reset(reply_msg);
if (appcache_service_.get()) {
- if (!backend_impl_.SwapCacheWithCallback(
- host_id, swap_cache_callback_, reply_msg)) {
+ if (!backend_impl_.SwapCacheWithCallback(host_id, swap_cache_callback_,
+ reply_msg)) {
bad_message::ReceivedBadMessage(this, bad_message::ACDH_SWAP_CACHE);
}
return;
@@ -231,4 +251,14 @@ void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) {
Send(pending_reply_msg_.release());
}
+// static
+scoped_refptr<AppCacheDispatcherHost> AppCacheDispatcherHost::GetHostForProcess(
+ int process_id) {
+ ProcessIdToHostMap::iterator index =
+ g_process_id_host_map.Get().find(process_id);
+ if (index == g_process_id_host_map.Get().end())
+ return scoped_refptr<AppCacheDispatcherHost>();
+ return index->second;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698