| 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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/notifications/notification.h" | 15 #include "chrome/browser/notifications/notification.h" |
| 16 #include "chrome/browser/prefs/pref_service_syncable.h" | 16 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 17 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 22 #include "components/pref_registry/pref_registry_syncable.h" | 23 #include "components/pref_registry/pref_registry_syncable.h" |
| 23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/message_center/message_center.h" | 27 #include "ui/message_center/message_center.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 158 |
| 158 // static | 159 // static |
| 159 ExtensionWelcomeNotification* ExtensionWelcomeNotification::Create( | 160 ExtensionWelcomeNotification* ExtensionWelcomeNotification::Create( |
| 160 Profile* const profile, Delegate* const delegate) { | 161 Profile* const profile, Delegate* const delegate) { |
| 161 return new ExtensionWelcomeNotification(profile, delegate); | 162 return new ExtensionWelcomeNotification(profile, delegate); |
| 162 } | 163 } |
| 163 | 164 |
| 164 ExtensionWelcomeNotification::~ExtensionWelcomeNotification() { | 165 ExtensionWelcomeNotification::~ExtensionWelcomeNotification() { |
| 165 if (delayed_notification_) { | 166 if (delayed_notification_) { |
| 166 delayed_notification_.reset(); | 167 delayed_notification_.reset(); |
| 167 PrefServiceSyncable::FromProfile(profile_)->RemoveObserver(this); | 168 PrefServiceSyncableFromProfile(profile_)->RemoveObserver(this); |
| 168 } else { | 169 } else { |
| 169 HideWelcomeNotification(); | 170 HideWelcomeNotification(); |
| 170 } | 171 } |
| 171 } | 172 } |
| 172 | 173 |
| 173 void ExtensionWelcomeNotification::OnIsSyncingChanged() { | 174 void ExtensionWelcomeNotification::OnIsSyncingChanged() { |
| 174 DCHECK(delayed_notification_); | 175 DCHECK(delayed_notification_); |
| 175 PrefServiceSyncable* const pref_service_syncable = | 176 PrefServiceSyncable* const pref_service_syncable = |
| 176 PrefServiceSyncable::FromProfile(profile_); | 177 PrefServiceSyncableFromProfile(profile_); |
| 177 if (pref_service_syncable->IsSyncing()) { | 178 if (pref_service_syncable->IsSyncing()) { |
| 178 pref_service_syncable->RemoveObserver(this); | 179 pref_service_syncable->RemoveObserver(this); |
| 179 scoped_ptr<Notification> previous_notification( | 180 scoped_ptr<Notification> previous_notification( |
| 180 delayed_notification_.release()); | 181 delayed_notification_.release()); |
| 181 ShowWelcomeNotificationIfNecessary(*(previous_notification.get())); | 182 ShowWelcomeNotificationIfNecessary(*(previous_notification.get())); |
| 182 } | 183 } |
| 183 } | 184 } |
| 184 | 185 |
| 185 void ExtensionWelcomeNotification::ShowWelcomeNotificationIfNecessary( | 186 void ExtensionWelcomeNotification::ShowWelcomeNotificationIfNecessary( |
| 186 const Notification& notification) { | 187 const Notification& notification) { |
| 187 if ((notification.notifier_id() == notifier_id_) && !delayed_notification_) { | 188 if ((notification.notifier_id() == notifier_id_) && !delayed_notification_) { |
| 188 PrefServiceSyncable* const pref_service_syncable = | 189 PrefServiceSyncable* const pref_service_syncable = |
| 189 PrefServiceSyncable::FromProfile(profile_); | 190 PrefServiceSyncableFromProfile(profile_); |
| 190 if (pref_service_syncable->IsSyncing()) { | 191 if (pref_service_syncable->IsSyncing()) { |
| 191 PrefService* const pref_service = profile_->GetPrefs(); | 192 PrefService* const pref_service = profile_->GetPrefs(); |
| 192 if (!UserHasDismissedWelcomeNotification()) { | 193 if (!UserHasDismissedWelcomeNotification()) { |
| 193 const PopUpRequest pop_up_request = | 194 const PopUpRequest pop_up_request = |
| 194 pref_service->GetBoolean( | 195 pref_service->GetBoolean( |
| 195 prefs::kWelcomeNotificationPreviouslyPoppedUp) | 196 prefs::kWelcomeNotificationPreviouslyPoppedUp) |
| 196 ? POP_UP_HIDDEN | 197 ? POP_UP_HIDDEN |
| 197 : POP_UP_SHOWN; | 198 : POP_UP_SHOWN; |
| 198 if (pop_up_request == POP_UP_SHOWN) { | 199 if (pop_up_request == POP_UP_SHOWN) { |
| 199 pref_service->SetBoolean( | 200 pref_service->SetBoolean( |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 prefs::kWelcomeNotificationExpirationTimestamp, | 347 prefs::kWelcomeNotificationExpirationTimestamp, |
| 347 (delegate_->GetCurrentTime() + | 348 (delegate_->GetCurrentTime() + |
| 348 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); | 349 base::TimeDelta::FromDays(kRequestedShowTimeDays)).ToInternalValue()); |
| 349 } | 350 } |
| 350 | 351 |
| 351 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { | 352 bool ExtensionWelcomeNotification::IsWelcomeNotificationExpired() const { |
| 352 const base::Time expiration_timestamp = GetExpirationTimestamp(); | 353 const base::Time expiration_timestamp = GetExpirationTimestamp(); |
| 353 return !expiration_timestamp.is_null() && | 354 return !expiration_timestamp.is_null() && |
| 354 (expiration_timestamp <= delegate_->GetCurrentTime()); | 355 (expiration_timestamp <= delegate_->GetCurrentTime()); |
| 355 } | 356 } |
| OLD | NEW |