blob: 63955b4440d87b7a19e8344af77e4459678531c8 [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"
Sebastien Marchandf1349f52019-01-25 03:16:418#include "base/bind.h"
Evan Stade82ba4b62019-07-11 01:58:019#include "chrome/app/vector_icons/vector_icons.h"
xiaoyinhf39e3dd2016-06-18 04:50:2310#include "chrome/browser/browser_process.h"
Sarah Hu4ad394b2017-11-27 19:03:0011#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
Evan Stadecc63b182017-09-26 16:05:1212#include "chrome/browser/notifications/notification_display_service.h"
13#include "chrome/browser/notifications/notification_display_service_factory.h"
xiaoyinhf39e3dd2016-06-18 04:50:2314#include "chrome/browser/ui/browser_navigator.h"
15#include "chrome/browser/ui/browser_navigator_params.h"
16#include "chrome/common/pref_names.h"
17#include "chrome/common/url_constants.h"
18#include "chrome/grit/generated_resources.h"
19#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"
Vladislav Kaznacheeve9805222019-05-28 19:44:4024#include "ui/chromeos/devicetype_utils.h"
xiaoyinhaa17d8342016-06-30 22:56:0225#include "ui/gfx/color_palette.h"
26#include "ui/gfx/paint_vector_icon.h"
Evan Stade889ce4712018-01-28 15:26:2627#include "ui/message_center/public/cpp/notification.h"
xiaoyinhf39e3dd2016-06-18 04:50:2328
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";
xiaoyinhf39e3dd2016-06-18 04:50:2335
Evan Stadecf27dae12017-11-07 23:57:5136// Buttons that appear in notifications.
37enum ButtonIndex {
38 BUTTON_MORE_INFO = 0,
39 BUTTON_DISMISS,
40 BUTTON_SIZE = BUTTON_DISMISS
41};
Evan Stadecc63b182017-09-26 16:05:1242
Evan Stadecf27dae12017-11-07 23:57:5143class EolNotificationDelegate : public message_center::NotificationDelegate {
44 public:
45 explicit EolNotificationDelegate(Profile* profile) : profile_(profile) {}
46
47 private:
48 ~EolNotificationDelegate() override = default;
49
50 // NotificationDelegate overrides:
Evan Stadee0921092018-04-04 21:13:0951 void Click(const base::Optional<int>& button_index,
52 const base::Optional<base::string16>& reply) override {
53 if (!button_index)
54 return;
55
56 switch (*button_index) {
Evan Stadecc63b182017-09-26 16:05:1257 case BUTTON_MORE_INFO: {
58 // show eol link
cm.sanchi2522bc92017-12-04 08:04:1359 NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
60 ui::PAGE_TRANSITION_LINK);
Evan Stadecc63b182017-09-26 16:05:1261 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
cm.sanchi2522bc92017-12-04 08:04:1362 params.window_action = NavigateParams::SHOW_WINDOW;
63 Navigate(&params);
Evan Stadecc63b182017-09-26 16:05:1264 break;
65 }
66 case BUTTON_DISMISS:
67 // set dismiss pref.
Evan Stadecf27dae12017-11-07 23:57:5168 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed,
69 true);
Evan Stadecc63b182017-09-26 16:05:1270 break;
71 }
Evan Stadecf27dae12017-11-07 23:57:5172 NotificationDisplayServiceFactory::GetForProfile(profile_)->Close(
Peter Beverloo6dba2e102017-11-23 17:46:3373 NotificationHandler::Type::TRANSIENT, kEolNotificationId);
Evan Stadecc63b182017-09-26 16:05:1274 }
75
Evan Stadecf27dae12017-11-07 23:57:5176 Profile* const profile_;
xiaoyinhf39e3dd2016-06-18 04:50:2377
Evan Stadecf27dae12017-11-07 23:57:5178 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
xiaoyinhf39e3dd2016-06-18 04:50:2379};
80
xiaoyinhf39e3dd2016-06-18 04:50:2381} // namespace
82
Sarah Hu4ad394b2017-11-27 19:03:0083// static
84bool EolNotification::ShouldShowEolNotification() {
Sarah Hu4ad394b2017-11-27 19:03:0085 // Do not show end of life notification if this device is managed by
86 // enterprise user.
87 if (g_browser_process->platform_part()
88 ->browser_policy_connector_chromeos()
89 ->IsEnterpriseManaged()) {
90 return false;
91 }
92
93 return true;
94}
95
xiaoyinhf39e3dd2016-06-18 04:50:2396EolNotification::EolNotification(Profile* profile)
97 : profile_(profile),
98 status_(update_engine::EndOfLifeStatus::kSupported),
99 weak_factory_(this) {}
100
101EolNotification::~EolNotification() {}
102
103void EolNotification::CheckEolStatus() {
104 UpdateEngineClient* update_engine_client =
105 DBusThreadManager::Get()->GetUpdateEngineClient();
106
107 // Request the Eol Status.
Sarah Hu32816fa72018-02-28 02:20:38108 update_engine_client->GetEolStatus(base::BindOnce(
109 &EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
xiaoyinhf39e3dd2016-06-18 04:50:23110}
111
xiaoyinhaa17d8342016-06-30 22:56:02112void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) {
xiaoyinhf39e3dd2016-06-18 04:50:23113 status_ = status;
114
115 const int pre_eol_status =
116 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
117 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
118
xiaoyinhf4e5b5b2017-02-27 23:22:46119 // Security only state is no longer supported.
120 if (status_ == update_engine::EndOfLifeStatus::kSupported ||
121 status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
xiaoyinhf39e3dd2016-06-18 04:50:23122 return;
xiaoyinhf4e5b5b2017-02-27 23:22:46123 }
xiaoyinhf39e3dd2016-06-18 04:50:23124
125 if (pre_eol_status != status_) {
126 // If Eol status has changed, we should reset
127 // kEolNotificationDismissed and show notification.
128 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
129 }
130
131 bool user_dismissed_eol_notification =
132 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
133 if (user_dismissed_eol_notification)
134 return;
135
xiaoyinhf39e3dd2016-06-18 04:50:23136 Update();
137}
138
139void EolNotification::Update() {
xiaoyinhf39e3dd2016-06-18 04:50:23140 message_center::RichNotificationData data;
Evan Stadecf27dae12017-11-07 23:57:51141
142 DCHECK_EQ(BUTTON_MORE_INFO, data.buttons.size());
dpapad943ef182018-01-20 02:58:20143 data.buttons.emplace_back(GetStringUTF16(IDS_LEARN_MORE));
Evan Stadecf27dae12017-11-07 23:57:51144
145 DCHECK_EQ(BUTTON_DISMISS, data.buttons.size());
146 data.buttons.emplace_back(GetStringUTF16(IDS_EOL_DISMISS_BUTTON));
xiaoyinhf39e3dd2016-06-18 04:50:23147
Tetsui Ohkubof24e7a942017-12-19 03:15:00148 std::unique_ptr<message_center::Notification> notification =
Evan Stade70e2ed42018-11-08 06:23:05149 ash::CreateSystemNotification(
Tetsui Ohkubof24e7a942017-12-19 03:15:00150 message_center::NOTIFICATION_TYPE_SIMPLE, kEolNotificationId,
151 GetStringUTF16(IDS_EOL_NOTIFICATION_TITLE),
Vladislav Kaznacheeve9805222019-05-28 19:44:40152 l10n_util::GetStringFUTF16(IDS_EOL_NOTIFICATION_EOL,
153 ui::GetChromeOSDeviceName()),
154 base::string16() /* display_source */, GURL(kEolNotificationId),
Tetsui Ohkubof24e7a942017-12-19 03:15:00155 message_center::NotifierId(
Daniel Chenga925cbb52018-11-06 21:52:35156 message_center::NotifierType::SYSTEM_COMPONENT,
157 kEolNotificationId),
Tetsui Ohkubof24e7a942017-12-19 03:15:00158 data, new EolNotificationDelegate(profile_),
Evan Stade82ba4b62019-07-11 01:58:01159 kNotificationEndOfSupportIcon,
Vladislav Kaznacheeve9805222019-05-28 19:44:40160 message_center::SystemNotificationWarningLevel::NORMAL);
Evan Stadecc63b182017-09-26 16:05:12161
Evan Stadecc63b182017-09-26 16:05:12162 NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
Lei Zhang03c6b782019-03-21 05:22:24163 NotificationHandler::Type::TRANSIENT, *notification,
164 /*metadata=*/nullptr);
xiaoyinhf39e3dd2016-06-18 04:50:23165}
166
xiaoyinhf39e3dd2016-06-18 04:50:23167} // namespace chromeos