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 #include "chrome/browser/notifications/extension_welcome_notification.h" | 5 #include "chrome/browser/notifications/extension_welcome_notification.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 const message_center::NotifierId notifier_id, | 40 const message_center::NotifierId notifier_id, |
41 const std::string& welcome_notification_id, | 41 const std::string& welcome_notification_id, |
42 ExtensionWelcomeNotification::Delegate* delegate) | 42 ExtensionWelcomeNotification::Delegate* delegate) |
43 : profile_(profile), | 43 : profile_(profile), |
44 notifier_id_(notifier_id.type, notifier_id.id), | 44 notifier_id_(notifier_id.type, notifier_id.id), |
45 welcome_notification_id_(welcome_notification_id), | 45 welcome_notification_id_(welcome_notification_id), |
46 delegate_(delegate) { | 46 delegate_(delegate) { |
47 } | 47 } |
48 | 48 |
49 // Overridden from NotificationDelegate: | 49 // Overridden from NotificationDelegate: |
50 virtual void Display() OVERRIDE {} | 50 virtual void Display() override {} |
51 virtual void Error() OVERRIDE {} | 51 virtual void Error() override {} |
52 | 52 |
53 virtual void Close(bool by_user) OVERRIDE { | 53 virtual void Close(bool by_user) override { |
54 if (by_user) { | 54 if (by_user) { |
55 // Setting the preference here may cause the notification erasing | 55 // Setting the preference here may cause the notification erasing |
56 // to reenter. Posting a task avoids this issue. | 56 // to reenter. Posting a task avoids this issue. |
57 delegate_->PostTask( | 57 delegate_->PostTask( |
58 FROM_HERE, | 58 FROM_HERE, |
59 base::Bind(&NotificationCallbacks::MarkAsDismissed, this)); | 59 base::Bind(&NotificationCallbacks::MarkAsDismissed, this)); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 virtual void Click() OVERRIDE {} | 63 virtual void Click() override {} |
64 virtual void ButtonClick(int index) OVERRIDE { | 64 virtual void ButtonClick(int index) override { |
65 if (index == 0) { | 65 if (index == 0) { |
66 OpenNotificationLearnMoreTab(); | 66 OpenNotificationLearnMoreTab(); |
67 } else if (index == 1) { | 67 } else if (index == 1) { |
68 DisableNotificationProvider(); | 68 DisableNotificationProvider(); |
69 Close(true); | 69 Close(true); |
70 } else { | 70 } else { |
71 NOTREACHED(); | 71 NOTREACHED(); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // Weak ref owned by ExtensionWelcomeNotification. | 109 // Weak ref owned by ExtensionWelcomeNotification. |
110 ExtensionWelcomeNotification::Delegate* const delegate_; | 110 ExtensionWelcomeNotification::Delegate* const delegate_; |
111 | 111 |
112 DISALLOW_COPY_AND_ASSIGN(NotificationCallbacks); | 112 DISALLOW_COPY_AND_ASSIGN(NotificationCallbacks); |
113 }; | 113 }; |
114 | 114 |
115 class DefaultDelegate : public ExtensionWelcomeNotification::Delegate { | 115 class DefaultDelegate : public ExtensionWelcomeNotification::Delegate { |
116 public: | 116 public: |
117 DefaultDelegate() {} | 117 DefaultDelegate() {} |
118 | 118 |
119 virtual message_center::MessageCenter* GetMessageCenter() OVERRIDE { | 119 virtual message_center::MessageCenter* GetMessageCenter() override { |
120 return g_browser_process->message_center(); | 120 return g_browser_process->message_center(); |
121 } | 121 } |
122 | 122 |
123 virtual base::Time GetCurrentTime() OVERRIDE { | 123 virtual base::Time GetCurrentTime() override { |
124 return base::Time::Now(); | 124 return base::Time::Now(); |
125 } | 125 } |
126 | 126 |
127 virtual void PostTask( | 127 virtual void PostTask( |
128 const tracked_objects::Location& from_here, | 128 const tracked_objects::Location& from_here, |
129 const base::Closure& task) OVERRIDE { | 129 const base::Closure& task) override { |
130 base::MessageLoop::current()->PostTask(from_here, task); | 130 base::MessageLoop::current()->PostTask(from_here, task); |
131 } | 131 } |
132 | 132 |
133 private: | 133 private: |
134 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); | 134 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); |
135 }; | 135 }; |
136 | 136 |
137 } // namespace | 137 } // namespace |
138 | 138 |
139 ExtensionWelcomeNotification::ExtensionWelcomeNotification( | 139 ExtensionWelcomeNotification::ExtensionWelcomeNotification( |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 prefs::kWelcomeNotificationExpirationTimestamp, | 358 prefs::kWelcomeNotificationExpirationTimestamp, |
359 (delegate_->GetCurrentTime() + | 359 (delegate_->GetCurrentTime() + |
360 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); | 360 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); |
361 } | 361 } |
362 | 362 |
363 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { | 363 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { |
364 const base::Time expiration_timestamp = GetExpirationTimestamp(); | 364 const base::Time expiration_timestamp = GetExpirationTimestamp(); |
365 return !expiration_timestamp.is_null() && | 365 return !expiration_timestamp.is_null() && |
366 (expiration_timestamp <= delegate_->GetCurrentTime()); | 366 (expiration_timestamp <= delegate_->GetCurrentTime()); |
367 } | 367 } |
OLD | NEW |