Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Unified Diff: chrome/browser/chromeos/eol_notification.cc

Issue 2060623002: Implementation of Device End of Life Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase the branch Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/eol_notification.cc
diff --git a/chrome/browser/chromeos/eol_notification.cc b/chrome/browser/chromeos/eol_notification.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a9dcb91763acbd9c6d020191b4360a7c1fe21fd3
--- /dev/null
+++ b/chrome/browser/chromeos/eol_notification.cc
@@ -0,0 +1,153 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// // Use of this source code is governed by a BSD-style license that can be
+// // found in the LICENSE file.
+
+#include "chrome/browser/chromeos/eol_notification.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/browser/ui/browser_navigator_params.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
+#include "chrome/grit/generated_resources.h"
+#include "chromeos/dbus/dbus_thread_manager.h"
+#include "chromeos/dbus/update_engine_client.h"
+#include "components/prefs/pref_service.h"
+#include "grit/ash_resources.h"
+#include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+using message_center::MessageCenter;
+
+namespace chromeos {
+namespace {
+
+const char kEolNotificationId[] = "eol";
+const char kDelegateId[] = "eol_delegate";
+
+class EolNotificationDelegate : public NotificationDelegate {
+ public:
+ explicit EolNotificationDelegate(Profile* profile);
+
+ private:
+ ~EolNotificationDelegate() override;
+
+ // NotificationDelegate overrides:
+ void Close(bool by_user) override;
+ void ButtonClick(int button_index) override;
+ std::string id() const override;
+
+ Profile* const profile_;
+
+ void OpenMoreInfoPage();
+
+ DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
+};
+
+EolNotificationDelegate::EolNotificationDelegate(Profile* profile)
+ : profile_(profile) {}
+
+EolNotificationDelegate::~EolNotificationDelegate() {}
+
+void EolNotificationDelegate::Close(bool by_user) {
+ if (by_user) {
+ // set dismiss pref.
+ profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
+ }
+}
+
+void EolNotificationDelegate::ButtonClick(int button_index) {
+ // show eol link
+ OpenMoreInfoPage();
+}
+
+std::string EolNotificationDelegate::id() const {
+ return kDelegateId;
+}
+
+void EolNotificationDelegate::OpenMoreInfoPage() {
+ chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
+ ui::PAGE_TRANSITION_LINK);
+ params.disposition = NEW_FOREGROUND_TAB;
+ params.window_action = chrome::NavigateParams::SHOW_WINDOW;
+ chrome::Navigate(&params);
+}
+
+} // namespace
+
+EolNotification::EolNotification(Profile* profile)
+ : profile_(profile),
+ status_(update_engine::EndOfLifeStatus::kSupported),
+ weak_factory_(this) {}
+
+EolNotification::~EolNotification() {}
+
+void EolNotification::CheckEolStatus() {
+ UpdateEngineClient* update_engine_client =
+ DBusThreadManager::Get()->GetUpdateEngineClient();
+
+ // Request the Eol Status.
+ update_engine_client->GetEolStatus(
+ base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
+}
+
+void EolNotification::OnEolStatus(int status) {
+ status_ = status;
oshima 2016/06/17 23:54:58 does it makes sense to check status_ != state, or
xiaoyinh(OOO Sep 11-29) 2016/06/18 01:08:12 There are cases that we want to show notification
+
+ const int pre_eol_status =
+ profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
+ profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
+
+ if (status_ == update_engine::EndOfLifeStatus::kSupported)
+ return;
+
+ if (pre_eol_status != status_) {
+ // If Eol status has changed, we should reset
+ // kEolNotificationDismissed and show notification.
+ profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
+ }
+
+ bool user_dismissed_eol_notification =
+ profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
+ if (user_dismissed_eol_notification)
+ return;
+
+ // When device is in Security-Only state, only show notification the first
+ // time.
+ if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
+ profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
+ }
oshima 2016/06/17 23:54:58 nit: remove {}
xiaoyinh(OOO Sep 11-29) 2016/06/18 01:08:12 Done.
+
+ Update();
+}
+
+void EolNotification::Update() {
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+ message_center::RichNotificationData data;
+ data.buttons.push_back(message_center::ButtonInfo(
+ l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON)));
+
+ Notification notification(
+ message_center::NOTIFICATION_TYPE_SIMPLE,
+ base::string16(), // title
+ // TODO(xiaoyinh): Update the Eol icon once it's ready.
+ GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
+ message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
+ kEolNotificationId),
+ base::string16(), // display_source
+ GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_));
+ g_browser_process->notification_ui_manager()->Add(notification, profile_);
+}
+
+base::string16 EolNotification::GetEolMessage() {
+ if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
+ return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY);
+ } else {
+ return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL);
+ }
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698