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

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

Issue 814123006: Revert of Implemented consumer management unenrollment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dcpm
Patch Set: Created 5 years, 11 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
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
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";
40 37
41 // The path to the consumer management enrollment/unenrollment confirmation 38 // The path to the consumer management enrollment/unenrollment confirmation
42 // overlay, relative to the settings page URL. 39 // overlay, relative to the settings page URL.
43 const char kConsumerManagementOverlay[] = "consumer-management-overlay"; 40 const char kConsumerManagementOverlay[] = "consumer-management-overlay";
44 41
45 class DesktopNotificationDelegate : public NotificationDelegate { 42 class DesktopNotificationDelegate : public NotificationDelegate {
46 public: 43 public:
47 // |button_click_callback| is called when the button in the notification is 44 // |button_click_callback| is called when the button in the notification is
48 // clicked. 45 // clicked.
49 DesktopNotificationDelegate(const std::string& id, 46 DesktopNotificationDelegate(const std::string& id,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 void ConsumerManagementNotifier::Shutdown() { 96 void ConsumerManagementNotifier::Shutdown() {
100 consumer_management_service_->RemoveObserver(this); 97 consumer_management_service_->RemoveObserver(this);
101 } 98 }
102 99
103 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() { 100 void ConsumerManagementNotifier::OnConsumerManagementStatusChanged() {
104 const ConsumerManagementStage stage = 101 const ConsumerManagementStage stage =
105 consumer_management_service_->GetStage(); 102 consumer_management_service_->GetStage();
106 if (stage.HasPendingNotification()) { 103 if (stage.HasPendingNotification()) {
107 // Reset the stage so that we won't show the same notification, again. 104 // Reset the stage so that we won't show the same notification, again.
108 consumer_management_service_->SetStage(ConsumerManagementStage::None()); 105 consumer_management_service_->SetStage(ConsumerManagementStage::None());
109 ShowNotification(stage); 106 ShowDesktopNotification(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();
153 } 107 }
154 } 108 }
155 109
156 void ConsumerManagementNotifier::ShowDesktopNotification( 110 void ConsumerManagementNotifier::ShowDesktopNotification(
157 const std::string& notification_id, 111 const ConsumerManagementStage& stage) {
158 const std::string& notification_url, 112 base::string16 title;
159 int title_message_id, 113 base::string16 body;
160 int body_message_id, 114 base::string16 button_label;
161 int button_label_message_id, 115 base::Closure button_click_callback;
162 const base::Closure& button_click_callback) { 116
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
163 message_center::RichNotificationData optional_field; 142 message_center::RichNotificationData optional_field;
164 optional_field.buttons.push_back(message_center::ButtonInfo( 143 optional_field.buttons.push_back(message_center::ButtonInfo(button_label));
165 l10n_util::GetStringUTF16(button_label_message_id)));
166
167 Notification notification( 144 Notification notification(
168 message_center::NOTIFICATION_TYPE_SIMPLE, 145 message_center::NOTIFICATION_TYPE_SIMPLE,
169 GURL(notification_url), 146 GURL(kEnrollmentNotificationUrl),
170 l10n_util::GetStringUTF16(title_message_id), 147 title,
171 l10n_util::GetStringUTF16(body_message_id), 148 body,
172 ui::ResourceBundle::GetSharedInstance().GetImageNamed( 149 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
173 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), 150 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON),
174 blink::WebTextDirectionDefault, 151 blink::WebTextDirectionDefault,
175 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, 152 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
176 notification_id), 153 kEnrollmentNotificationId),
177 base::string16(), // display_source 154 base::string16(), // display_source
178 base::UTF8ToUTF16(notification_id), 155 base::UTF8ToUTF16(kEnrollmentNotificationId),
179 optional_field, 156 optional_field,
180 new DesktopNotificationDelegate(notification_id, button_click_callback)); 157 new DesktopNotificationDelegate(kEnrollmentNotificationId,
181 158 button_click_callback));
182 notification.SetSystemPriority(); 159 notification.SetSystemPriority();
183 g_browser_process->notification_ui_manager()->Add(notification, profile_); 160 g_browser_process->notification_ui_manager()->Add(notification, profile_);
184 } 161 }
185 162
186 void ConsumerManagementNotifier::OpenSettingsPage() const { 163 void ConsumerManagementNotifier::OpenSettingsPage() const {
187 const GURL url(chrome::kChromeUISettingsURL); 164 const GURL url(chrome::kChromeUISettingsURL);
188 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); 165 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK);
189 params.disposition = NEW_FOREGROUND_TAB; 166 params.disposition = NEW_FOREGROUND_TAB;
190 chrome::Navigate(&params); 167 chrome::Navigate(&params);
191 } 168 }
192 169
193 void ConsumerManagementNotifier::TryAgain() const { 170 void ConsumerManagementNotifier::TryEnrollmentAgain() const {
194 const GURL base_url(chrome::kChromeUISettingsURL); 171 const GURL base_url(chrome::kChromeUISettingsURL);
195 const GURL url = base_url.Resolve(kConsumerManagementOverlay); 172 const GURL url = base_url.Resolve(kConsumerManagementOverlay);
196 173
197 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK); 174 chrome::NavigateParams params(profile_, url, ui::PAGE_TRANSITION_LINK);
198 params.disposition = NEW_FOREGROUND_TAB; 175 params.disposition = NEW_FOREGROUND_TAB;
199 chrome::Navigate(&params); 176 chrome::Navigate(&params);
200 } 177 }
201 178
202 } // namespace policy 179 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698