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

Side by Side 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: incorporate comments from xiyuan@ 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/notifications/notification.h"
9 #include "chrome/browser/notifications/notification_ui_manager.h"
10 #include "chrome/browser/ui/browser_navigator.h"
11 #include "chrome/browser/ui/browser_navigator_params.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "chromeos/dbus/update_engine_client.h"
17 #include "components/prefs/pref_service.h"
18 #include "grit/ash_resources.h"
19 #include "third_party/cros_system_api/dbus/update_engine/dbus-constants.h"
20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/resource/resource_bundle.h"
22
23 using message_center::MessageCenter;
24
25 namespace chromeos {
26 namespace {
27
28 const char kEolNotificationId[] = "eol";
29 const char kDelegateId[] = "eol_delegate";
30
31 class EolNotificationDelegate : public NotificationDelegate {
32 public:
33 explicit EolNotificationDelegate(Profile* profile);
34
35 private:
36 ~EolNotificationDelegate() override;
37
38 // NotificationDelegate overrides:
39 void Close(bool by_user) override;
40 void ButtonClick(int button_index) override;
41 std::string id() const override;
42
43 Profile* const profile_;
44
45 void OpenMoreInfoPage();
46
47 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
48 };
49
50 EolNotificationDelegate::EolNotificationDelegate(Profile* profile)
51 : profile_(profile) {}
52
53 EolNotificationDelegate::~EolNotificationDelegate() {
54 // Clean up the notification
55 g_browser_process->notification_ui_manager()->CancelById(
56 id(), NotificationUIManager::GetProfileID(profile_));
xiyuan 2016/06/17 22:43:11 Don't do this in NotificationDelegate's destructor
xiaoyinh(OOO Sep 11-29) 2016/06/17 22:59:59 Removed.
57 }
58
59 void EolNotificationDelegate::Close(bool by_user) {
60 if (by_user) {
61 // set dismiss pref.
62 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
63 }
64 }
65
66 void EolNotificationDelegate::ButtonClick(int button_index) {
67 // show eol link
68 OpenMoreInfoPage();
69 }
70
71 std::string EolNotificationDelegate::id() const {
72 return kDelegateId;
73 }
74
75 void EolNotificationDelegate::OpenMoreInfoPage() {
76 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
77 ui::PAGE_TRANSITION_LINK);
78 params.disposition = NEW_FOREGROUND_TAB;
79 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
80 chrome::Navigate(&params);
81 }
82
83 } // namespace
84
85 EolNotification::EolNotification(Profile* profile)
86 : profile_(profile),
87 status_(update_engine::EndOfLifeStatus::kSupported),
88 weak_factory_(this) {}
89
90 EolNotification::~EolNotification() {}
91
92 void EolNotification::CheckEolStatus() {
93 UpdateEngineClient* update_engine_client =
94 DBusThreadManager::Get()->GetUpdateEngineClient();
95
96 // Request the Eol Status.
97 update_engine_client->GetEolStatus(
98 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
99 }
100
101 void EolNotification::OnEolStatus(int status) {
102 status_ = status;
103
104 const int pre_eol_status =
105 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
106 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
107
108 if (status_ == update_engine::EndOfLifeStatus::kSupported)
109 return;
110
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
122 // When device is in Security-Only state, only show notification the first
123 // time.
124 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
125 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
126 }
127
128 Update();
129 }
130
131 void EolNotification::Update() {
132 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
133 message_center::RichNotificationData data;
134 data.buttons.push_back(message_center::ButtonInfo(
135 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON)));
136
137 Notification notification(
138 message_center::NOTIFICATION_TYPE_SIMPLE,
139 base::string16(), // title
140 // TODO(xiaoyinh): Update the Eol icon once it's ready.
141 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
142 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
143 kEolNotificationId),
144 base::string16(), // display_source
145 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_));
146 g_browser_process->notification_ui_manager()->Add(notification, profile_);
147 }
148
149 base::string16 EolNotification::GetEolMessage() {
150 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
151 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY);
152 } else {
153 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL);
154 }
155 }
156
157 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/eol_notification.h ('k') | chrome/browser/chromeos/login/session/user_session_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698