| 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_EXTENSION_WELCOME_NOTIFICATION_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_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 that show |
| 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. | 72 static ExtensionWelcomeNotification* Create(Profile* const profile); |
| 67 static scoped_ptr<ExtensionWelcomeNotification> Create( | |
| 68 const std::string& extension_id, | |
| 69 Profile* const profile); | |
| 70 | 73 |
| 71 // Creates an ExtensionWelcomeNotification owned by the specified | 74 // Creates an ExtensionWelcomeNotification with the specified delegate. |
| 72 // extension id with the specified delegate. | 75 static ExtensionWelcomeNotification* Create(Profile* const profile, |
| 73 static scoped_ptr<ExtensionWelcomeNotification> Create( | 76 Delegate* const delegate); |
| 74 const std::string& extension_id, | |
| 75 Profile* const profile, | |
| 76 Delegate* const delegate); | |
| 77 | 77 |
| 78 // PrefServiceSyncableObserver | 78 // PrefServiceSyncableObserver |
| 79 virtual void OnIsSyncingChanged() OVERRIDE; | 79 virtual void OnIsSyncingChanged() OVERRIDE; |
| 80 | 80 |
| 81 // Adds in the welcome notification if required for components built | 81 // Adds in the welcome notification if required for components built |
| 82 // into Chrome that show notifications like Chrome Now. | 82 // into Chrome that show notifications like Chrome Now. |
| 83 void ShowWelcomeNotificationIfNecessary(const Notification& notification); | 83 void ShowWelcomeNotificationIfNecessary(const Notification& notification); |
| 84 | 84 |
| 85 // Handles Preference Registration for the Welcome Notification. | 85 // Handles Preference Registration for the Welcome Notification. |
| 86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | 86 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 enum PopUpRequest { POP_UP_HIDDEN = 0, POP_UP_SHOWN = 1, }; | 89 enum PopUpRequest { POP_UP_HIDDEN = 0, POP_UP_SHOWN = 1, }; |
| 90 | 90 |
| 91 ExtensionWelcomeNotification( | 91 ExtensionWelcomeNotification( |
| 92 const std::string& extension_id, | |
| 93 Profile* const profile, | 92 Profile* const profile, |
| 94 ExtensionWelcomeNotification::Delegate* const delegate); | 93 ExtensionWelcomeNotification::Delegate* const delegate); |
| 95 | 94 |
| 96 // Gets the message center from the delegate. | 95 // Gets the message center from the delegate. |
| 97 message_center::MessageCenter* GetMessageCenter() const; | 96 message_center::MessageCenter* GetMessageCenter() const; |
| 98 | 97 |
| 99 // Unconditionally shows the welcome notification. | 98 // Unconditionally shows the welcome notification. |
| 100 void ShowWelcomeNotification(const base::string16& display_source, | 99 void ShowWelcomeNotification(const base::string16& display_source, |
| 101 const PopUpRequest pop_up_request); | 100 const PopUpRequest pop_up_request); |
| 102 | 101 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 expiration_timer_; | 155 expiration_timer_; |
| 157 | 156 |
| 158 // Delegate for Chrome global calls like base::Time::GetTime() for | 157 // Delegate for Chrome global calls like base::Time::GetTime() for |
| 159 // testability. | 158 // testability. |
| 160 scoped_ptr<Delegate> delegate_; | 159 scoped_ptr<Delegate> delegate_; |
| 161 | 160 |
| 162 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotification); | 161 DISALLOW_COPY_AND_ASSIGN(ExtensionWelcomeNotification); |
| 163 }; | 162 }; |
| 164 | 163 |
| 165 #endif // CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ | 164 #endif // CHROME_BROWSER_NOTIFICATIONS_EXTENSION_WELCOME_NOTIFICATION_H_ |
| OLD | NEW |