Home | History | Annotate | Download | only in notifications
      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 
     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 
     21 void NotificationObjectProxy::Display() {
     22   Send(new DesktopNotificationMsg_PostDisplay(route_id_, notification_id_));
     23 }
     24 
     25 void NotificationObjectProxy::Error() {
     26   Send(new DesktopNotificationMsg_PostError(
     27       route_id_, notification_id_, string16()));
     28 }
     29 
     30 void NotificationObjectProxy::Close(bool by_user) {
     31   Send(new DesktopNotificationMsg_PostClose(
     32       route_id_, notification_id_, by_user));
     33 }
     34 
     35 void NotificationObjectProxy::Click() {
     36   Send(new DesktopNotificationMsg_PostClick(route_id_, notification_id_));
     37 }
     38 
     39 std::string NotificationObjectProxy::id() const {
     40   return StringPrintf("%d:%d:%d:%d", process_id_, route_id_,
     41                       notification_id_, worker_);
     42 }
     43 
     44 
     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