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

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: hook EolNotification in UserSessionManager::FinalizePrepareProfile 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 #include "ui/gfx/image/image.h"
xiyuan 2016/06/17 20:02:09 nit: not used. Only need to include this if we act
xiaoyinh(OOO Sep 11-29) 2016/06/17 22:36:53 Done.
23
24 using message_center::MessageCenter;
25
26 namespace chromeos {
27 namespace {
28
29 const char kEolNotificationId[] = "eol";
30 const char kDelegateId[] = "eol_delegate";
31
32 class EolNotificationDelegate : public NotificationDelegate {
33 public:
34 explicit EolNotificationDelegate(Profile* profile);
35
36 private:
37 ~EolNotificationDelegate() override;
38
39 // NotificationDelegate overrides:
40 void Close(bool by_user) override;
41 void ButtonClick(int button_index) override;
42 std::string id() const override;
43
44 Profile* const profile_;
45
46 void OpenMoreInfoPage();
47
48 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate);
49 };
50
51 EolNotificationDelegate::EolNotificationDelegate(Profile* profile)
52 : profile_(profile) {}
53
54 EolNotificationDelegate::~EolNotificationDelegate() {}
55
56 void EolNotificationDelegate::Close(bool by_user) {
57 if (by_user) {
58 // set dismiss pref.
59 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
60 }
61 }
62
63 void EolNotificationDelegate::ButtonClick(int button_index) {
64 // show eol link
65 OpenMoreInfoPage();
66 }
67
68 std::string EolNotificationDelegate::id() const {
69 return kDelegateId;
70 }
71
72 void EolNotificationDelegate::OpenMoreInfoPage() {
73 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
74 ui::PAGE_TRANSITION_LINK);
75 params.disposition = NEW_FOREGROUND_TAB;
76 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
77 chrome::Navigate(&params);
78 }
79
80 } // namespace
81
82 EolNotification::EolNotification(Profile* profile)
83 : profile_(profile),
84 status_(update_engine::EndOfLifeStatus::kSupported),
85 weak_factory_(this) {}
86
87 EolNotification::~EolNotification() {}
xiyuan 2016/06/17 20:02:09 Do we need to notification_ui_manager()->CancelByI
xiaoyinh(OOO Sep 11-29) 2016/06/17 22:36:53 I added CancelById in the EolNotificationDelegate
88
89 void EolNotification::CheckEolStatus() {
90 UpdateEngineClient* update_engine_client =
91 DBusThreadManager::Get()->GetUpdateEngineClient();
92
93 // Request the Eol Status.
94 update_engine_client->GetEolStatus(
95 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
96 }
97
98 void EolNotification::OnEolStatus(int status) {
99 status_ = status;
100
101 const int pre_eol_status =
102 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
103 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
104
105 if (status_ == update_engine::EndOfLifeStatus::kSupported)
106 return;
107
108 if (pre_eol_status != status_) {
109 // If Eol status has changed, we should reset
110 // kEolNotificationDismissed and show notification.
111 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
112 }
113
114 bool user_dismissed_eol_notification =
115 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
116 if (user_dismissed_eol_notification)
117 return;
118
119 // When device is in Security-Only state, only show notification the first
120 // time.
121 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
122 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
123 }
124
125 Update();
126 }
127
128 void EolNotification::Update() {
129 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
130 message_center::RichNotificationData data;
131 data.buttons.push_back(message_center::ButtonInfo(
132 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON)));
133
134 Notification notification(
135 message_center::NOTIFICATION_TYPE_SIMPLE,
136 base::string16(), // title
137 // TODO(xiaoyinh): Update the Eol icon once it's ready.
138 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
139 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
140 kEolNotificationId),
141 base::string16(), // display_source
142 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_));
143 g_browser_process->notification_ui_manager()->Add(notification, profile_);
144 }
145
146 base::string16 EolNotification::GetEolMessage() {
147 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
148 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY);
149 } else {
150 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL);
151 }
152 }
153
154 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698