blob: c3278ab4b6b5be2736145d2f2410454851819a58 [file] [log] [blame]
xiaoyinhf39e3dd2016-06-18 04:50:231// Copyright 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 "chrome/browser/chromeos/eol_notification.h"
6
estade3b0d20252017-03-09 07:25:187#include "chrome/app/vector_icons/vector_icons.h"
xiaoyinhf39e3dd2016-06-18 04:50:238#include "chrome/browser/browser_process.h"
Evan Stadecc63b182017-09-26 16:05:129#include "chrome/browser/notifications/notification_common.h"
10#include "chrome/browser/notifications/notification_display_service.h"
11#include "chrome/browser/notifications/notification_display_service_factory.h"
xiaoyinhf39e3dd2016-06-18 04:50:2312#include "chrome/browser/ui/browser_navigator.h"
13#include "chrome/browser/ui/browser_navigator_params.h"
14#include "chrome/common/pref_names.h"
15#include "chrome/common/url_constants.h"
16#include "chrome/grit/generated_resources.h"
17#include "chromeos/dbus/dbus_thread_manager.h"
18#include "chromeos/dbus/update_engine_client.h"
19#include "components/prefs/pref_service.h"
Evan Stade619a89be2017-07-17 20:24:2620#include "components/vector_icons/vector_icons.h"
xiaoyinhf39e3dd2016-06-18 04:50:2321#include "ui/base/l10n/l10n_util.h"
xiaoyinhaa17d8342016-06-30 22:56:0222#include "ui/gfx/color_palette.h"
23#include "ui/gfx/paint_vector_icon.h"
Evan Stade4755cf22017-10-17 18:35:4324#include "ui/message_center/notification.h"
Evan Stade353058c2017-09-08 21:31:1325#include "ui/message_center/public/cpp/message_center_constants.h"
26#include "ui/message_center/public/cpp/message_center_switches.h"
xiaoyinhf39e3dd2016-06-18 04:50:2327
28using message_center::MessageCenter;
Tetsui Ohkuboe8f95e82017-08-23 06:10:4729using l10n_util::GetStringUTF16;
xiaoyinhf39e3dd2016-06-18 04:50:2330
31namespace chromeos {
32namespace {
33
Evan Stadecc63b182017-09-26 16:05:1234const char kEolNotificationId[] = "chrome://product_eol";
xiaoyinhaa17d8342016-06-30 22:56:0235const SkColor kButtonIconColor = SkColorSetRGB(150, 150, 152);
36const SkColor kNotificationIconColor = SkColorSetRGB(219, 68, 55);
xiaoyinhf39e3dd2016-06-18 04:50:2337
Evan Stadecf27dae12017-11-07 23:57:5138// Buttons that appear in notifications.
39enum ButtonIndex {
40 BUTTON_MORE_INFO = 0,
41 BUTTON_DISMISS,
42 BUTTON_SIZE = BUTTON_DISMISS
43};
Evan Stadecc63b182017-09-26 16:05:1244
Evan Stadecf27dae12017-11-07 23:57:5145class EolNotificationDelegate : public message_center::NotificationDelegate {
46 public:
47 explicit EolNotificationDelegate(Profile* profile) : profile_(profile) {}
48
49 private:
50 ~EolNotificationDelegate() override = default;
51
52 // NotificationDelegate overrides:
53 void ButtonClick(int button_index) override {
54 switch (button_index) {
Evan Stadecc63b182017-09-26 16:05:1255 case BUTTON_MORE_INFO: {
56 // show eol link
Evan Stadecf27dae12017-11-07 23:57:5157 chrome::NavigateParams params(profile_,
Evan Stadecc63b182017-09-26 16:05:1258 GURL(chrome::kEolNotificationURL),
59 ui::PAGE_TRANSITION_LINK);
60 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
61 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
62 chrome::Navigate(&params);
63 break;
64 }
65 case BUTTON_DISMISS:
66 // set dismiss pref.
Evan Stadecf27dae12017-11-07 23:57:5167 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed,
68 true);
Evan Stadecc63b182017-09-26 16:05:1269 break;
70 }
Evan Stadecf27dae12017-11-07 23:57:5171 NotificationDisplayServiceFactory::GetForProfile(profile_)->Close(
72 NotificationCommon::TRANSIENT, kEolNotificationId);
Evan Stadecc63b182017-09-26 16:05:1273 }
74
Evan Stadecf27dae12017-11-07 23:57:5175 Profile* const profile_;
xiaoyinhf39e3dd2016-06-18 04:50:2376
Evan Stadecf27dae12017-11-07 23:57:5177 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
xiaoyinhf39e3dd2016-06-18 04:50:2378};
79
xiaoyinhf39e3dd2016-06-18 04:50:2380} // namespace
81
82EolNotification::EolNotification(Profile* profile)
83 : profile_(profile),
84 status_(update_engine::EndOfLifeStatus::kSupported),
85 weak_factory_(this) {}
86
87EolNotification::~EolNotification() {}
88
89void EolNotification::CheckEolStatus() {
90 UpdateEngineClient* update_engine_client =
91 DBusThreadManager::Get()->GetUpdateEngineClient();
92
93 // Request the Eol Status.
94 update_engine_client->GetEolStatus(
95 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
96}
97
xiaoyinhaa17d8342016-06-30 22:56:0298void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) {
xiaoyinhf39e3dd2016-06-18 04:50:2399 status_ = status;
100
101 const int pre_eol_status =
102 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
103 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
104
xiaoyinhf4e5b5b2017-02-27 23:22:46105 // Security only state is no longer supported.
106 if (status_ == update_engine::EndOfLifeStatus::kSupported ||
107 status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
xiaoyinhf39e3dd2016-06-18 04:50:23108 return;
xiaoyinhf4e5b5b2017-02-27 23:22:46109 }
xiaoyinhf39e3dd2016-06-18 04:50:23110
111 if (pre_eol_status != status_) {
112 // If Eol status has changed, we should reset
113 // kEolNotificationDismissed and show notification.
114 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
115 }
116
117 bool user_dismissed_eol_notification =
118 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
119 if (user_dismissed_eol_notification)
120 return;
121
xiaoyinhf39e3dd2016-06-18 04:50:23122 Update();
123}
124
125void EolNotification::Update() {
xiaoyinhf39e3dd2016-06-18 04:50:23126 message_center::RichNotificationData data;
Evan Stadecf27dae12017-11-07 23:57:51127
128 DCHECK_EQ(BUTTON_MORE_INFO, data.buttons.size());
129 data.buttons.emplace_back(GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON));
130 data.buttons.back().icon = gfx::Image(
131 CreateVectorIcon(vector_icons::kInfoOutlineIcon, kButtonIconColor));
132
133 DCHECK_EQ(BUTTON_DISMISS, data.buttons.size());
134 data.buttons.emplace_back(GetStringUTF16(IDS_EOL_DISMISS_BUTTON));
135 data.buttons.back().icon = gfx::Image(
136 CreateVectorIcon(vector_icons::kNotificationsOffIcon, kButtonIconColor));
xiaoyinhf39e3dd2016-06-18 04:50:23137
Evan Stade4755cf22017-10-17 18:35:43138 message_center::Notification notification(
Evan Stade7ff08dc2017-09-13 01:52:00139 message_center::NOTIFICATION_TYPE_SIMPLE, kEolNotificationId,
Tetsui Ohkuboe8f95e82017-08-23 06:10:47140 GetStringUTF16(IDS_EOL_NOTIFICATION_TITLE),
141 GetStringUTF16(IDS_EOL_NOTIFICATION_EOL),
Evan Stade353058c2017-09-08 21:31:13142 message_center::IsNewStyleNotificationEnabled()
Tetsui Ohkuboe8f95e82017-08-23 06:10:47143 ? gfx::Image()
144 : gfx::Image(CreateVectorIcon(kEolIcon, kNotificationIconColor)),
Evan Stade4755cf22017-10-17 18:35:43145 GetStringUTF16(IDS_EOL_NOTIFICATION_DISPLAY_SOURCE),
146 GURL(kEolNotificationId),
xiaoyinhf39e3dd2016-06-18 04:50:23147 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
148 kEolNotificationId),
Evan Stadecf27dae12017-11-07 23:57:51149 data, new EolNotificationDelegate(profile_));
Evan Stadecc63b182017-09-26 16:05:12150
Evan Stade353058c2017-09-08 21:31:13151 if (message_center::IsNewStyleNotificationEnabled()) {
Tetsui Ohkuboe8f95e82017-08-23 06:10:47152 notification.set_accent_color(
153 message_center::kSystemNotificationColorCriticalWarning);
154 notification.set_small_image(gfx::Image(gfx::CreateVectorIcon(
155 kNotificationEndOfSupportIcon,
156 message_center::kSystemNotificationColorCriticalWarning)));
157 notification.set_vector_small_image(kNotificationEndOfSupportIcon);
158 }
Evan Stadecc63b182017-09-26 16:05:12159
Evan Stadecc63b182017-09-26 16:05:12160 NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
Evan Stadecf27dae12017-11-07 23:57:51161 NotificationCommon::TRANSIENT, notification);
xiaoyinhf39e3dd2016-06-18 04:50:23162}
163
xiaoyinhf39e3dd2016-06-18 04:50:23164} // namespace chromeos