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 | 30 |
31 class EolNotificationDelegate : public NotificationDelegate { | 31 class EolNotificationDelegate : public NotificationDelegate { |
32 public: | 32 public: |
33 explicit EolNotificationDelegate(Profile* profile); | 33 explicit EolNotificationDelegate(Profile* profile); |
34 | 34 |
35 private: | 35 private: |
36 // Buttons that appear in notifications. | |
37 enum EOL_Button { BUTTON_MORE_INFO, BUTTON_DISMISS }; | |
38 | |
36 ~EolNotificationDelegate() override; | 39 ~EolNotificationDelegate() override; |
37 | 40 |
38 // NotificationDelegate overrides: | 41 // NotificationDelegate overrides: |
39 void Close(bool by_user) override; | |
40 void ButtonClick(int button_index) override; | 42 void ButtonClick(int button_index) override; |
41 std::string id() const override; | 43 std::string id() const override; |
42 | 44 |
43 Profile* const profile_; | 45 Profile* const profile_; |
44 | 46 |
45 void OpenMoreInfoPage(); | 47 void OpenMoreInfoPage(); |
46 | 48 |
47 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate); | 49 DISALLOW_COPY_AND_ASSIGN(EolNotificationDelegate); |
48 }; | 50 }; |
49 | 51 |
50 EolNotificationDelegate::EolNotificationDelegate(Profile* profile) | 52 EolNotificationDelegate::EolNotificationDelegate(Profile* profile) |
51 : profile_(profile) {} | 53 : profile_(profile) {} |
52 | 54 |
53 EolNotificationDelegate::~EolNotificationDelegate() {} | 55 EolNotificationDelegate::~EolNotificationDelegate() {} |
54 | 56 |
55 void EolNotificationDelegate::Close(bool by_user) { | 57 void EolNotificationDelegate::ButtonClick(int button_index) { |
56 if (by_user) { | 58 switch (button_index) { |
xiyuan
2016/06/23 21:19:54
Should we close the notification when either of th
| |
57 // set dismiss pref. | 59 case BUTTON_MORE_INFO: |
58 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | 60 // show eol link |
61 OpenMoreInfoPage(); | |
62 break; | |
63 case BUTTON_DISMISS: | |
64 // set dismiss pref. | |
65 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | |
66 break; | |
59 } | 67 } |
60 } | 68 } |
61 | 69 |
62 void EolNotificationDelegate::ButtonClick(int button_index) { | |
63 // show eol link | |
64 OpenMoreInfoPage(); | |
65 } | |
66 | |
67 std::string EolNotificationDelegate::id() const { | 70 std::string EolNotificationDelegate::id() const { |
68 return kDelegateId; | 71 return kDelegateId; |
69 } | 72 } |
70 | 73 |
71 void EolNotificationDelegate::OpenMoreInfoPage() { | 74 void EolNotificationDelegate::OpenMoreInfoPage() { |
72 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL), | 75 chrome::NavigateParams params(profile_, GURL(chrome::kEolNotificationURL), |
73 ui::PAGE_TRANSITION_LINK); | 76 ui::PAGE_TRANSITION_LINK); |
74 params.disposition = NEW_FOREGROUND_TAB; | 77 params.disposition = NEW_FOREGROUND_TAB; |
75 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 78 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
76 chrome::Navigate(¶ms); | 79 chrome::Navigate(¶ms); |
(...skipping 10 matching lines...) Expand all Loading... | |
87 | 90 |
88 void EolNotification::CheckEolStatus() { | 91 void EolNotification::CheckEolStatus() { |
89 UpdateEngineClient* update_engine_client = | 92 UpdateEngineClient* update_engine_client = |
90 DBusThreadManager::Get()->GetUpdateEngineClient(); | 93 DBusThreadManager::Get()->GetUpdateEngineClient(); |
91 | 94 |
92 // Request the Eol Status. | 95 // Request the Eol Status. |
93 update_engine_client->GetEolStatus( | 96 update_engine_client->GetEolStatus( |
94 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr())); | 97 base::Bind(&EolNotification::OnEolStatus, weak_factory_.GetWeakPtr())); |
95 } | 98 } |
96 | 99 |
97 void EolNotification::OnEolStatus(int status) { | 100 void EolNotification::OnEolStatus(update_engine::EndOfLifeStatus status) { |
98 status_ = status; | 101 status_ = status; |
99 | 102 |
100 const int pre_eol_status = | 103 const int pre_eol_status = |
101 profile_->GetPrefs()->GetInteger(prefs::kEolStatus); | 104 profile_->GetPrefs()->GetInteger(prefs::kEolStatus); |
102 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_); | 105 profile_->GetPrefs()->SetInteger(prefs::kEolStatus, status_); |
103 | 106 |
104 if (status_ == update_engine::EndOfLifeStatus::kSupported) | 107 if (status_ == update_engine::EndOfLifeStatus::kSupported) |
105 return; | 108 return; |
106 | 109 |
107 if (pre_eol_status != status_) { | 110 if (pre_eol_status != status_) { |
108 // If Eol status has changed, we should reset | 111 // If Eol status has changed, we should reset |
109 // kEolNotificationDismissed and show notification. | 112 // kEolNotificationDismissed and show notification. |
110 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false); | 113 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, false); |
111 } | 114 } |
112 | 115 |
113 bool user_dismissed_eol_notification = | 116 bool user_dismissed_eol_notification = |
114 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed); | 117 profile_->GetPrefs()->GetBoolean(prefs::kEolNotificationDismissed); |
115 if (user_dismissed_eol_notification) | 118 if (user_dismissed_eol_notification) |
116 return; | 119 return; |
117 | 120 |
118 // When device is in Security-Only state, only show notification the first | 121 // When device is in Security-Only state, only show notification the first |
119 // time. | 122 // time. |
120 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) | 123 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) |
121 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); | 124 profile_->GetPrefs()->SetBoolean(prefs::kEolNotificationDismissed, true); |
122 | 125 |
123 Update(); | 126 Update(); |
124 } | 127 } |
125 | 128 |
126 void EolNotification::Update() { | 129 void EolNotification::Update() { |
127 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
128 message_center::RichNotificationData data; | 130 message_center::RichNotificationData data; |
129 data.buttons.push_back(message_center::ButtonInfo( | 131 data.buttons.push_back(message_center::ButtonInfo( |
130 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON))); | 132 l10n_util::GetStringUTF16(IDS_EOL_MORE_INFO_BUTTON))); |
133 data.buttons.push_back(message_center::ButtonInfo( | |
134 l10n_util::GetStringUTF16(IDS_EOL_DISMISS_BUTTON))); | |
131 | 135 |
132 Notification notification( | 136 Notification notification( |
133 message_center::NOTIFICATION_TYPE_SIMPLE, | 137 message_center::NOTIFICATION_TYPE_SIMPLE, |
134 base::string16(), // title | 138 base::string16(), // title |
135 // TODO(xiaoyinh): Update the Eol icon once it's ready. | 139 GetEolMessage(), gfx::Image(CreateVectorIcon(gfx::VectorIconId::EOL, |
136 GetEolMessage(), bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 140 gfx::kPlaceholderColor)), |
137 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 141 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
138 kEolNotificationId), | 142 kEolNotificationId), |
139 base::string16(), // display_source | 143 base::string16(), // display_source |
140 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_)); | 144 GURL(), kEolNotificationId, data, new EolNotificationDelegate(profile_)); |
141 g_browser_process->notification_ui_manager()->Add(notification, profile_); | 145 g_browser_process->notification_ui_manager()->Add(notification, profile_); |
142 } | 146 } |
143 | 147 |
144 base::string16 EolNotification::GetEolMessage() { | 148 base::string16 EolNotification::GetEolMessage() { |
145 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { | 149 if (status_ == update_engine::EndOfLifeStatus::kSecurityOnly) { |
146 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY); | 150 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_SECURITY_ONLY); |
147 } else { | 151 } else { |
148 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL); | 152 return l10n_util::GetStringUTF16(IDS_EOL_NOTIFICATION_EOL); |
149 } | 153 } |
150 } | 154 } |
151 | 155 |
152 } // namespace chromeos | 156 } // namespace chromeos |
OLD | NEW |