Refactor notification provider in renderer process to not use a message filter.

BUG=24241
TEST=not crashing

Review URL: http://codereview.chromium.org/276032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29064 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/renderer/notification_provider.cc b/chrome/renderer/notification_provider.cc
index 505349d..0c1b789b 100644
--- a/chrome/renderer/notification_provider.cc
+++ b/chrome/renderer/notification_provider.cc
@@ -60,6 +60,19 @@
                                                      GURL(origin), id));
 }
 
+bool NotificationProvider::OnMessageReceived(const IPC::Message& message) {
+  bool handled = true;
+  IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message)
+    IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay);
+    IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError);
+    IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose);
+    IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone,
+                        OnPermissionRequestComplete);
+    IPC_MESSAGE_UNHANDLED(handled = false)
+  IPC_END_MESSAGE_MAP()
+  return handled;
+}
+
 bool NotificationProvider::ShowHTML(const WebNotification& notification,
                                     int id) {
   DCHECK(notification.isHTML());
@@ -78,30 +91,6 @@
 }
 
 void NotificationProvider::OnDisplay(int id) {
-  RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
-      NewRunnableMethod(this, &NotificationProvider::HandleOnDisplay, id));
-}
-
-void NotificationProvider::OnError(int id, const WebString& message) {
-  RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
-      NewRunnableMethod(this, &NotificationProvider::HandleOnError,
-                        id, message));
-}
-
-void NotificationProvider::OnClose(int id, bool by_user) {
-  RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
-      NewRunnableMethod(this, &NotificationProvider::HandleOnClose,
-                        id, by_user));
-}
-
-void NotificationProvider::OnPermissionRequestComplete(int id) {
-  RenderProcess::current()->main_thread()->message_loop()->PostTask(FROM_HERE,
-      NewRunnableMethod(this,
-          &NotificationProvider::HandleOnPermissionRequestComplete, id));
-}
-
-void NotificationProvider::HandleOnDisplay(int id) {
-  DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
   WebNotification notification;
   bool found = manager_.GetNotification(id, &notification);
   // |found| may be false if the WebNotification went out of scope in
@@ -110,8 +99,7 @@
     notification.dispatchDisplayEvent();
 }
 
-void NotificationProvider::HandleOnError(int id, const WebString& message) {
-  DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+void NotificationProvider::OnError(int id, const WebString& message) {
   WebNotification notification;
   bool found = manager_.GetNotification(id, &notification);
   // |found| may be false if the WebNotification went out of scope in
@@ -120,8 +108,7 @@
     notification.dispatchErrorEvent(message);
 }
 
-void NotificationProvider::HandleOnClose(int id, bool by_user) {
-  DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+void NotificationProvider::OnClose(int id, bool by_user) {
   WebNotification notification;
   bool found = manager_.GetNotification(id, &notification);
   // |found| may be false if the WebNotification went out of scope in
@@ -131,30 +118,13 @@
   manager_.UnregisterNotification(id);
 }
 
-void NotificationProvider::HandleOnPermissionRequestComplete(int id) {
-  DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+void NotificationProvider::OnPermissionRequestComplete(int id) {
   WebNotificationPermissionCallback* callback = manager_.GetCallback(id);
   DCHECK(callback);
   callback->permissionRequestComplete();
   manager_.OnPermissionRequestComplete(id);
 }
 
-bool NotificationProvider::OnMessageReceived(const IPC::Message& message) {
-  if (message.routing_id() != view_->routing_id())
-    return false;
-
-  bool handled = true;
-  IPC_BEGIN_MESSAGE_MAP(NotificationProvider, message)
-    IPC_MESSAGE_HANDLER(ViewMsg_PostDisplayToNotificationObject, OnDisplay);
-    IPC_MESSAGE_HANDLER(ViewMsg_PostErrorToNotificationObject, OnError);
-    IPC_MESSAGE_HANDLER(ViewMsg_PostCloseToNotificationObject, OnClose);
-    IPC_MESSAGE_HANDLER(ViewMsg_PermissionRequestDone,
-                        OnPermissionRequestComplete);
-    IPC_MESSAGE_UNHANDLED(handled = false)
-  IPC_END_MESSAGE_MAP()
-  return handled;
-}
-
 bool NotificationProvider::Send(IPC::Message* message) {
   return RenderThread::current()->Send(message);
 }