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/extensions/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" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
13 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
14 #include "chrome/browser/prefs/pref_service_syncable.h" | 14 #include "chrome/browser/prefs/pref_service_syncable.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser_navigator.h" | 16 #include "chrome/browser/ui/browser_navigator.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
20 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
21 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
22 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/message_center/message_center.h" | 24 #include "ui/message_center/message_center.h" |
25 #include "ui/message_center/notification.h" | 25 #include "ui/message_center/notification.h" |
26 #include "ui/message_center/notification_delegate.h" | 26 #include "ui/message_center/notification_delegate.h" |
27 #include "ui/message_center/notification_types.h" | 27 #include "ui/message_center/notification_types.h" |
28 | 28 |
29 const int ExtensionWelcomeNotification::kRequestedShowTimeDays = 14; | 29 const int ExtensionWelcomeNotification::kRequestedShowTimeDays = 14; |
30 const char ExtensionWelcomeNotification::kChromeNowExtensionID[]= | |
robliao
2014/09/18 20:10:01
Space between [] and =
| |
31 "pafkbggdmjlpgkdkcbjmhmfcdpncadgh"; | |
30 | 32 |
31 namespace { | 33 namespace { |
32 | 34 |
33 class NotificationCallbacks | 35 class NotificationCallbacks |
34 : public message_center::NotificationDelegate { | 36 : public message_center::NotificationDelegate { |
35 public: | 37 public: |
36 NotificationCallbacks( | 38 NotificationCallbacks( |
37 Profile* profile, | 39 Profile* profile, |
38 const message_center::NotifierId notifier_id, | 40 const message_center::NotifierId notifier_id, |
39 const std::string& welcome_notification_id, | 41 const std::string& welcome_notification_id, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 base::MessageLoop::current()->PostTask(from_here, task); | 130 base::MessageLoop::current()->PostTask(from_here, task); |
129 } | 131 } |
130 | 132 |
131 private: | 133 private: |
132 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); | 134 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); |
133 }; | 135 }; |
134 | 136 |
135 } // namespace | 137 } // namespace |
136 | 138 |
137 ExtensionWelcomeNotification::ExtensionWelcomeNotification( | 139 ExtensionWelcomeNotification::ExtensionWelcomeNotification( |
138 const std::string& extension_id, | |
139 Profile* const profile, | 140 Profile* const profile, |
140 ExtensionWelcomeNotification::Delegate* const delegate) | 141 ExtensionWelcomeNotification::Delegate* const delegate) |
141 : notifier_id_(message_center::NotifierId::APPLICATION, extension_id), | 142 : notifier_id_(message_center::NotifierId::APPLICATION, |
143 ExtensionWelcomeNotification::kChromeNowExtensionID), | |
Jun Mukai
2014/09/18 17:53:48
You can just say kChromeNowExtensionID because it'
Peter Beverloo
2014/09/19 13:01:22
I removed the prefix, but since still end up with
| |
142 profile_(profile), | 144 profile_(profile), |
143 delegate_(delegate) { | 145 delegate_(delegate) { |
144 welcome_notification_dismissed_pref_.Init( | 146 welcome_notification_dismissed_pref_.Init( |
145 prefs::kWelcomeNotificationDismissed, | 147 prefs::kWelcomeNotificationDismissed, |
146 profile_->GetPrefs(), | 148 profile_->GetPrefs(), |
147 base::Bind( | 149 base::Bind( |
148 &ExtensionWelcomeNotification::OnWelcomeNotificationDismissedChanged, | 150 &ExtensionWelcomeNotification::OnWelcomeNotificationDismissedChanged, |
149 base::Unretained(this))); | 151 base::Unretained(this))); |
150 welcome_notification_dismissed_local_pref_.Init( | 152 welcome_notification_dismissed_local_pref_.Init( |
151 prefs::kWelcomeNotificationDismissedLocal, | 153 prefs::kWelcomeNotificationDismissedLocal, |
152 profile_->GetPrefs()); | 154 profile_->GetPrefs()); |
153 } | 155 } |
154 | 156 |
155 // static | 157 // static |
156 scoped_ptr<ExtensionWelcomeNotification> ExtensionWelcomeNotification::Create( | 158 scoped_ptr<ExtensionWelcomeNotification> ExtensionWelcomeNotification::Create( |
157 const std::string& extension_id, | |
158 Profile* const profile) { | 159 Profile* const profile) { |
159 return Create(extension_id, profile, new DefaultDelegate()).Pass(); | 160 return Create(profile, new DefaultDelegate()).Pass(); |
160 } | 161 } |
161 | 162 |
162 // static | 163 // static |
163 scoped_ptr<ExtensionWelcomeNotification> ExtensionWelcomeNotification::Create( | 164 scoped_ptr<ExtensionWelcomeNotification> ExtensionWelcomeNotification::Create( |
164 const std::string& extension_id, | 165 Profile* const profile, Delegate* const delegate) { |
165 Profile* const profile, | |
166 Delegate* const delegate) { | |
167 return scoped_ptr<ExtensionWelcomeNotification>( | 166 return scoped_ptr<ExtensionWelcomeNotification>( |
168 new ExtensionWelcomeNotification(extension_id, profile, delegate)).Pass(); | 167 new ExtensionWelcomeNotification(profile, delegate)).Pass(); |
169 } | 168 } |
170 | 169 |
171 ExtensionWelcomeNotification::~ExtensionWelcomeNotification() { | 170 ExtensionWelcomeNotification::~ExtensionWelcomeNotification() { |
172 if (delayed_notification_) { | 171 if (delayed_notification_) { |
173 delayed_notification_.reset(); | 172 delayed_notification_.reset(); |
174 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 173 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); |
175 } else { | 174 } else { |
176 HideWelcomeNotification(); | 175 HideWelcomeNotification(); |
177 } | 176 } |
178 } | 177 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 prefs::kWelcomeNotificationExpirationTimestamp, | 359 prefs::kWelcomeNotificationExpirationTimestamp, |
361 (delegate_->GetCurrentTime() + | 360 (delegate_->GetCurrentTime() + |
362 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); | 361 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); |
363 } | 362 } |
364 | 363 |
365 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { | 364 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { |
366 const base::Time expiration_timestamp = GetExpirationTimestamp(); | 365 const base::Time expiration_timestamp = GetExpirationTimestamp(); |
367 return !expiration_timestamp.is_null() && | 366 return !expiration_timestamp.is_null() && |
368 (expiration_timestamp <= delegate_->GetCurrentTime()); | 367 (expiration_timestamp <= delegate_->GetCurrentTime()); |
369 } | 368 } |
OLD | NEW |