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

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

Issue 5625003: Make the AppCacheDispatcherHost be a MessageFilter so that ResourceMessageFil... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix dependency issue in AppCacheDispatcherHost Created 10 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: chrome/browser/appcache/appcache_dispatcher_host.cc
===================================================================
--- chrome/browser/appcache/appcache_dispatcher_host.cc (revision 68122)
+++ chrome/browser/appcache/appcache_dispatcher_host.cc (working copy)
@@ -11,28 +11,30 @@
#include "chrome/common/render_messages.h"
AppCacheDispatcherHost::AppCacheDispatcherHost(
- URLRequestContext* request_context)
- : request_context_(request_context),
- receiver_(NULL) {
+ URLRequestContext* request_context,
+ int process_id)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)),
+ request_context_(request_context),
+ process_id_(process_id) {
DCHECK(request_context_.get());
}
AppCacheDispatcherHost::AppCacheDispatcherHost(
- URLRequestContextGetter* request_context_getter)
- : request_context_getter_(request_context_getter),
- receiver_(NULL) {
+ URLRequestContextGetter* request_context_getter,
+ int process_id)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(frontend_proxy_(this)),
+ request_context_getter_(request_context_getter),
+ process_id_(process_id) {
DCHECK(request_context_getter_.get());
}
AppCacheDispatcherHost::~AppCacheDispatcherHost() {}
-void AppCacheDispatcherHost::Initialize(
- ResourceDispatcherHost::Receiver* receiver) {
- DCHECK(receiver && !receiver_);
+void AppCacheDispatcherHost::OnChannelConnected(int32 peer_pid) {
+ BrowserIOMessageFilter::OnChannelConnected(peer_pid);
+
DCHECK(request_context_.get() || request_context_getter_.get());
- receiver_ = receiver;
-
// Get the AppCacheService (it can only be accessed from IO thread).
URLRequestContext* context = request_context_.get();
if (!context)
@@ -42,10 +44,9 @@
request_context_ = NULL;
request_context_getter_ = NULL;
- frontend_proxy_.set_sender(receiver);
if (appcache_service_.get()) {
backend_impl_.Initialize(
- appcache_service_.get(), &frontend_proxy_, receiver->id());
+ appcache_service_.get(), &frontend_proxy_, process_id_);
get_status_callback_.reset(
NewCallback(this, &AppCacheDispatcherHost::GetStatusCallback));
start_update_callback_.reset(
@@ -55,12 +56,11 @@
}
}
-bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& msg,
- bool *msg_ok) {
- DCHECK(receiver_);
- *msg_ok = true;
+bool AppCacheDispatcherHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
- IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, msg, *msg_ok)
+ bool message_was_ok = true;
+
+ IPC_BEGIN_MESSAGE_MAP_EX(AppCacheDispatcherHost, message, message_was_ok)
IPC_MESSAGE_HANDLER(AppCacheMsg_RegisterHost, OnRegisterHost);
IPC_MESSAGE_HANDLER(AppCacheMsg_UnregisterHost, OnUnregisterHost);
IPC_MESSAGE_HANDLER(AppCacheMsg_GetResourceList, OnGetResourceList);
@@ -75,13 +75,17 @@
IPC_MESSAGE_HANDLER_DELAY_REPLY(AppCacheMsg_SwapCache, OnSwapCache);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP_EX()
+
+ if (!message_was_ok)
+ BadMessageReceived(message.type());
+
return handled;
}
void AppCacheDispatcherHost::OnRegisterHost(int host_id) {
if (appcache_service_.get()) {
if (!backend_impl_.RegisterHost(host_id)) {
- ReceivedBadMessage(AppCacheMsg_RegisterHost::ID);
+ BadMessageReceived(AppCacheMsg_RegisterHost::ID);
}
}
}
@@ -89,7 +93,7 @@
void AppCacheDispatcherHost::OnUnregisterHost(int host_id) {
if (appcache_service_.get()) {
if (!backend_impl_.UnregisterHost(host_id)) {
- ReceivedBadMessage(AppCacheMsg_UnregisterHost::ID);
+ BadMessageReceived(AppCacheMsg_UnregisterHost::ID);
}
}
}
@@ -102,7 +106,7 @@
if (!backend_impl_.SelectCache(host_id, document_url,
cache_document_was_loaded_from,
opt_manifest_url)) {
- ReceivedBadMessage(AppCacheMsg_SelectCache::ID);
+ BadMessageReceived(AppCacheMsg_SelectCache::ID);
}
} else {
frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
@@ -114,7 +118,7 @@
if (appcache_service_.get()) {
if (!backend_impl_.SelectCacheForWorker(
host_id, parent_process_id, parent_host_id)) {
- ReceivedBadMessage(AppCacheMsg_SelectCacheForWorker::ID);
+ BadMessageReceived(AppCacheMsg_SelectCacheForWorker::ID);
}
} else {
frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
@@ -125,7 +129,7 @@
int host_id, int64 appcache_id) {
if (appcache_service_.get()) {
if (!backend_impl_.SelectCacheForSharedWorker(host_id, appcache_id))
- ReceivedBadMessage(AppCacheMsg_SelectCacheForSharedWorker::ID);
+ BadMessageReceived(AppCacheMsg_SelectCacheForSharedWorker::ID);
} else {
frontend_proxy_.OnCacheSelected(host_id, appcache::AppCacheInfo());
}
@@ -137,7 +141,7 @@
if (appcache_service_.get()) {
if (!backend_impl_.MarkAsForeignEntry(host_id, document_url,
cache_document_was_loaded_from)) {
- ReceivedBadMessage(AppCacheMsg_MarkAsForeignEntry::ID);
+ BadMessageReceived(AppCacheMsg_MarkAsForeignEntry::ID);
}
}
}
@@ -151,7 +155,7 @@
void AppCacheDispatcherHost::OnGetStatus(int host_id,
IPC::Message* reply_msg) {
if (pending_reply_msg_.get()) {
- ReceivedBadMessage(AppCacheMsg_GetStatus::ID);
+ BadMessageReceived(AppCacheMsg_GetStatus::ID);
delete reply_msg;
return;
}
@@ -160,7 +164,7 @@
if (appcache_service_.get()) {
if (!backend_impl_.GetStatusWithCallback(
host_id, get_status_callback_.get(), reply_msg)) {
- ReceivedBadMessage(AppCacheMsg_GetStatus::ID);
+ BadMessageReceived(AppCacheMsg_GetStatus::ID);
}
return;
}
@@ -171,7 +175,7 @@
void AppCacheDispatcherHost::OnStartUpdate(int host_id,
IPC::Message* reply_msg) {
if (pending_reply_msg_.get()) {
- ReceivedBadMessage(AppCacheMsg_StartUpdate::ID);
+ BadMessageReceived(AppCacheMsg_StartUpdate::ID);
delete reply_msg;
return;
}
@@ -180,7 +184,7 @@
if (appcache_service_.get()) {
if (!backend_impl_.StartUpdateWithCallback(
host_id, start_update_callback_.get(), reply_msg)) {
- ReceivedBadMessage(AppCacheMsg_StartUpdate::ID);
+ BadMessageReceived(AppCacheMsg_StartUpdate::ID);
}
return;
}
@@ -191,7 +195,7 @@
void AppCacheDispatcherHost::OnSwapCache(int host_id,
IPC::Message* reply_msg) {
if (pending_reply_msg_.get()) {
- ReceivedBadMessage(AppCacheMsg_SwapCache::ID);
+ BadMessageReceived(AppCacheMsg_SwapCache::ID);
delete reply_msg;
return;
}
@@ -200,7 +204,7 @@
if (appcache_service_.get()) {
if (!backend_impl_.SwapCacheWithCallback(
host_id, swap_cache_callback_.get(), reply_msg)) {
- ReceivedBadMessage(AppCacheMsg_SwapCache::ID);
+ BadMessageReceived(AppCacheMsg_SwapCache::ID);
}
return;
}
@@ -213,26 +217,19 @@
IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
DCHECK(reply_msg == pending_reply_msg_.get());
AppCacheMsg_GetStatus::WriteReplyParams(reply_msg, status);
- frontend_proxy_.sender()->Send(pending_reply_msg_.release());
+ Send(pending_reply_msg_.release());
}
void AppCacheDispatcherHost::StartUpdateCallback(bool result, void* param) {
IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
DCHECK(reply_msg == pending_reply_msg_.get());
AppCacheMsg_StartUpdate::WriteReplyParams(reply_msg, result);
- frontend_proxy_.sender()->Send(pending_reply_msg_.release());
+ Send(pending_reply_msg_.release());
}
void AppCacheDispatcherHost::SwapCacheCallback(bool result, void* param) {
IPC::Message* reply_msg = reinterpret_cast<IPC::Message*>(param);
DCHECK(reply_msg == pending_reply_msg_.get());
AppCacheMsg_SwapCache::WriteReplyParams(reply_msg, result);
- frontend_proxy_.sender()->Send(pending_reply_msg_.release());
+ Send(pending_reply_msg_.release());
}
-
-void AppCacheDispatcherHost::ReceivedBadMessage(uint32 msg_type) {
- // TODO(michaeln): Consider gathering UMA stats
- // http://code.google.com/p/chromium/issues/detail?id=24634
- BrowserRenderProcessHost::BadMessageTerminateProcess(
- msg_type, receiver_->handle());
-}

Powered by Google App Engine
This is Rietveld 408576698