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

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: 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 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
55 void EolNotificationDelegate::Close(bool by_user) {
56 if (by_user) {
57 // set dismiss pref.
58 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
59 }
60 }
61
62 void EolNotificationDelegate::ButtonClick(int button_index) {
63 // show eol link
64 OpenMoreInfoPage();
65 }
66
67 std::string EolNotificationDelegate::id() const {
68 return kDelegateId;
69 }
70
71 void EolNotificationDelegate::OpenMoreInfoPage() {
72 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL),
73 ui::PAGE_TRANSITION_LINK);
74 params.disposition = NEW_FOREGROUND_TAB;
75 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
76 chrome::Navigate(&params);
77 }
78
79 } // namespace
80
81 EolNotification::EolNotification(Profile* profile)
82 : profile_(profile),
83 status_(update_engine::EndOfLifeStatus::kSupported),
84 weak_factory_(this) {}
85
86 EolNotification::~EolNotification() {}
87
88 void EolNotification::CheckEolStatus() {
89 UpdateEngineClient* update_engine_client =
90 DBusThreadManager::Get()->GetUpdateEngineClient();
91
92 // Request the Eol Status.
93 update_engine_client->GetEolStatus(
94 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr()));
95 }
96
97 void EolNotification::OnEolStatus(int status) {
98 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
99
100 const int pre_eol_status =
101 profile_->GetPrefs()->GetInteger(prefs::kEolStatus);
102 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_);
103
104 if (status_ == update_engine::EndOfLifeStatus::kSupported)
105 return;
106
107 if (pre_eol_status != status_) {
108 // If Eol status has changed, we should reset
109 // kEolNotificationDismissed and show notification.
110 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false);
111 }
112
113 bool user_dismissed_eol_notification =
114 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed);
115 if (user_dismissed_eol_notification)
116 return;
117
118 // When device is in Security-Only state, only show notification the first
119 // time.
120 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
121 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true);
122 }
oshima 2016/06/17 23:54:58 nit: remove {}
xiaoyinh(OOO Sep 11-29) 2016/06/18 01:08:12 Done.
123
124 Update();
125 }
126
127 void EolNotification::Update() {
128 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
129 message_center::RichNotificationData data;
130 data.buttons.push_back(message_center::ButtonInfo(
131 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON)));
132
133 Notification notification(
134 message_center::NOTIFICATION_TYPE_SIMPLE,
135 base::string16(), // title
136 // TODO(xiaoyinh): Update the Eol icon once it's ready.
137 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
138 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
139 kEolNotificationId),
140 base::string16(), // display_source
141 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_));
142 g_browser_process->notification_ui_manager()->Add(notification, profile_);
143 }
144
145 base::string16 EolNotification::GetEolMessage() {
146 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) {
147 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY);
148 } else {
149 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL);
150 }
151 }
152
153 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698