OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/eol_notification.h" | 5 #include "chrome/browser/chromeos/eol_notification.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/notifications/notification.h" | 8 #include "chrome/browser/notifications/notification.h" |
9 #include "chrome/browser/notifications/notification_ui_manager.h" | 9 #include "chrome/browser/notifications/notification_ui_manager.h" |
10 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
11 #include "chrome/browser/ui/browser_navigator_params.h" | 11 #include "chrome/browser/ui/browser_navigator_params.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/dbus/update_engine_client.h" | 16 #include "chromeos/dbus/update_engine_client.h" |
17 #include "components/prefs/pref_service.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" | 18 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/gfx/color_palette.h" |
| 20 #include "ui/gfx/paint_vector_icon.h" |
| 21 #include "ui/gfx/vector_icons_public.h" |
22 | 22 |
23 using message_center::MessageCenter; | 23 using message_center::MessageCenter; |
24 | 24 |
25 namespace chromeos { | 25 namespace chromeos { |
26 namespace { | 26 namespace { |
27 | 27 |
28 const char kEolNotificationId[] = "eol"; | 28 const char kEolNotificationId[] = "eol"; |
29 const char kDelegateId[] = "eol_delegate"; | 29 const char kDelegateId[] = "eol_delegate"; |
| 30 const SkColor kButtonIconColor = SkColorSetRGB(150, 150, 152); |
| 31 const SkColor kNotificationIconColor = SkColorSetRGB(219, 68, 55); |
30 | 32 |
31 class EolNotificationDelegate : public NotificationDelegate { | 33 class EolNotificationDelegate : public NotificationDelegate { |
32 public: | 34 public: |
33 explicit EolNotificationDelegate(Profile* profile); | 35 explicit EolNotificationDelegate(Profile* profile); |
34 | 36 |
35 private: | 37 private: |
| 38 // Buttons that appear in notifications. |
| 39 enum EOL_Button { BUTTON_MORE_INFO = 0, BUTTON_DISMISS }; |
| 40 |
36 ~EolNotificationDelegate() override; | 41 ~EolNotificationDelegate() override; |
37 | 42 |
38 // NotificationDelegate overrides: | 43 // NotificationDelegate overrides: |
39 void Close(bool by_user) override; | |
40 void ButtonClick(int button_index) override; | 44 void ButtonClick(int button_index) override; |
41 std::string id() const override; | 45 std::string id() const override; |
42 | 46 |
43 Profile* const profile_; | 47 Profile* const profile_; |
44 | 48 |
45 void OpenMoreInfoPage(); | 49 void OpenMoreInfoPage(); |
| 50 void CancelNotification(); |
46 | 51 |
47 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate); | 52 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate); |
48 }; | 53 }; |
49 | 54 |
50 EolNotificationDelegate::EolNotificationDelegate(Profile* profile) | 55 EolNotificationDelegate::EolNotificationDelegate(Profile* profile) |
51 : profile_(profile) {} | 56 : profile_(profile) {} |
52 | 57 |
53 EolNotificationDelegate::~EolNotificationDelegate() {} | 58 EolNotificationDelegate::~EolNotificationDelegate() {} |
54 | 59 |
55 void EolNotificationDelegate::Close(bool by_user) { | 60 void EolNotificationDelegate::ButtonClick(int button_index) { |
56 if (by_user) { | 61 switch (button_index) { |
57 // set dismiss pref. | 62 case BUTTON_MORE_INFO: |
58 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | 63 // show eol link |
| 64 OpenMoreInfoPage(); |
| 65 break; |
| 66 case BUTTON_DISMISS: |
| 67 // set dismiss pref. |
| 68 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); |
| 69 break; |
| 70 default: |
| 71 NOTREACHED(); |
59 } | 72 } |
60 } | 73 CancelNotification(); |
61 | |
62 void EolNotificationDelegate::ButtonClick(int button_index) { | |
63 // show eol link | |
64 OpenMoreInfoPage(); | |
65 } | 74 } |
66 | 75 |
67 std::string EolNotificationDelegate::id() const { | 76 std::string EolNotificationDelegate::id() const { |
68 return kDelegateId; | 77 return kDelegateId; |
69 } | 78 } |
70 | 79 |
71 void EolNotificationDelegate::OpenMoreInfoPage() { | 80 void EolNotificationDelegate::OpenMoreInfoPage() { |
72 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL), | 81 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL), |
73 ui::PAGE_TRANSITION_LINK); | 82 ui::PAGE_TRANSITION_LINK); |
74 params.disposition = NEW_FOREGROUND_TAB; | 83 params.disposition = NEW_FOREGROUND_TAB; |
75 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 84 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
76 chrome::Navigate(¶ms); | 85 chrome::Navigate(¶ms); |
77 } | 86 } |
78 | 87 |
| 88 void EolNotificationDelegate::CancelNotification() { |
| 89 // Clean up the notification |
| 90 g_browser_process->notification_ui_manager()->CancelById( |
| 91 id(), NotificationUIManager::GetProfileID(profile_)); |
| 92 } |
| 93 |
79 } // namespace | 94 } // namespace |
80 | 95 |
81 EolNotification::EolNotification(Profile* profile) | 96 EolNotification::EolNotification(Profile* profile) |
82 : profile_(profile), | 97 : profile_(profile), |
83 status_(update_engine::EndOfLifeStatus::kSupported), | 98 status_(update_engine::EndOfLifeStatus::kSupported), |
84 weak_factory_(this) {} | 99 weak_factory_(this) {} |
85 | 100 |
86 EolNotification::~EolNotification() {} | 101 EolNotification::~EolNotification() {} |
87 | 102 |
88 void EolNotification::CheckEolStatus() { | 103 void EolNotification::CheckEolStatus() { |
89 UpdateEngineClient* update_engine_client = | 104 UpdateEngineClient* update_engine_client = |
90 DBusThreadManager::Get()->GetUpdateEngineClient(); | 105 DBusThreadManager::Get()->GetUpdateEngineClient(); |
91 | 106 |
92 // Request the Eol Status. | 107 // Request the Eol Status. |
93 update_engine_client->GetEolStatus( | 108 update_engine_client->GetEolStatus( |
94 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr())); | 109 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr())); |
95 } | 110 } |
96 | 111 |
97 void EolNotification::OnEolStatus(int status) { | 112 void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) { |
98 status_ = status; | 113 status_ = status; |
99 | 114 |
100 const int pre_eol_status = | 115 const int pre_eol_status = |
101 profile_->GetPrefs()->GetInteger(prefs::kEolStatus); | 116 profile_->GetPrefs()->GetInteger(prefs::kEolStatus); |
102 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_); | 117 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_); |
103 | 118 |
104 if (status_ == update_engine::EndOfLifeStatus::kSupported) | 119 if (status_ == update_engine::EndOfLifeStatus::kSupported) |
105 return; | 120 return; |
106 | 121 |
107 if (pre_eol_status != status_) { | 122 if (pre_eol_status != status_) { |
108 // If Eol status has changed, we should reset | 123 // If Eol status has changed, we should reset |
109 // kEolNotificationDismissed and show notification. | 124 // kEolNotificationDismissed and show notification. |
110 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false); | 125 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false); |
111 } | 126 } |
112 | 127 |
113 bool user_dismissed_eol_notification = | 128 bool user_dismissed_eol_notification = |
114 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed); | 129 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed); |
115 if (user_dismissed_eol_notification) | 130 if (user_dismissed_eol_notification) |
116 return; | 131 return; |
117 | 132 |
118 // When device is in Security-Only state, only show notification the first | 133 // When device is in Security-Only state, only show notification the first |
119 // time. | 134 // time. |
120 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) | 135 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) |
121 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | 136 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); |
122 | 137 |
123 Update(); | 138 Update(); |
124 } | 139 } |
125 | 140 |
126 void EolNotification::Update() { | 141 void EolNotification::Update() { |
127 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 142 message_center::ButtonInfo learn_more( |
| 143 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON)); |
| 144 learn_more.icon = gfx::Image( |
| 145 CreateVectorIcon(gfx::VectorIconId::INFO_OUTLINE, kButtonIconColor)); |
| 146 message_center::ButtonInfo dismiss( |
| 147 l10n_util::GetStringUTF16(IDS_EOL_DISMISS_BUTTON)); |
| 148 dismiss.icon = gfx::Image( |
| 149 CreateVectorIcon(gfx::VectorIconId::NOTIFICATIONS_OFF, kButtonIconColor)); |
| 150 |
128 message_center::RichNotificationData data; | 151 message_center::RichNotificationData data; |
129 data.buttons.push_back(message_center::ButtonInfo( | 152 data.buttons.push_back(learn_more); |
130 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON))); | 153 data.buttons.push_back(dismiss); |
131 | 154 |
132 Notification notification( | 155 Notification notification( |
133 message_center::NOTIFICATION_TYPE_SIMPLE, | 156 message_center::NOTIFICATION_TYPE_SIMPLE, |
134 base::string16(), // title | 157 l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_TITLE), GetEolMessage(), |
135 // TODO(xiaoyinh): Update the Eol icon once it's ready. | 158 gfx::Image( |
136 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 159 CreateVectorIcon(gfx::VectorIconId::EOL, kNotificationIconColor)), |
137 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 160 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
138 kEolNotificationId), | 161 kEolNotificationId), |
139 base::string16(), // display_source | 162 base::string16(), // display_source |
140 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_)); | 163 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_)); |
141 g_browser_process->notification_ui_manager()->Add(notification, profile_); | 164 g_browser_process->notification_ui_manager()->Add(notification, profile_); |
142 } | 165 } |
143 | 166 |
144 base::string16 EolNotification::GetEolMessage() { | 167 base::string16 EolNotification::GetEolMessage() { |
145 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { | 168 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { |
146 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY); | 169 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY); |
147 } else { | 170 } else { |
148 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL); | 171 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL); |
149 } | 172 } |
150 } | 173 } |
151 | 174 |
152 } // namespace chromeos | 175 } // namespace chromeos |
OLD | NEW |