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

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

Issue 468873002: Show a desktop notification when the enrollment is completed or failed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix broken build and un-inline virtual functions. Created 6 years, 3 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 | Annotate | Revision Log
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_service.h" 5 #include "chrome/browser/chromeos/policy/consumer_management_service.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/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/prefs/pref_registry_simple.h" 12 #include "base/prefs/pref_registry_simple.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/browser_process_platform_part.h" 17 #include "chrome/browser/browser_process_platform_part.h"
17 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
19 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h"
20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
21 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chrome/browser/notifications/notification.h"
24 #include "chrome/browser/notifications/notification_ui_manager.h"
22 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
24 #include "chrome/browser/signin/signin_manager_factory.h" 27 #include "chrome/browser/signin/signin_manager_factory.h"
28 #include "chrome/browser/ui/browser_navigator.h"
25 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "chrome/common/url_constants.h"
26 #include "chromeos/dbus/cryptohome/rpc.pb.h" 31 #include "chromeos/dbus/cryptohome/rpc.pb.h"
27 #include "chromeos/dbus/cryptohome_client.h" 32 #include "chromeos/dbus/cryptohome_client.h"
28 #include "components/policy/core/common/cloud/cloud_policy_constants.h" 33 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
29 #include "components/signin/core/browser/profile_oauth2_token_service.h" 34 #include "components/signin/core/browser/profile_oauth2_token_service.h"
30 #include "components/signin/core/browser/signin_manager_base.h" 35 #include "components/signin/core/browser/signin_manager_base.h"
31 #include "components/user_manager/user_manager.h" 36 #include "components/user_manager/user_manager.h"
32 #include "content/public/browser/notification_details.h" 37 #include "content/public/browser/notification_details.h"
33 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
40 #include "content/public/common/page_transition_types.h"
35 #include "google_apis/gaia/gaia_constants.h" 41 #include "google_apis/gaia/gaia_constants.h"
36 #include "google_apis/gaia/google_service_auth_error.h" 42 #include "google_apis/gaia/google_service_auth_error.h"
43 #include "grit/generated_resources.h"
44 #include "grit/theme_resources.h"
37 #include "policy/proto/device_management_backend.pb.h" 45 #include "policy/proto/device_management_backend.pb.h"
46 #include "third_party/WebKit/public/web/WebTextDirection.h"
47 #include "ui/base/l10n/l10n_util.h"
48 #include "ui/base/resource/resource_bundle.h"
49 #include "ui/base/window_open_disposition.h"
50 #include "ui/message_center/notification.h"
51 #include "ui/message_center/notification_types.h"
52 #include "ui/message_center/notifier_settings.h"
53 #include "url/gurl.h"
38 54
39 namespace { 55 namespace {
40 56
41 const char* kAttributeOwnerId = "consumer_management.owner_id"; 57 // Boot atttributes ID.
58 const char kAttributeOwnerId[] = "consumer_management.owner_id";
59
60 // Desktop notification constants.
61 const char kEnrollmentNotificationId[] = "consumer_management.enroll";
62 const char kEnrollmentNotificationUrl[] = "chrome://consumer-management/enroll";
63
64 // The path to the consumer management enrollment/unenrollment confirmation
65 // overlay, relative to the settings page URL.
66 const char kConsumerManagementOverlay[] = "consumer-management-overlay";
67
68 // Returns the account ID signed in to |profile|.
69 const std::string& GetAccountIdFromProfile(Profile* profile) {
70 return SigninManagerFactory::GetForProfile(profile)->
71 GetAuthenticatedAccountId();
72 }
73
74 class DesktopNotificationDelegate : public NotificationDelegate {
75 public:
76 // |button_click_callback| is called when the button in the notification is
77 // clicked.
78 DesktopNotificationDelegate(const std::string& id,
79 const base::Closure& button_click_callback);
80
81 // NotificationDelegate:
82 virtual std::string id() const OVERRIDE;
83 virtual content::WebContents* GetWebContents() const OVERRIDE;
84 virtual void Display() OVERRIDE;
85 virtual void ButtonClick(int button_index) OVERRIDE;
86 virtual void Error() OVERRIDE;
87 virtual void Close(bool by_user) OVERRIDE;
88 virtual void Click() OVERRIDE;
89
90 private:
91 virtual ~DesktopNotificationDelegate();
92
93 std::string id_;
94 base::Closure button_click_callback_;
95
96 DISALLOW_COPY_AND_ASSIGN(DesktopNotificationDelegate);
97 };
98
99 DesktopNotificationDelegate::DesktopNotificationDelegate(
100 const std::string& id,
101 const base::Closure& button_click_callback)
102 : id_(id), button_click_callback_(button_click_callback) {
103 }
104
105 DesktopNotificationDelegate::~DesktopNotificationDelegate() {
106 }
107
108 std::string DesktopNotificationDelegate::id() const {
109 return id_;
110 }
111
112 content::WebContents* DesktopNotificationDelegate::GetWebContents() const {
113 return NULL;
114 }
115
116 void DesktopNotificationDelegate::Display() {
117 }
118
119 void DesktopNotificationDelegate::ButtonClick(int button_index) {
120 button_click_callback_.Run();
121 }
122
123 void DesktopNotificationDelegate::Error() {
124 }
125
126 void DesktopNotificationDelegate::Close(bool by_user) {
127 }
128
129 void DesktopNotificationDelegate::Click() {
130 }
42 131
43 } // namespace 132 } // namespace
44 133
45 namespace policy { 134 namespace policy {
46 135
47 ConsumerManagementService::ConsumerManagementService( 136 ConsumerManagementService::ConsumerManagementService(
48 chromeos::CryptohomeClient* client) 137 chromeos::CryptohomeClient* client)
49 : Consumer("consumer_management_service"), 138 : Consumer("consumer_management_service"),
50 client_(client), 139 client_(client),
51 enrolling_token_service_(NULL), 140 enrolling_profile_(NULL),
52 weak_ptr_factory_(this) { 141 weak_ptr_factory_(this) {
53 registrar_.Add(this, 142 registrar_.Add(this,
54 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 143 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
55 content::NotificationService::AllSources()); 144 content::NotificationService::AllSources());
56 } 145 }
57 146
58 ConsumerManagementService::~ConsumerManagementService() { 147 ConsumerManagementService::~ConsumerManagementService() {
59 registrar_.Remove(this, 148 registrar_.Remove(this,
60 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, 149 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
61 content::NotificationService::AllSources()); 150 content::NotificationService::AllSources());
62 if (enrolling_token_service_) 151 if (enrolling_profile_) {
63 enrolling_token_service_->RemoveObserver(this); 152 ProfileOAuth2TokenServiceFactory::GetForProfile(enrolling_profile_)->
153 RemoveObserver(this);
154 }
64 } 155 }
65 156
66 // static 157 // static
67 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) { 158 void ConsumerManagementService::RegisterPrefs(PrefRegistrySimple* registry) {
68 registry->RegisterIntegerPref( 159 registry->RegisterIntegerPref(
69 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE); 160 prefs::kConsumerManagementEnrollmentState, ENROLLMENT_NONE);
70 } 161 }
71 162
72 ConsumerManagementService::ConsumerEnrollmentState 163 ConsumerManagementService::ConsumerEnrollmentState
73 ConsumerManagementService::GetEnrollmentState() const { 164 ConsumerManagementService::GetEnrollmentState() const {
(...skipping 15 matching lines...) Expand all
89 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) { 180 void ConsumerManagementService::GetOwner(const GetOwnerCallback& callback) {
90 cryptohome::GetBootAttributeRequest request; 181 cryptohome::GetBootAttributeRequest request;
91 request.set_name(kAttributeOwnerId); 182 request.set_name(kAttributeOwnerId);
92 client_->GetBootAttribute( 183 client_->GetBootAttribute(
93 request, 184 request,
94 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone, 185 base::Bind(&ConsumerManagementService::OnGetBootAttributeDone,
95 weak_ptr_factory_.GetWeakPtr(), 186 weak_ptr_factory_.GetWeakPtr(),
96 callback)); 187 callback));
97 } 188 }
98 189
99 void ConsumerManagementService::OnGetBootAttributeDone(
100 const GetOwnerCallback& callback,
101 chromeos::DBusMethodCallStatus call_status,
102 bool dbus_success,
103 const cryptohome::BaseReply& reply) {
104 if (!dbus_success || reply.error() != 0) {
105 LOG(ERROR) << "Failed to get the owner info from boot lockbox.";
106 callback.Run("");
107 return;
108 }
109
110 callback.Run(
111 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value());
112 }
113
114 void ConsumerManagementService::SetOwner(const std::string& user_id, 190 void ConsumerManagementService::SetOwner(const std::string& user_id,
115 const SetOwnerCallback& callback) { 191 const SetOwnerCallback& callback) {
116 cryptohome::SetBootAttributeRequest request; 192 cryptohome::SetBootAttributeRequest request;
117 request.set_name(kAttributeOwnerId); 193 request.set_name(kAttributeOwnerId);
118 request.set_value(user_id.data(), user_id.size()); 194 request.set_value(user_id.data(), user_id.size());
119 client_->SetBootAttribute( 195 client_->SetBootAttribute(
120 request, 196 request,
121 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone, 197 base::Bind(&ConsumerManagementService::OnSetBootAttributeDone,
122 weak_ptr_factory_.GetWeakPtr(), 198 weak_ptr_factory_.GetWeakPtr(),
123 callback)); 199 callback));
124 } 200 }
125 201
126 void ConsumerManagementService::OnSetBootAttributeDone(
127 const SetOwnerCallback& callback,
128 chromeos::DBusMethodCallStatus call_status,
129 bool dbus_success,
130 const cryptohome::BaseReply& reply) {
131 if (!dbus_success || reply.error() != 0) {
132 LOG(ERROR) << "Failed to set owner info in boot lockbox.";
133 callback.Run(false);
134 return;
135 }
136
137 cryptohome::FlushAndSignBootAttributesRequest request;
138 client_->FlushAndSignBootAttributes(
139 request,
140 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone,
141 weak_ptr_factory_.GetWeakPtr(),
142 callback));
143 }
144
145 void ConsumerManagementService::OnFlushAndSignBootAttributesDone(
146 const SetOwnerCallback& callback,
147 chromeos::DBusMethodCallStatus call_status,
148 bool dbus_success,
149 const cryptohome::BaseReply& reply) {
150 if (!dbus_success || reply.error() != 0) {
151 LOG(ERROR) << "Failed to flush and sign boot lockbox.";
152 callback.Run(false);
153 return;
154 }
155
156 callback.Run(true);
157 }
158
159 void ConsumerManagementService::Observe( 202 void ConsumerManagementService::Observe(
160 int type, 203 int type,
161 const content::NotificationSource& source, 204 const content::NotificationSource& source,
162 const content::NotificationDetails& details) { 205 const content::NotificationDetails& details) {
163 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) { 206 if (type != chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED) {
164 NOTREACHED() << "Unexpected notification " << type; 207 NOTREACHED() << "Unexpected notification " << type;
165 return; 208 return;
166 } 209 }
167 210
168 Profile* profile = content::Details<Profile>(details).ptr(); 211 Profile* profile = content::Details<Profile>(details).ptr();
169 if (chromeos::ProfileHelper::IsOwnerProfile(profile)) 212 if (chromeos::ProfileHelper::IsOwnerProfile(profile))
170 OnOwnerSignin(profile); 213 OnOwnerSignin(profile);
171 } 214 }
172 215
173 void ConsumerManagementService::OnRefreshTokenAvailable( 216 void ConsumerManagementService::OnRefreshTokenAvailable(
174 const std::string& account_id) { 217 const std::string& account_id) {
175 if (account_id == enrolling_account_id_) { 218 CHECK(enrolling_profile_);
176 enrolling_token_service_->RemoveObserver(this); 219
220 if (account_id == GetAccountIdFromProfile(enrolling_profile_)) {
221 ProfileOAuth2TokenServiceFactory::GetForProfile(enrolling_profile_)->
222 RemoveObserver(this);
177 OnOwnerRefreshTokenAvailable(); 223 OnOwnerRefreshTokenAvailable();
178 } 224 }
179 } 225 }
180 226
181 void ConsumerManagementService::OnGetTokenSuccess( 227 void ConsumerManagementService::OnGetTokenSuccess(
182 const OAuth2TokenService::Request* request, 228 const OAuth2TokenService::Request* request,
183 const std::string& access_token, 229 const std::string& access_token,
184 const base::Time& expiration_time) { 230 const base::Time& expiration_time) {
185 DCHECK_EQ(token_request_, request); 231 DCHECK_EQ(token_request_, request);
186 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); 232 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release());
187 233
188 OnOwnerAccessTokenAvailable(access_token); 234 OnOwnerAccessTokenAvailable(access_token);
189 } 235 }
190 236
191 void ConsumerManagementService::OnGetTokenFailure( 237 void ConsumerManagementService::OnGetTokenFailure(
192 const OAuth2TokenService::Request* request, 238 const OAuth2TokenService::Request* request,
193 const GoogleServiceAuthError& error) { 239 const GoogleServiceAuthError& error) {
194 DCHECK_EQ(token_request_, request); 240 DCHECK_EQ(token_request_, request);
195 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release()); 241 base::MessageLoop::current()->DeleteSoon(FROM_HERE, token_request_.release());
196 242
197 LOG(ERROR) << "Failed to get the access token: " << error.ToString(); 243 LOG(ERROR) << "Failed to get the access token: " << error.ToString();
198 EndEnrollment(ENROLLMENT_GET_TOKEN_FAILED); 244 EndEnrollment(ENROLLMENT_GET_TOKEN_FAILED);
199 } 245 }
200 246
247 void ConsumerManagementService::OnGetBootAttributeDone(
248 const GetOwnerCallback& callback,
249 chromeos::DBusMethodCallStatus call_status,
250 bool dbus_success,
251 const cryptohome::BaseReply& reply) {
252 if (!dbus_success || reply.error() != 0) {
253 LOG(ERROR) << "Failed to get the owner info from boot lockbox.";
254 callback.Run("");
255 return;
256 }
257
258 callback.Run(
259 reply.GetExtension(cryptohome::GetBootAttributeReply::reply).value());
260 }
261
262 void ConsumerManagementService::OnSetBootAttributeDone(
263 const SetOwnerCallback& callback,
264 chromeos::DBusMethodCallStatus call_status,
265 bool dbus_success,
266 const cryptohome::BaseReply& reply) {
267 if (!dbus_success || reply.error() != 0) {
268 LOG(ERROR) << "Failed to set owner info in boot lockbox.";
269 callback.Run(false);
270 return;
271 }
272
273 cryptohome::FlushAndSignBootAttributesRequest request;
274 client_->FlushAndSignBootAttributes(
275 request,
276 base::Bind(&ConsumerManagementService::OnFlushAndSignBootAttributesDone,
277 weak_ptr_factory_.GetWeakPtr(),
278 callback));
279 }
280
281 void ConsumerManagementService::OnFlushAndSignBootAttributesDone(
282 const SetOwnerCallback& callback,
283 chromeos::DBusMethodCallStatus call_status,
284 bool dbus_success,
285 const cryptohome::BaseReply& reply) {
286 if (!dbus_success || reply.error() != 0) {
287 LOG(ERROR) << "Failed to flush and sign boot lockbox.";
288 callback.Run(false);
289 return;
290 }
291
292 callback.Run(true);
293 }
294
201 void ConsumerManagementService::OnOwnerSignin(Profile* profile) { 295 void ConsumerManagementService::OnOwnerSignin(Profile* profile) {
202 const ConsumerEnrollmentState state = GetEnrollmentState(); 296 const ConsumerEnrollmentState state = GetEnrollmentState();
203 switch (state) { 297 switch (state) {
204 case ENROLLMENT_NONE: 298 case ENROLLMENT_NONE:
205 // Do nothing. 299 // Do nothing.
206 return; 300 return;
207 301
208 case ENROLLMENT_OWNER_STORED: 302 case ENROLLMENT_OWNER_STORED:
209 // Continue the enrollment process after the owner signs in. 303 // Continue the enrollment process after the owner signs in.
210 ContinueEnrollmentProcess(profile); 304 ContinueEnrollmentProcess(profile);
211 return; 305 return;
212 306
213 case ENROLLMENT_SUCCESS: 307 case ENROLLMENT_SUCCESS:
214 case ENROLLMENT_CANCELED: 308 case ENROLLMENT_CANCELED:
215 case ENROLLMENT_BOOT_LOCKBOX_FAILED: 309 case ENROLLMENT_BOOT_LOCKBOX_FAILED:
216 case ENROLLMENT_DM_SERVER_FAILED: 310 case ENROLLMENT_DM_SERVER_FAILED:
217 case ENROLLMENT_GET_TOKEN_FAILED: 311 case ENROLLMENT_GET_TOKEN_FAILED:
218 ShowDesktopNotificationAndResetState(state); 312 ShowDesktopNotificationAndResetState(state, profile);
219 return; 313 return;
220 314
221 case ENROLLMENT_REQUESTED: 315 case ENROLLMENT_REQUESTED:
222 case ENROLLMENT_LAST: 316 case ENROLLMENT_LAST:
223 NOTREACHED() << "Unexpected enrollment state " << state; 317 NOTREACHED() << "Unexpected enrollment state " << state;
224 return; 318 return;
225 } 319 }
226 } 320 }
227 321
228 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { 322 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) {
323 enrolling_profile_ = profile;
324
229 // First, we need to ensure that the refresh token is available. 325 // First, we need to ensure that the refresh token is available.
230 SigninManagerBase* signin_manager = 326 const std::string& account_id = GetAccountIdFromProfile(profile);
231 SigninManagerFactory::GetForProfile(profile); 327 ProfileOAuth2TokenService* token_service =
232 enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId();
233
234 enrolling_token_service_ =
235 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); 328 ProfileOAuth2TokenServiceFactory::GetForProfile(profile);
236 if (enrolling_token_service_->RefreshTokenIsAvailable( 329 if (token_service->RefreshTokenIsAvailable(account_id)) {
237 enrolling_account_id_)) {
238 OnOwnerRefreshTokenAvailable(); 330 OnOwnerRefreshTokenAvailable();
239 } else { 331 } else {
240 enrolling_token_service_->AddObserver(this); 332 token_service->AddObserver(this);
241 } 333 }
242 } 334 }
243 335
244 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() { 336 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() {
245 CHECK(enrolling_token_service_); 337 CHECK(enrolling_profile_);
246 338
247 // Now we can request the OAuth access token for device management to send the 339 // Now we can request the OAuth access token for device management to send the
248 // device registration request to the device management server. 340 // device registration request to the device management server.
249 OAuth2TokenService::ScopeSet oauth_scopes; 341 OAuth2TokenService::ScopeSet oauth_scopes;
250 oauth_scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth); 342 oauth_scopes.insert(GaiaConstants::kDeviceManagementServiceOAuth);
251 343 const std::string& account_id = GetAccountIdFromProfile(enrolling_profile_);
252 token_request_ = enrolling_token_service_->StartRequest( 344 token_request_ = ProfileOAuth2TokenServiceFactory::GetForProfile(
253 enrolling_account_id_, oauth_scopes, this); 345 enrolling_profile_)->StartRequest(account_id, oauth_scopes, this);
254 } 346 }
255 347
256 void ConsumerManagementService::OnOwnerAccessTokenAvailable( 348 void ConsumerManagementService::OnOwnerAccessTokenAvailable(
257 const std::string& access_token) { 349 const std::string& access_token) {
258 // Now that we have the access token, we got everything we need to send the 350 // Now that we have the access token, we got everything we need to send the
259 // device registration request to the device management server. 351 // device registration request to the device management server.
260 BrowserPolicyConnectorChromeOS* connector = 352 BrowserPolicyConnectorChromeOS* connector =
261 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 353 g_browser_process->platform_part()->browser_policy_connector_chromeos();
262 DeviceCloudPolicyInitializer* initializer = 354 DeviceCloudPolicyInitializer* initializer =
263 connector->GetDeviceCloudPolicyInitializer(); 355 connector->GetDeviceCloudPolicyInitializer();
(...skipping 21 matching lines...) Expand all
285 << " store_status=" << status.store_status() 377 << " store_status=" << status.store_status()
286 << " validation_status=" << status.validation_status(); 378 << " validation_status=" << status.validation_status();
287 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED); 379 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED);
288 return; 380 return;
289 } 381 }
290 382
291 EndEnrollment(ENROLLMENT_SUCCESS); 383 EndEnrollment(ENROLLMENT_SUCCESS);
292 } 384 }
293 385
294 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { 386 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) {
387 Profile* profile = enrolling_profile_;
388 enrolling_profile_ = NULL;
389
295 SetEnrollmentState(state); 390 SetEnrollmentState(state);
296 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) 391 if (user_manager::UserManager::Get()->IsCurrentUserOwner())
297 ShowDesktopNotificationAndResetState(state); 392 ShowDesktopNotificationAndResetState(state, profile);
298 } 393 }
299 394
300 void ConsumerManagementService::ShowDesktopNotificationAndResetState( 395 void ConsumerManagementService::ShowDesktopNotificationAndResetState(
301 ConsumerEnrollmentState state) { 396 ConsumerEnrollmentState state, Profile* profile) {
302 // TODO(davidyu): Show a desktop notification to the current user, who should 397 base::string16 title;
303 // be the owner. 398 base::string16 body;
399 base::string16 button_label;
400 base::Closure button_click_callback;
401
402 if (state == ENROLLMENT_SUCCESS) {
403 title = l10n_util::GetStringUTF16(
404 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE);
405 body = l10n_util::GetStringUTF16(
406 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY);
407 button_label = l10n_util::GetStringUTF16(
408 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON);
409 button_click_callback = base::Bind(
410 &ConsumerManagementService::OpenSettingsPage,
411 weak_ptr_factory_.GetWeakPtr(),
412 profile);
413 } else {
414 title = l10n_util::GetStringUTF16(
415 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE);
416 body = l10n_util::GetStringUTF16(
417 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY);
418 button_label = l10n_util::GetStringUTF16(
419 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON);
420 button_click_callback = base::Bind(
421 &ConsumerManagementService::TryEnrollmentAgain,
422 weak_ptr_factory_.GetWeakPtr(),
423 profile);
424 }
425
426 message_center::RichNotificationData optional_field;
427 optional_field.buttons.push_back(message_center::ButtonInfo(button_label));
428 Notification notification(
429 message_center::NOTIFICATION_TYPE_SIMPLE,
430 GURL(kEnrollmentNotificationUrl),
431 title,
432 body,
433 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
434 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON),
435 blink::WebTextDirectionDefault,
436 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
437 kEnrollmentNotificationId),
438 base::string16(), // display_source
439 base::UTF8ToUTF16(kEnrollmentNotificationId),
440 optional_field,
441 new DesktopNotificationDelegate(kEnrollmentNotificationId,
442 button_click_callback));
443 notification.SetSystemPriority();
444 g_browser_process->notification_ui_manager()->Add(notification, profile);
445
304 SetEnrollmentState(ENROLLMENT_NONE); 446 SetEnrollmentState(ENROLLMENT_NONE);
305 } 447 }
306 448
449 void ConsumerManagementService::OpenSettingsPage(Profile* profile) const {
450 const GURL url(chrome::kChromeUISettingsURL);
451 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK);
452 params.disposition = NEW_FOREGROUND_TAB;
453 chrome::Navigate(&params);
454 }
455
456 void ConsumerManagementService::TryEnrollmentAgain(Profile* profile) const {
457 const GURL base_url(chrome::kChromeUISettingsURL);
458 const GURL url = base_url.Resolve(kConsumerManagementOverlay);
459
460 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK);
461 params.disposition = NEW_FOREGROUND_TAB;
462 chrome::Navigate(&params);
463 }
464
307 } // namespace policy 465 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698