| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/policy/consumer_management_notifier.h" | 5 #include "chrome/browser/chromeos/policy/consumer_management_notifier.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "ui/base/window_open_disposition.h" | 27 #include "ui/base/window_open_disposition.h" |
| 28 #include "ui/message_center/notification_types.h" | 28 #include "ui/message_center/notification_types.h" |
| 29 #include "ui/message_center/notifier_settings.h" | 29 #include "ui/message_center/notifier_settings.h" |
| 30 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Desktop notification constants. | 34 // Desktop notification constants. |
| 35 const char kEnrollmentNotificationId[] = "consumer_management.enroll"; | 35 const char kEnrollmentNotificationId[] = "consumer_management.enroll"; |
| 36 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll"; | 36 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll"; |
| 37 const char kUnenrollmentNotificationId[] = "consumer_management.unenroll"; |
| 38 const char kUnenrollmentNotificationUrl[] = |
| 39 "chrome://consumer-management/unenroll"; |
| 37 | 40 |
| 38 // The path to the consumer management enrollment/unenrollment confirmation | 41 // The path to the consumer management enrollment/unenrollment confirmation |
| 39 // overlay, relative to the settings page URL. | 42 // overlay, relative to the settings page URL. |
| 40 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; | 43 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; |
| 41 | 44 |
| 42 class DesktopNotificationDelegate : public NotificationDelegate { | 45 class DesktopNotificationDelegate : public NotificationDelegate { |
| 43 public: | 46 public: |
| 44 // |button_click_callback| is called when the button in the notification is | 47 // |button_click_callback| is called when the button in the notification is |
| 45 // clicked. | 48 // clicked. |
| 46 DesktopNotificationDelegate(const std::string& id, | 49 DesktopNotificationDelegate(const std::string& id, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 void ConsumerManagementNotifier::Shutdown() { | 99 void ConsumerManagementNotifier::Shutdown() { |
| 97 consumer_management_service_->RemoveObserver(this); | 100 consumer_management_service_->RemoveObserver(this); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() { | 103 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() { |
| 101 const ConsumerManagementStage stage = | 104 const ConsumerManagementStage stage = |
| 102 consumer_management_service_->GetStage(); | 105 consumer_management_service_->GetStage(); |
| 103 if (stage.HasPendingNotification()) { | 106 if (stage.HasPendingNotification()) { |
| 104 // Reset the stage so that we won't show the same notification, again. | 107 // Reset the stage so that we won't show the same notification, again. |
| 105 consumer_management_service_->SetStage(ConsumerManagementStage::None()); | 108 consumer_management_service_->SetStage(ConsumerManagementStage::None()); |
| 106 ShowDesktopNotification(stage); | 109 ShowNotification(stage); |
| 110 } |
| 111 } |
| 112 |
| 113 void ConsumerManagementNotifier::ShowNotification( |
| 114 const ConsumerManagementStage& stage) { |
| 115 if (stage.HasEnrollmentSucceeded()) { |
| 116 ShowDesktopNotification( |
| 117 kEnrollmentNotificationId, |
| 118 kEnrollmentNotificationUrl, |
| 119 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE, |
| 120 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY, |
| 121 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON, |
| 122 base::Bind(&ConsumerManagementNotifier::OpenSettingsPage, |
| 123 weak_ptr_factory_.GetWeakPtr())); |
| 124 } else if (stage.HasEnrollmentFailed()) { |
| 125 ShowDesktopNotification( |
| 126 kEnrollmentNotificationId, |
| 127 kEnrollmentNotificationUrl, |
| 128 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE, |
| 129 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY, |
| 130 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON, |
| 131 base::Bind(&ConsumerManagementNotifier::TryAgain, |
| 132 weak_ptr_factory_.GetWeakPtr())); |
| 133 } else if (stage.HasUnenrollmentSucceeded()) { |
| 134 ShowDesktopNotification( |
| 135 kUnenrollmentNotificationId, |
| 136 kUnenrollmentNotificationUrl, |
| 137 IDS_CONSUMER_MANAGEMENT_UNENROLLMENT_NOTIFICATION_TITLE, |
| 138 IDS_CONSUMER_MANAGEMENT_UNENROLLMENT_NOTIFICATION_BODY, |
| 139 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON, |
| 140 base::Bind(&ConsumerManagementNotifier::OpenSettingsPage, |
| 141 weak_ptr_factory_.GetWeakPtr())); |
| 142 } else if (stage.HasUnenrollmentFailed()) { |
| 143 ShowDesktopNotification( |
| 144 kUnenrollmentNotificationId, |
| 145 kUnenrollmentNotificationUrl, |
| 146 IDS_CONSUMER_MANAGEMENT_UNENROLLMENT_FAILURE_NOTIFICATION_TITLE, |
| 147 IDS_CONSUMER_MANAGEMENT_UNENROLLMENT_FAILURE_NOTIFICATION_BODY, |
| 148 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON, |
| 149 base::Bind(&ConsumerManagementNotifier::TryAgain, |
| 150 weak_ptr_factory_.GetWeakPtr())); |
| 151 } else { |
| 152 NOTREACHED(); |
| 107 } | 153 } |
| 108 } | 154 } |
| 109 | 155 |
| 110 void ConsumerManagementNotifier::ShowDesktopNotification( | 156 void ConsumerManagementNotifier::ShowDesktopNotification( |
| 111 const ConsumerManagementStage& stage) { | 157 const std::string& notification_id, |
| 112 base::string16 title; | 158 const std::string& notification_url, |
| 113 base::string16 body; | 159 int title_message_id, |
| 114 base::string16 button_label; | 160 int body_message_id, |
| 115 base::Closure button_click_callback; | 161 int button_label_message_id, |
| 162 const base::Closure& button_click_callback) { |
| 163 message_center::RichNotificationData optional_field; |
| 164 optional_field.buttons.push_back(message_center::ButtonInfo( |
| 165 l10n_util::GetStringUTF16(button_label_message_id))); |
| 116 | 166 |
| 117 if (stage.HasEnrollmentSucceeded()) { | |
| 118 title = l10n_util::GetStringUTF16( | |
| 119 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE); | |
| 120 body = l10n_util::GetStringUTF16( | |
| 121 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY); | |
| 122 button_label = l10n_util::GetStringUTF16( | |
| 123 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON); | |
| 124 button_click_callback = base::Bind( | |
| 125 &ConsumerManagementNotifier::OpenSettingsPage, | |
| 126 weak_ptr_factory_.GetWeakPtr()); | |
| 127 } else if (stage.HasEnrollmentFailed()) { | |
| 128 title = l10n_util::GetStringUTF16( | |
| 129 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE); | |
| 130 body = l10n_util::GetStringUTF16( | |
| 131 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY); | |
| 132 button_label = l10n_util::GetStringUTF16( | |
| 133 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON); | |
| 134 button_click_callback = base::Bind( | |
| 135 &ConsumerManagementNotifier::TryEnrollmentAgain, | |
| 136 weak_ptr_factory_.GetWeakPtr()); | |
| 137 } else { | |
| 138 NOTREACHED(); | |
| 139 return; | |
| 140 } | |
| 141 | |
| 142 message_center::RichNotificationData optional_field; | |
| 143 optional_field.buttons.push_back(message_center::ButtonInfo(button_label)); | |
| 144 Notification notification( | 167 Notification notification( |
| 145 message_center::NOTIFICATION_TYPE_SIMPLE, | 168 message_center::NOTIFICATION_TYPE_SIMPLE, |
| 146 GURL(kEnrollmentNotificationUrl), | 169 GURL(notification_url), |
| 147 title, | 170 l10n_util::GetStringUTF16(title_message_id), |
| 148 body, | 171 l10n_util::GetStringUTF16(body_message_id), |
| 149 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 172 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 150 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), | 173 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), |
| 151 blink::WebTextDirectionDefault, | 174 blink::WebTextDirectionDefault, |
| 152 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 175 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| 153 kEnrollmentNotificationId), | 176 notification_id), |
| 154 base::string16(), // display_source | 177 base::string16(), // display_source |
| 155 base::UTF8ToUTF16(kEnrollmentNotificationId), | 178 base::UTF8ToUTF16(notification_id), |
| 156 optional_field, | 179 optional_field, |
| 157 new DesktopNotificationDelegate(kEnrollmentNotificationId, | 180 new DesktopNotificationDelegate(notification_id, button_click_callback)); |
| 158 button_click_callback)); | 181 |
| 159 notification.SetSystemPriority(); | 182 notification.SetSystemPriority(); |
| 160 g_browser_process->notification_ui_manager()->Add(notification, profile_); | 183 g_browser_process->notification_ui_manager()->Add(notification, profile_); |
| 161 } | 184 } |
| 162 | 185 |
| 163 void ConsumerManagementNotifier::OpenSettingsPage() const { | 186 void ConsumerManagementNotifier::OpenSettingsPage() const { |
| 164 const GURL url(chrome::kChromeUISettingsURL); | 187 const GURL url(chrome::kChromeUISettingsURL); |
| 165 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); | 188 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); |
| 166 params.disposition = NEW_FOREGROUND_TAB; | 189 params.disposition = NEW_FOREGROUND_TAB; |
| 167 chrome::Navigate(¶ms); | 190 chrome::Navigate(¶ms); |
| 168 } | 191 } |
| 169 | 192 |
| 170 void ConsumerManagementNotifier::TryEnrollmentAgain() const { | 193 void ConsumerManagementNotifier::TryAgain() const { |
| 171 const GURL base_url(chrome::kChromeUISettingsURL); | 194 const GURL base_url(chrome::kChromeUISettingsURL); |
| 172 const GURL url = base_url.Resolve(kConsumerManagementOverlay); | 195 const GURL url = base_url.Resolve(kConsumerManagementOverlay); |
| 173 | 196 |
| 174 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); | 197 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); |
| 175 params.disposition = NEW_FOREGROUND_TAB; | 198 params.disposition = NEW_FOREGROUND_TAB; |
| 176 chrome::Navigate(¶ms); | 199 chrome::Navigate(¶ms); |
| 177 } | 200 } |
| 178 | 201 |
| 179 } // namespace policy | 202 } // namespace policy |
| OLD | NEW |