blob: 3952030a661b867b83d8d1c28ed054ec1a4417de [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
Evan Stade70e2ed42018-11-08 06:23:057#include "ash/public/cpp/notification_utils.h"
Evan Stade6a095782018-02-14 03:55:008#include "ash/public/cpp/vector_icons/vector_icons.h"
xiaoyinhf39e3dd2016-06-18 04:50:239#include "chrome/browser/browser_process.h"
Sarah Hu4ad394b2017-11-27 19:03:0010#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
Evan Stadecc63b182017-09-26 16:05:1211#include "chrome/browser/notifications/notification_display_service.h"
12#include "chrome/browser/notifications/notification_display_service_factory.h"
xiaoyinhf39e3dd2016-06-18 04:50:2313#include "chrome/browser/ui/browser_navigator.h"
14#include "chrome/browser/ui/browser_navigator_params.h"
15#include "chrome/common/pref_names.h"
16#include "chrome/common/url_constants.h"
17#include "chrome/grit/generated_resources.h"
Sarah Hu4ad394b2017-11-27 19:03:0018#include "chromeos/chromeos_switches.h"
xiaoyinhf39e3dd2016-06-18 04:50:2319#include "chromeos/dbus/dbus_thread_manager.h"
20#include "chromeos/dbus/update_engine_client.h"
21#include "components/prefs/pref_service.h"
dpapad943ef182018-01-20 02:58:2022#include "components/strings/grit/components_strings.h"
xiaoyinhf39e3dd2016-06-18 04:50:2323#include "ui/base/l10n/l10n_util.h"
xiaoyinhaa17d8342016-06-30 22:56:0224#include "ui/gfx/color_palette.h"
25#include "ui/gfx/paint_vector_icon.h"
Evan Stade889ce4712018-01-28 15:26:2626#include "ui/message_center/public/cpp/notification.h"
xiaoyinhf39e3dd2016-06-18 04:50:2327
Tetsui Ohkuboe8f95e82017-08-23 06:10:4728using l10n_util::GetStringUTF16;
xiaoyinhf39e3dd2016-06-18 04:50:2329
30namespace chromeos {
31namespace {
32
Evan Stadecc63b182017-09-26 16:05:1233const char kEolNotificationId[] = "chrome://product_eol";
xiaoyinhf39e3dd2016-06-18 04:50:2334
Evan Stadecf27dae12017-11-07 23:57:5135// Buttons that appear in notifications.
36enum ButtonIndex {
37 BUTTON_MORE_INFO = 0,
38 BUTTON_DISMISS,
39 BUTTON_SIZE = BUTTON_DISMISS
40};
Evan Stadecc63b182017-09-26 16:05:1241
Evan Stadecf27dae12017-11-07 23:57:5142class EolNotificationDelegate : public message_center::NotificationDelegate {
43 public:
44 explicit EolNotificationDelegate(Profile* profile) : profile_(profile) {}
45
46 private:
47 ~EolNotificationDelegate() override = default;
48
49 // NotificationDelegate overrides:
Evan Stadee0921092018-04-04 21:13:0950 void Click(const base::Optional<int>& button_index,
51 const base::Optional<base::string16>& reply) override {
52 if (!button_index)
53 return;
54
55 switch (*button_index) {
Evan Stadecc63b182017-09-26 16:05:1256 case BUTTON_MORE_INFO: {
57 // show eol link
cm.sanchi2522bc92017-12-04 08:04:1358 NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
59 ui::PAGE_TRANSITION_LINK);
Evan Stadecc63b182017-09-26 16:05:1260 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
cm.sanchi2522bc92017-12-04 08:04:1361 params.window_action = NavigateParams::SHOW_WINDOW;
62 Navigate(&params);
Evan Stadecc63b182017-09-26 16:05:1263 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(
Peter Beverloo6dba2e102017-11-23 17:46:3372 NotificationHandler::Type::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
Sarah Hu4ad394b2017-11-27 19:03:0082// static
83bool EolNotification::ShouldShowEolNotification() {
84 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
85 chromeos::switches::kDisableEolNotification)) {
86 return false;
87 }
88
89 // Do not show end of life notification if this device is managed by
90 // enterprise user.
91 if (g_browser_process->platform_part()
92 ->browser_policy_connector_chromeos()
93 ->IsEnterpriseManaged()) {
94 return false;
95 }
96
97 return true;
98}
99
xiaoyinhf39e3dd2016-06-18 04:50:23100EolNotification::EolNotification(Profile* profile)
101 : profile_(profile),
102 status_(update_engine::EndOfLifeStatus::kSupported),
103 weak_factory_(this) {}
104
105EolNotification::~EolNotification() {}
106
107void EolNotification::CheckEolStatus() {
108 UpdateEngineClient* update_engine_client =
109 DBusThreadManager::Get()->GetUpdateEngineClient();
110
111 // Request the Eol Status.
Sarah Hu32816fa72018-02-28 02:20:38112 update_engine_client->GetEolStatus(base::BindOnce(
113 &EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
xiaoyinhf39e3dd2016-06-18 04:50:23114}
115
xiaoyinhaa17d8342016-06-30 22:56:02116void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) {
xiaoyinhf39e3dd2016-06-18 04:50:23117 status_ = status;
118
119 const int pre_eol_status =
120 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
121 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
122
xiaoyinhf4e5b5b2017-02-27 23:22:46123 // Security only state is no longer supported.
124 if (status_ == update_engine::EndOfLifeStatus::kSupported ||
125 status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
xiaoyinhf39e3dd2016-06-18 04:50:23126 return;
xiaoyinhf4e5b5b2017-02-27 23:22:46127 }
xiaoyinhf39e3dd2016-06-18 04:50:23128
129 if (pre_eol_status != status_) {
130 // If Eol status has changed, we should reset
131 // kEolNotificationDismissed and show notification.
132 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
133 }
134
135 bool user_dismissed_eol_notification =
136 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
137 if (user_dismissed_eol_notification)
138 return;
139
xiaoyinhf39e3dd2016-06-18 04:50:23140 Update();
141}
142
143void EolNotification::Update() {
xiaoyinhf39e3dd2016-06-18 04:50:23144 message_center::RichNotificationData data;
Evan Stadecf27dae12017-11-07 23:57:51145
146 DCHECK_EQ(BUTTON_MORE_INFO, data.buttons.size());
dpapad943ef182018-01-20 02:58:20147 data.buttons.emplace_back(GetStringUTF16(IDS_LEARN_MORE));
Evan Stadecf27dae12017-11-07 23:57:51148
149 DCHECK_EQ(BUTTON_DISMISS, data.buttons.size());
150 data.buttons.emplace_back(GetStringUTF16(IDS_EOL_DISMISS_BUTTON));
xiaoyinhf39e3dd2016-06-18 04:50:23151
Tetsui Ohkubof24e7a942017-12-19 03:15:00152 std::unique_ptr<message_center::Notification> notification =
Evan Stade70e2ed42018-11-08 06:23:05153 ash::CreateSystemNotification(
Tetsui Ohkubof24e7a942017-12-19 03:15:00154 message_center::NOTIFICATION_TYPE_SIMPLE, kEolNotificationId,
155 GetStringUTF16(IDS_EOL_NOTIFICATION_TITLE),
Evan Stade35e870cd2018-08-08 19:04:09156 GetStringUTF16(IDS_EOL_NOTIFICATION_EOL),
Tetsui Ohkubof24e7a942017-12-19 03:15:00157 GetStringUTF16(IDS_EOL_NOTIFICATION_DISPLAY_SOURCE),
158 GURL(kEolNotificationId),
159 message_center::NotifierId(
Daniel Chenga925cbb52018-11-06 21:52:35160 message_center::NotifierType::SYSTEM_COMPONENT,
161 kEolNotificationId),
Tetsui Ohkubof24e7a942017-12-19 03:15:00162 data, new EolNotificationDelegate(profile_),
Evan Stade6a095782018-02-14 03:55:00163 ash::kNotificationEndOfSupportIcon,
Tetsui Ohkubof24e7a942017-12-19 03:15:00164 message_center::SystemNotificationWarningLevel::CRITICAL_WARNING);
Evan Stadecc63b182017-09-26 16:05:12165
Evan Stadecc63b182017-09-26 16:05:12166 NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
Tetsui Ohkubof24e7a942017-12-19 03:15:00167 NotificationHandler::Type::TRANSIENT, *notification);
xiaoyinhf39e3dd2016-06-18 04:50:23168}
169
xiaoyinhf39e3dd2016-06-18 04:50:23170} // namespace chromeos