blob: 83ffa786e18b2552ec49330e7f6424e102f84e72 [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 Stade6a095782018-02-14 03:55:007#include "ash/public/cpp/vector_icons/vector_icons.h"
xiaoyinhf39e3dd2016-06-18 04:50:238#include "chrome/browser/browser_process.h"
Sarah Hu4ad394b2017-11-27 19:03:009#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
Evan Stadecc63b182017-09-26 16:05:1210#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"
Sarah Hu4ad394b2017-11-27 19:03:0017#include "chromeos/chromeos_switches.h"
xiaoyinhf39e3dd2016-06-18 04:50:2318#include "chromeos/dbus/dbus_thread_manager.h"
19#include "chromeos/dbus/update_engine_client.h"
20#include "components/prefs/pref_service.h"
dpapad943ef182018-01-20 02:58:2021#include "components/strings/grit/components_strings.h"
xiaoyinhf39e3dd2016-06-18 04:50:2322#include "ui/base/l10n/l10n_util.h"
xiaoyinhaa17d8342016-06-30 22:56:0223#include "ui/gfx/color_palette.h"
24#include "ui/gfx/paint_vector_icon.h"
Evan Stade889ce4712018-01-28 15:26:2625#include "ui/message_center/public/cpp/notification.h"
xiaoyinhf39e3dd2016-06-18 04:50:2326
Tetsui Ohkuboe8f95e82017-08-23 06:10:4727using l10n_util::GetStringUTF16;
xiaoyinhf39e3dd2016-06-18 04:50:2328
29namespace chromeos {
30namespace {
31
Evan Stadecc63b182017-09-26 16:05:1232const char kEolNotificationId[] = "chrome://product_eol";
xiaoyinhf39e3dd2016-06-18 04:50:2333
Evan Stadecf27dae12017-11-07 23:57:5134// Buttons that appear in notifications.
35enum ButtonIndex {
36 BUTTON_MORE_INFO = 0,
37 BUTTON_DISMISS,
38 BUTTON_SIZE = BUTTON_DISMISS
39};
Evan Stadecc63b182017-09-26 16:05:1240
Evan Stadecf27dae12017-11-07 23:57:5141class EolNotificationDelegate : public message_center::NotificationDelegate {
42 public:
43 explicit EolNotificationDelegate(Profile* profile) : profile_(profile) {}
44
45 private:
46 ~EolNotificationDelegate() override = default;
47
48 // NotificationDelegate overrides:
Evan Stadee0921092018-04-04 21:13:0949 void Click(const base::Optional<int>& button_index,
50 const base::Optional<base::string16>& reply) override {
51 if (!button_index)
52 return;
53
54 switch (*button_index) {
Evan Stadecc63b182017-09-26 16:05:1255 case BUTTON_MORE_INFO: {
56 // show eol link
cm.sanchi2522bc92017-12-04 08:04:1357 NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
58 ui::PAGE_TRANSITION_LINK);
Evan Stadecc63b182017-09-26 16:05:1259 params.disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
cm.sanchi2522bc92017-12-04 08:04:1360 params.window_action = NavigateParams::SHOW_WINDOW;
61 Navigate(&params);
Evan Stadecc63b182017-09-26 16:05:1262 break;
63 }
64 case BUTTON_DISMISS:
65 // set dismiss pref.
Evan Stadecf27dae12017-11-07 23:57:5166 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed,
67 true);
Evan Stadecc63b182017-09-26 16:05:1268 break;
69 }
Evan Stadecf27dae12017-11-07 23:57:5170 NotificationDisplayServiceFactory::GetForProfile(profile_)->Close(
Peter Beverloo6dba2e102017-11-23 17:46:3371 NotificationHandler::Type::TRANSIENT, kEolNotificationId);
Evan Stadecc63b182017-09-26 16:05:1272 }
73
Evan Stadecf27dae12017-11-07 23:57:5174 Profile* const profile_;
xiaoyinhf39e3dd2016-06-18 04:50:2375
Evan Stadecf27dae12017-11-07 23:57:5176 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
xiaoyinhf39e3dd2016-06-18 04:50:2377};
78
xiaoyinhf39e3dd2016-06-18 04:50:2379} // namespace
80
Sarah Hu4ad394b2017-11-27 19:03:0081// static
82bool EolNotification::ShouldShowEolNotification() {
83 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
84 chromeos::switches::kDisableEolNotification)) {
85 return false;
86 }
87
88 // Do not show end of life notification if this device is managed by
89 // enterprise user.
90 if (g_browser_process->platform_part()
91 ->browser_policy_connector_chromeos()
92 ->IsEnterpriseManaged()) {
93 return false;
94 }
95
96 return true;
97}
98
xiaoyinhf39e3dd2016-06-18 04:50:2399EolNotification::EolNotification(Profile* profile)
100 : profile_(profile),
101 status_(update_engine::EndOfLifeStatus::kSupported),
102 weak_factory_(this) {}
103
104EolNotification::~EolNotification() {}
105
106void EolNotification::CheckEolStatus() {
107 UpdateEngineClient* update_engine_client =
108 DBusThreadManager::Get()->GetUpdateEngineClient();
109
110 // Request the Eol Status.
Sarah Hu32816fa72018-02-28 02:20:38111 update_engine_client->GetEolStatus(base::BindOnce(
112 &EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
xiaoyinhf39e3dd2016-06-18 04:50:23113}
114
xiaoyinhaa17d8342016-06-30 22:56:02115void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) {
xiaoyinhf39e3dd2016-06-18 04:50:23116 status_ = status;
117
118 const int pre_eol_status =
119 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
120 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
121
xiaoyinhf4e5b5b2017-02-27 23:22:46122 // Security only state is no longer supported.
123 if (status_ == update_engine::EndOfLifeStatus::kSupported ||
124 status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
xiaoyinhf39e3dd2016-06-18 04:50:23125 return;
xiaoyinhf4e5b5b2017-02-27 23:22:46126 }
xiaoyinhf39e3dd2016-06-18 04:50:23127
128 if (pre_eol_status != status_) {
129 // If Eol status has changed, we should reset
130 // kEolNotificationDismissed and show notification.
131 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
132 }
133
134 bool user_dismissed_eol_notification =
135 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
136 if (user_dismissed_eol_notification)
137 return;
138
xiaoyinhf39e3dd2016-06-18 04:50:23139 Update();
140}
141
142void EolNotification::Update() {
xiaoyinhf39e3dd2016-06-18 04:50:23143 message_center::RichNotificationData data;
Evan Stadecf27dae12017-11-07 23:57:51144
145 DCHECK_EQ(BUTTON_MORE_INFO, data.buttons.size());
dpapad943ef182018-01-20 02:58:20146 data.buttons.emplace_back(GetStringUTF16(IDS_LEARN_MORE));
Evan Stadecf27dae12017-11-07 23:57:51147
148 DCHECK_EQ(BUTTON_DISMISS, data.buttons.size());
149 data.buttons.emplace_back(GetStringUTF16(IDS_EOL_DISMISS_BUTTON));
xiaoyinhf39e3dd2016-06-18 04:50:23150
Tetsui Ohkubof24e7a942017-12-19 03:15:00151 std::unique_ptr<message_center::Notification> notification =
152 message_center::Notification::CreateSystemNotification(
153 message_center::NOTIFICATION_TYPE_SIMPLE, kEolNotificationId,
154 GetStringUTF16(IDS_EOL_NOTIFICATION_TITLE),
155 GetStringUTF16(IDS_EOL_NOTIFICATION_EOL), gfx::Image(),
156 GetStringUTF16(IDS_EOL_NOTIFICATION_DISPLAY_SOURCE),
157 GURL(kEolNotificationId),
158 message_center::NotifierId(
159 message_center::NotifierId::SYSTEM_COMPONENT, kEolNotificationId),
160 data, new EolNotificationDelegate(profile_),
Evan Stade6a095782018-02-14 03:55:00161 ash::kNotificationEndOfSupportIcon,
Tetsui Ohkubof24e7a942017-12-19 03:15:00162 message_center::SystemNotificationWarningLevel::CRITICAL_WARNING);
Evan Stadecc63b182017-09-26 16:05:12163
Evan Stadecc63b182017-09-26 16:05:12164 NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
Tetsui Ohkubof24e7a942017-12-19 03:15:00165 NotificationHandler::Type::TRANSIENT, *notification);
xiaoyinhf39e3dd2016-06-18 04:50:23166}
167
xiaoyinhf39e3dd2016-06-18 04:50:23168} // namespace chromeos