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 "content/browser/browser_thread.h"
10 #include "content/browser/renderer_host/render_view_host.h"
11 #include "content/common/desktop_notification_messages.h"
12
NotificationObjectProxy(int process_id,int route_id,int notification_id,bool worker)13 NotificationObjectProxy::NotificationObjectProxy(int process_id, int route_id,
14 int notification_id, bool worker)
15 : process_id_(process_id),
16 route_id_(route_id),
17 notification_id_(notification_id),
18 worker_(worker) {
19 }
20
Display()21 void NotificationObjectProxy::Display() {
22 Send(new DesktopNotificationMsg_PostDisplay(route_id_, notification_id_));
23 }
24
Error()25 void NotificationObjectProxy::Error() {
26 Send(new DesktopNotificationMsg_PostError(
27 route_id_, notification_id_, string16()));
28 }
29
Close(bool by_user)30 void NotificationObjectProxy::Close(bool by_user) {
31 Send(new DesktopNotificationMsg_PostClose(
32 route_id_, notification_id_, by_user));
33 }
34
Click()35 void NotificationObjectProxy::Click() {
36 Send(new DesktopNotificationMsg_PostClick(route_id_, notification_id_));
37 }
38
id() const39 std::string NotificationObjectProxy::id() const {
40 return StringPrintf("%d:%d:%d:%d", process_id_, route_id_,
41 notification_id_, worker_);
42 }
43
44
Send(IPC::Message * message)45 void NotificationObjectProxy::Send(IPC::Message* message) {
46 if (worker_) {
47 // TODO(johnnyg): http://crbug.com/23065 Worker support coming soon.
48 NOTREACHED();
49 return;
50 }
51
52 RenderViewHost* host = RenderViewHost::FromID(process_id_, route_id_);
53 if (host) {
54 host->Send(message);
55 } else {
56 delete message;
57 }
58 }
59