Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
| 2 // // Use of this source code is governed by a BSD-style license that can be | |
| 3 // // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/system_notifier.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/bind_helpers.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/chromeos/eol_notification.h" | |
|
xiyuan
2016/06/16 22:41:27
Make this the first include and insert a space aft
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 11 #include "chrome/browser/notifications/notification.h" | |
| 12 #include "chrome/browser/notifications/notification_delegate.h" | |
| 13 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/profiles/profile_manager.h" | |
| 16 #include "chrome/browser/ui/browser_navigator.h" | |
| 17 #include "chrome/browser/ui/browser_navigator_params.h" | |
| 18 #include "chrome/common/pref_names.h" | |
| 19 #include "chrome/common/url_constants.h" | |
| 20 #include "chrome/grit/generated_resources.h" | |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 22 #include "chromeos/dbus/update_engine_client.h" | |
| 23 #include "components/prefs/pref_service.h" | |
| 24 #include "grit/ash_resources.h" | |
| 25 #include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | |
| 27 #include "ui/base/resource/resource_bundle.h" | |
| 28 #include "ui/gfx/image/image.h" | |
| 29 #include "ui/message_center/message_center.h" | |
| 30 #include "ui/message_center/notification.h" | |
| 31 #include "ui/message_center/notification_delegate.h" | |
|
xiyuan
2016/06/16 22:41:27
Clean up the includes and remove the unused ones,
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 32 | |
| 33 using message_center::MessageCenter; | |
| 34 | |
| 35 namespace chromeos { | |
| 36 namespace { | |
| 37 | |
| 38 const char kEolNotificationId[] = "eol"; | |
| 39 const char kDelegateId[] = "eol_delegate"; | |
| 40 | |
| 41 class EolNotificationDelegate : public NotificationDelegate { | |
| 42 public: | |
| 43 explicit EolNotificationDelegate(Profile* profile); | |
| 44 | |
| 45 private: | |
| 46 ~EolNotificationDelegate() override; | |
| 47 | |
| 48 // NotificationDelegate overrides: | |
| 49 void Close(bool by_user) override; | |
| 50 void ButtonClick(int button_index) override; | |
| 51 std::string id() const override; | |
| 52 | |
| 53 Profile* profile_; | |
|
xiyuan
2016/06/16 22:41:27
nit: Profile* const profile_; if it never changes
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 54 | |
| 55 void OpenMoreInfoPage(); | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate); | |
| 58 }; | |
| 59 | |
| 60 EolNotificationDelegate::EolNotificationDelegate(Profile* profile) | |
| 61 : profile_(profile) {} | |
| 62 | |
| 63 EolNotificationDelegate::~EolNotificationDelegate() {} | |
| 64 | |
| 65 void EolNotificationDelegate::Close(bool by_user) { | |
| 66 if (by_user) { | |
| 67 // set dismiss pref. | |
| 68 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void EolNotificationDelegate::ButtonClick(int button_index) { | |
| 73 // show eol link | |
| 74 OpenMoreInfoPage(); | |
| 75 } | |
| 76 | |
| 77 std::string EolNotificationDelegate::id() const { | |
| 78 return kDelegateId; | |
| 79 } | |
| 80 | |
| 81 void EolNotificationDelegate::OpenMoreInfoPage() { | |
| 82 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL), | |
| 83 ui::PAGE_TRANSITION_LINK); | |
| 84 params.disposition = NEW_FOREGROUND_TAB; | |
| 85 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 86 chrome::Navigate(¶ms); | |
| 87 } | |
| 88 | |
| 89 } // namespace | |
| 90 | |
| 91 EolNotification::EolNotification(Profile* profile) | |
| 92 : profile_(profile), weak_factory_(this) {} | |
| 93 | |
| 94 EolNotification::~EolNotification() {} | |
| 95 | |
| 96 void EolNotification::Update() { | |
|
xiyuan
2016/06/16 22:41:27
Move this down to match its order in the header fi
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 97 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 98 message_center::RichNotificationData data; | |
| 99 data.buttons.push_back(message_center::ButtonInfo( | |
| 100 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON))); | |
| 101 | |
| 102 Notification notification( | |
| 103 message_center::NOTIFICATION_TYPE_SIMPLE, | |
| 104 base::string16(), // title | |
| 105 // TODO(xiaoyinh): Update the Eol icon once it's ready. | |
| 106 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | |
| 107 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | |
| 108 kEolNotificationId), | |
| 109 base::string16(), // display_source | |
| 110 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_)); | |
| 111 g_browser_process->notification_ui_manager()->Add(notification, profile_); | |
| 112 } | |
| 113 | |
| 114 void EolNotification::GetEolStatus() { | |
|
xiyuan
2016/06/16 22:41:27
nit: GetEolStatus -> CheckEolStatus seems more fit
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 115 UpdateEngineClient* update_engine_client = | |
| 116 DBusThreadManager::Get()->GetUpdateEngineClient(); | |
| 117 | |
| 118 // Request the Eol Status. | |
| 119 update_engine_client->GetEolStatus( | |
| 120 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr())); | |
| 121 } | |
| 122 | |
| 123 void EolNotification::OnEolStatus(int status) { | |
| 124 status_ = status; | |
| 125 | |
| 126 int pre_eol_status = profile_->GetPrefs()->GetInteger(prefs::kEolStatus); | |
|
xiyuan
2016/06/16 22:41:27
nit: const int
xiaoyinh(OOO Sep 11-29)
2016/06/17 04:07:34
Done.
| |
| 127 | |
| 128 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_); | |
| 129 | |
| 130 if (status_ == update_engine::EndOfLifeStatus::kSupported) | |
| 131 return; | |
| 132 | |
| 133 if (pre_eol_status != status_) { | |
| 134 // If Eol status has changed, we should reset | |
| 135 // kEolNotificationDismissed and show notification. | |
| 136 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false); | |
| 137 } | |
| 138 | |
| 139 bool user_dismissed_eol_notification = | |
| 140 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed); | |
| 141 | |
| 142 if (user_dismissed_eol_notification) | |
| 143 return; | |
| 144 | |
| 145 // When device is in Security-Only state, only show notification the first | |
| 146 // time. | |
| 147 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { | |
| 148 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | |
| 149 } | |
| 150 | |
| 151 Update(); | |
| 152 } | |
| 153 | |
| 154 base::string16 EolNotification::GetEolMessage() { | |
| 155 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { | |
| 156 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY); | |
| 157 } else { | |
| 158 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL); | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 } // namespace chromeos | |
| OLD | NEW |