OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "base/string16.h" |
| 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/browser/renderer_host/render_view_host.h" |
| 12 #include "chrome/common/render_messages.h" |
| 13 |
| 14 NotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id, |
| 15 int notification_id, bool worker) |
| 16 : process_id_(process_id), |
| 17 route_id_(route_id), |
| 18 notification_id_(notification_id), |
| 19 worker_(worker) { |
| 20 } |
| 21 |
| 22 void NotificationObjectProxy::Display() { |
| 23 if (worker_) { |
| 24 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. |
| 25 NOTREACHED(); |
| 26 } else { |
| 27 DeliverMessage(new ViewMsg_PostDisplayToNotificationObject( |
| 28 route_id_, notification_id_)); |
| 29 } |
| 30 } |
| 31 |
| 32 void NotificationObjectProxy::Error() { |
| 33 if (worker_) { |
| 34 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. |
| 35 NOTREACHED(); |
| 36 } else { |
| 37 DeliverMessage(new ViewMsg_PostErrorToNotificationObject( |
| 38 route_id_, notification_id_, string16())); |
| 39 } |
| 40 } |
| 41 |
| 42 void NotificationObjectProxy::Close(bool by_user) { |
| 43 if (worker_) { |
| 44 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon. |
| 45 NOTREACHED(); |
| 46 } else { |
| 47 DeliverMessage(new ViewMsg_PostCloseToNotificationObject( |
| 48 route_id_, notification_id_, by_user)); |
| 49 } |
| 50 } |
| 51 |
| 52 void NotificationObjectProxy::DeliverMessage(IPC::Message* message) { |
| 53 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 54 MessageLoop* io_loop = ChromeThread::GetMessageLoop(ChromeThread::IO); |
| 55 if (io_loop) { |
| 56 io_loop->PostTask(FROM_HERE, |
| 57 NewRunnableMethod(this, &NotificationObjectProxy::Send, message)); |
| 58 } |
| 59 } |
| 60 |
| 61 // Deferred method which runs on the IO thread and sends a message to the |
| 62 // proxied notification, routing it through the correct host in the browser. |
| 63 void NotificationObjectProxy::Send(IPC::Message* message) { |
| 64 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 65 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_); |
| 66 if (host) |
| 67 host->Send(message); |
| 68 } |
OLD | NEW |