[email protected] | 4bb33630 | 2009-10-12 05:44:26 | [diff] [blame^] | 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 | #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_ |
| 6 | #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_ |
| 7 | |
| 8 | #include "base/ref_counted.h" |
| 9 | |
| 10 | class MessageLoop; |
| 11 | namespace IPC { |
| 12 | class Message; |
| 13 | } |
| 14 | |
| 15 | // A NotificationObjectProxy stands in for the JavaScript Notification object |
| 16 | // which corresponds to a notification toast on the desktop. It can be signaled |
| 17 | // when various events occur regarding the desktop notification, and the |
| 18 | // attached JS listeners will be invoked in the renderer or worker process. |
| 19 | class NotificationObjectProxy : |
| 20 | public base::RefCountedThreadSafe<NotificationObjectProxy> { |
| 21 | public: |
| 22 | // Creates a Proxy object with the necessary callback information. |
| 23 | NotificationObjectProxy(int process_id, int route_id, |
| 24 | int notification_id, bool worker); |
| 25 | |
| 26 | // To be called when the desktop notification is actually shown. |
| 27 | void Display(); |
| 28 | |
| 29 | // To be called when the desktop notification cannot be shown due to an |
| 30 | // error. |
| 31 | void Error(); |
| 32 | |
| 33 | // To be called when the desktop notification is closed. If closed by a |
| 34 | // user explicitly (as opposed to timeout), |by_user| should be true. |
| 35 | void Close(bool by_user); |
| 36 | |
| 37 | private: |
| 38 | // Called on UI thread to schedule a message for sending. |
| 39 | void DeliverMessage(IPC::Message* message); |
| 40 | |
| 41 | // Called via Task on IO thread to actually send a message to a notification. |
| 42 | void Send(IPC::Message* message); |
| 43 | |
| 44 | // Callback information to find the JS Notification object where it lives. |
| 45 | int process_id_; |
| 46 | int route_id_; |
| 47 | int notification_id_; |
| 48 | bool worker_; |
| 49 | }; |
| 50 | |
| 51 | #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_OBJECT_PROXY_H_ |