Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/notifications/extension_welcome_notification.cc

Issue 667283002: Standardize usage of virtual/override/final in chrome/browser/notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void Display() override {}
51 virtual void Error() override {} 51 void Error() override {}
52 52
53 virtual void Close(bool by_user) override { 53 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 void Click() override {}
64 virtual void ButtonClick(int index) override { 64 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 16 matching lines...) Expand all
91 void DisableNotificationProvider() { 91 void DisableNotificationProvider() {
92 message_center::Notifier notifier(notifier_id_, base::string16(), true); 92 message_center::Notifier notifier(notifier_id_, base::string16(), true);
93 message_center::MessageCenter* message_center = 93 message_center::MessageCenter* message_center =
94 delegate_->GetMessageCenter(); 94 delegate_->GetMessageCenter();
95 message_center->DisableNotificationsByNotifier(notifier_id_); 95 message_center->DisableNotificationsByNotifier(notifier_id_);
96 message_center->RemoveNotification(welcome_notification_id_, false); 96 message_center->RemoveNotification(welcome_notification_id_, false);
97 message_center->GetNotifierSettingsProvider()->SetNotifierEnabled( 97 message_center->GetNotifierSettingsProvider()->SetNotifierEnabled(
98 notifier, false); 98 notifier, false);
99 } 99 }
100 100
101 virtual ~NotificationCallbacks() {} 101 ~NotificationCallbacks() override {}
102 102
103 Profile* const profile_; 103 Profile* const profile_;
104 104
105 const message_center::NotifierId notifier_id_; 105 const message_center::NotifierId notifier_id_;
106 106
107 std::string welcome_notification_id_; 107 std::string welcome_notification_id_;
108 108
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 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 base::Time GetCurrentTime() override { return base::Time::Now(); }
124 return base::Time::Now();
125 }
126 124
127 virtual void PostTask( 125 void PostTask(const tracked_objects::Location& from_here,
128 const tracked_objects::Location& from_here, 126 const base::Closure& task) override {
129 const base::Closure& task) override {
130 base::MessageLoop::current()->PostTask(from_here, task); 127 base::MessageLoop::current()->PostTask(from_here, task);
131 } 128 }
132 129
133 private: 130 private:
134 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); 131 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate);
135 }; 132 };
136 133
137 } // namespace 134 } // namespace
138 135
139 ExtensionWelcomeNotification::ExtensionWelcomeNotification( 136 ExtensionWelcomeNotification::ExtensionWelcomeNotification(
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 prefs::kWelcomeNotificationExpirationTimestamp, 355 prefs::kWelcomeNotificationExpirationTimestamp,
359 (delegate_->GetCurrentTime() + 356 (delegate_->GetCurrentTime() +
360 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); 357 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue());
361 } 358 }
362 359
363 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { 360 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const {
364 const base::Time expiration_timestamp = GetExpirationTimestamp(); 361 const base::Time expiration_timestamp = GetExpirationTimestamp();
365 return !expiration_timestamp.is_null() && 362 return !expiration_timestamp.is_null() &&
366 (expiration_timestamp <= delegate_->GetCurrentTime()); 363 (expiration_timestamp <= delegate_->GetCurrentTime());
367 } 364 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698