• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 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_WELCOME_NOTIFICATION_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_WELCOME_NOTIFICATION_H_
7 
8 #include <string>
9 
10 #include "base/memory/scoped_ptr.h"
11 #include "base/prefs/pref_member.h"
12 #include "chrome/browser/prefs/pref_service_syncable_observer.h"
13 #include "ui/message_center/notifier_settings.h"
14 
15 namespace message_center {
16 class MessageCenter;
17 }
18 
19 namespace user_prefs {
20 class PrefRegistrySyncable;
21 }
22 
23 class Notification;
24 class Profile;
25 
26 // WelcomeNotification is a part of DesktopNotificationService and manages
27 // showing and hiding a welcome notification for built-in components that
28 // show notifications. The Welcome Notification presumes network connectivity
29 // since it relies on synced preferences to work. This is generally fine since
30 // the current consumers on the welcome notification also presume network
31 // connectivity.
32 class WelcomeNotification
33     : public PrefServiceSyncableObserver {
34  public:
35   WelcomeNotification(
36       Profile* profile,
37       message_center::MessageCenter* message_center);
38   virtual ~WelcomeNotification();
39 
40   // PrefServiceSyncableObserver
41   virtual void OnIsSyncingChanged() OVERRIDE;
42 
43   // Adds in a the welcome notification if required for components built
44   // into Chrome that show notifications like Chrome Now.
45   void ShowWelcomeNotificationIfNecessary(
46       const Notification& notification);
47 
48   // Handles Preference Registeration for the Welcome Notification.
49   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
50 
51  private:
52 
53   enum PopUpRequest {
54     POP_UP_HIDDEN = 0,
55     POP_UP_SHOWN = 1,
56   };
57 
58   // Unconditionally shows the welcome notification.
59   void ShowWelcomeNotification(
60       const message_center::NotifierId notifier_id,
61       const base::string16& display_source,
62       PopUpRequest pop_up_request);
63 
64   // Hides the welcome notification.
65   void HideWelcomeNotification();
66 
67   // Called when the Welcome Notification Dismissed pref has been changed.
68   void OnWelcomeNotificationDismissedChanged();
69 
70   // Prefs listener for welcome_notification_dismissed.
71   BooleanPrefMember welcome_notification_dismissed_pref_;
72 
73   // The profile which owns this object.
74   Profile* profile_;
75 
76   // Notification ID of the Welcome Notification.
77   std::string welcome_notification_id_;
78 
79   // If the preferences are still syncing, store the last notification here
80   // so we can replay ShowWelcomeNotificationIfNecessary once the sync finishes.
81   // Simplifying Assumption: The delayed notification has passed the
82   // extension ID check. This means we do not need to store all of the
83   // notifications that may also show a welcome notification.
84   scoped_ptr<Notification> delayed_notification_;
85 
86   message_center::MessageCenter* message_center_;  // Weak reference.
87 };
88 
89 #endif  // CHROME_BROWSER_NOTIFICATIONS_WELCOME_NOTIFICATION_H_
90