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

Side by Side Diff: chrome/browser/chromeos/policy/consumer_management_notifier.cc

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

Powered by Google App Engine
This is Rietveld 408576698