OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_EXTENSIONS_EXTENSION_WELCOME_NOTIFICATION_H _ |
6 #define CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_EXTENSIONS_EXTENSION_WELCOME_NOTIFICATION_H _ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/prefs/pref_member.h" | 11 #include "base/prefs/pref_member.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "chrome/browser/prefs/pref_service_syncable_observer.h" | 13 #include "chrome/browser/prefs/pref_service_syncable_observer.h" |
14 #include "components/keyed_service/core/keyed_service.h" | |
14 #include "ui/message_center/notifier_settings.h" | 15 #include "ui/message_center/notifier_settings.h" |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 typedef Callback<void(void)> Closure; | 18 typedef Callback<void(void)> Closure; |
18 } | 19 } |
19 | 20 |
20 namespace message_center { | 21 namespace message_center { |
21 class MessageCenter; | 22 class MessageCenter; |
22 } | 23 } |
23 | 24 |
24 namespace tracked_objects { | 25 namespace tracked_objects { |
25 class Location; | 26 class Location; |
26 } | 27 } |
27 | 28 |
28 namespace user_prefs { | 29 namespace user_prefs { |
29 class PrefRegistrySyncable; | 30 class PrefRegistrySyncable; |
30 } | 31 } |
31 | 32 |
32 class Notification; | 33 class Notification; |
33 class Profile; | 34 class Profile; |
34 | 35 |
35 // ExtensionWelcomeNotification is a part of DesktopNotificationService and | 36 // ExtensionWelcomeNotification is a keyed service which manages showing and |
36 // manages showing and hiding a welcome notification for built-in components | 37 // hiding a welcome notification for built-in components which show |
robliao
2014/09/18 20:10:01
Nit: s/which/that
The first clause is non-restric
Peter Beverloo
2014/09/19 13:01:22
Insightful, thanks :-).
| |
37 // that show notifications. The Welcome Notification presumes network | 38 // notifications. The Welcome Notification presumes network connectivity since |
38 // connectivity since it relies on synced preferences to work. This is generally | 39 // it relies on synced preferences to work. This is generally fine since the |
39 // fine since the current consumers on the welcome notification also presume | 40 // current consumers on the welcome notification also presume network |
40 // network connectivity. | 41 // connectivity. |
42 // | |
41 // This class expects to be created and called from the UI thread. | 43 // This class expects to be created and called from the UI thread. |
42 class ExtensionWelcomeNotification : public PrefServiceSyncableObserver { | 44 class ExtensionWelcomeNotification : public KeyedService, |
45 public PrefServiceSyncableObserver { | |
43 public: | 46 public: |
44 // Allows for overriding global calls. | 47 // Allows for overriding global calls. |
45 class Delegate { | 48 class Delegate { |
46 public: | 49 public: |
47 Delegate() {} | 50 Delegate() {} |
48 virtual ~Delegate() {} | 51 virtual ~Delegate() {} |
49 virtual message_center::MessageCenter* GetMessageCenter() = 0; | 52 virtual message_center::MessageCenter* GetMessageCenter() = 0; |
50 virtual base::Time GetCurrentTime() = 0; | 53 virtual base::Time GetCurrentTime() = 0; |
51 virtual void PostTask( | 54 virtual void PostTask( |
52 const tracked_objects::Location& from_here, | 55 const tracked_objects::Location& from_here, |
53 const base::Closure& task) = 0; | 56 const base::Closure& task) = 0; |
54 private: | 57 private: |
55 DISALLOW_COPY_AND_ASSIGN(Delegate); | 58 DISALLOW_COPY_AND_ASSIGN(Delegate); |
56 }; | 59 }; |
57 | 60 |
58 // Requested time from showing the welcome notification to expiration. | 61 // Requested time from showing the welcome notification to expiration. |
59 static const int kRequestedShowTimeDays; | 62 static const int kRequestedShowTimeDays; |
60 | 63 |
64 // The extension Id associated with the Google Now extension. | |
65 static const char kChromeNowExtensionID[]; | |
66 | |
61 virtual ~ExtensionWelcomeNotification(); | 67 virtual ~ExtensionWelcomeNotification(); |
62 | 68 |
63 // To workaround the lack of delegating constructors prior to C++11, we use | 69 // To workaround the lack of delegating constructors prior to C++11, we use |
64 // static Create methods. | 70 // static Create methods. |
65 // Creates an ExtensionWelcomeNotification owned by the specified | 71 // Creates an ExtensionWelcomeNotification with the default delegate. |
66 // extension id with the default delegate. | |
67 static scoped_ptr<ExtensionWelcomeNotification> Create( | 72 static scoped_ptr<ExtensionWelcomeNotification> Create( |
68 const std::string& extension_id, | |
69 Profile* const profile); | 73 Profile* const profile); |
70 | 74 |
71 // Creates an ExtensionWelcomeNotification owned by the specified | 75 // Creates an ExtensionWelcomeNotification with the specified delegate. |
72 // extension id with the specified delegate. | |
73 static scoped_ptr<ExtensionWelcomeNotification> Create( | 76 static scoped_ptr<ExtensionWelcomeNotification> Create( |
74 const std::string& extension_id, | |
75 Profile* const profile, | 77 Profile* const profile, |
76 Delegate* const delegate); | 78 Delegate* const delegate); |
77 | 79 |
78 // PrefServiceSyncableObserver | 80 // PrefServiceSyncableObserver |
79 virtual void OnIsSyncingChanged() OVERRIDE; | 81 virtual void OnIsSyncingChanged() OVERRIDE; |
80 | 82 |
81 // Adds in the welcome notification if required for components built | 83 // Adds in the welcome notification if required for components built |
82 // into Chrome that show notifications like Chrome Now. | 84 // into Chrome that show notifications like Chrome Now. |
83 void ShowWelcomeNotificationIfNecessary(const Notification& notification); | 85 void ShowWelcomeNotificationIfNecessary(const Notification& notification); |
84 | 86 |
85 // Handles Preference Registration for the Welcome Notification. | 87 // Handles Preference Registration for the Welcome Notification. |
86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 88 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
87 | 89 |
88 private: | 90 private: |
89 enum PopUpRequest { POP_UP_HIDDEN = 0, POP_UP_SHOWN = 1, }; | 91 enum PopUpRequest { POP_UP_HIDDEN = 0, POP_UP_SHOWN = 1, }; |
90 | 92 |
91 ExtensionWelcomeNotification( | 93 ExtensionWelcomeNotification( |
92 const std::string& extension_id, | |
93 Profile* const profile, | 94 Profile* const profile, |
94 ExtensionWelcomeNotification::Delegate* const delegate); | 95 ExtensionWelcomeNotification::Delegate* const delegate); |
95 | 96 |
96 // Gets the message center from the delegate. | 97 // Gets the message center from the delegate. |
97 message_center::MessageCenter* GetMessageCenter() const; | 98 message_center::MessageCenter* GetMessageCenter() const; |
98 | 99 |
99 // Unconditionally shows the welcome notification. | 100 // Unconditionally shows the welcome notification. |
100 void ShowWelcomeNotification(const base::string16& display_source, | 101 void ShowWelcomeNotification(const base::string16& display_source, |
101 const PopUpRequest pop_up_request); | 102 const PopUpRequest pop_up_request); |
102 | 103 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
155 scoped_ptr<base::OneShotTimer<ExtensionWelcomeNotification> > | 156 scoped_ptr<base::OneShotTimer<ExtensionWelcomeNotification> > |
156 expiration_timer_; | 157 expiration_timer_; |
157 | 158 |
158 // Delegate for Chrome global calls like base::Time::GetTime() for | 159 // Delegate for Chrome global calls like base::Time::GetTime() for |
159 // testability. | 160 // testability. |
160 scoped_ptr<Delegate> delegate_; | 161 scoped_ptr<Delegate> delegate_; |
161 | 162 |
162 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotification); | 163 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotification); |
163 }; | 164 }; |
164 | 165 |
165 #endif // CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ | 166 #endif // CHROME_BROWSER_NOTIFICATIONS_EXTENSIONS_EXTENSION_WELCOME_NOTIFICATIO N_H_ |
OLD | NEW |