Home | History | Annotate | Download | only in notifications
      1 // Copyright (c) 2010 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_CHROMEOS_NOTIFICATIONS_SYSTEM_NOTIFICATION_H_
      6 #define CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_SYSTEM_NOTIFICATION_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/string16.h"
     13 #include "chrome/browser/chromeos/notifications/balloon_collection_impl.h"
     14 #include "chrome/browser/notifications/notification_delegate.h"
     15 #include "googleurl/src/gurl.h"
     16 
     17 class MessageCallback;
     18 class Profile;
     19 
     20 namespace chromeos {
     21 
     22 // The system notification object handles the display of a system notification
     23 
     24 class SystemNotification {
     25  public:
     26   // The profile is the current user profile. The id is any string used
     27   // to uniquely identify this notification. The title is the title of
     28   // the message to be displayed. On creation, the message is hidden.
     29   SystemNotification(Profile* profile,
     30                      const std::string& id,
     31                      int icon_resource_id,
     32                      const string16& title);
     33 
     34   // Allows to provide custom NotificationDelegate.
     35   SystemNotification(Profile* profile,
     36                      NotificationDelegate* delegate,
     37                      int icon_resource_id,
     38                      const string16& title);
     39 
     40   virtual ~SystemNotification();
     41 
     42   void set_title(const string16& title) { title_ = title; }
     43 
     44   // Show will show or update the message for this notification
     45   // on a transition to urgent, the notification will be shown if it was
     46   // previously hidden or minimized by the user.
     47   void Show(const string16& message, bool urgent, bool sticky);
     48 
     49   // Same as Show() above with a footer link at the bottom and a callback
     50   // for when the link is clicked.
     51   void Show(const string16& message, const string16& link_text,
     52             MessageCallback* callback, bool urgent, bool sticky);
     53 
     54   // Hide will dismiss the notification, if the notification is already
     55   // hidden it does nothing
     56   void Hide();
     57 
     58   // Current visibility state for this notification.
     59   bool visible() const { return visible_; }
     60 
     61   // Current urgent state for this notification.
     62   bool urgent() const { return urgent_; }
     63 
     64  private:
     65   class Delegate : public NotificationDelegate {
     66    public:
     67     explicit Delegate(const std::string& id) : id_(id) {}
     68     void Display() {}
     69     void Error() {}
     70     void Close(bool by_user) {}
     71     void Click() {}
     72     std::string id() const { return id_; }
     73 
     74    private:
     75     std::string id_;
     76 
     77     DISALLOW_COPY_AND_ASSIGN(Delegate);
     78   };
     79 
     80   void Init(int icon_resource_id);
     81 
     82   Profile* profile_;
     83   BalloonCollectionImpl* collection_;
     84   scoped_refptr<NotificationDelegate> delegate_;
     85   GURL icon_;
     86   string16 title_;
     87   bool visible_;
     88   bool urgent_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(SystemNotification);
     91 };
     92 
     93 }  // namespace chromeos
     94 
     95 #endif  // CHROME_BROWSER_CHROMEOS_NOTIFICATIONS_SYSTEM_NOTIFICATION_H_
     96