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_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/browser/web_contents.h" | |
bartfab (slow)
2014/08/20 13:55:49
Nit: Not used.
davidyu
2014/08/21 04:08:25
Done.
| |
41 #include "content/public/common/page_transition_types.h" | |
35 #include "google_apis/gaia/gaia_constants.h" | 42 #include "google_apis/gaia/gaia_constants.h" |
36 #include "google_apis/gaia/google_service_auth_error.h" | 43 #include "google_apis/gaia/google_service_auth_error.h" |
44 #include "grit/generated_resources.h" | |
45 #include "grit/theme_resources.h" | |
37 #include "policy/proto/device_management_backend.pb.h" | 46 #include "policy/proto/device_management_backend.pb.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/notifier_settings.h" | |
51 #include "url/gurl.h" | |
38 | 52 |
39 namespace { | 53 namespace { |
40 | 54 |
55 // Boot atttributes ID. | |
41 const char* kAttributeOwnerId = "consumer_management.owner_id"; | 56 const char* kAttributeOwnerId = "consumer_management.owner_id"; |
oshima
2014/08/20 13:24:00
const char[]
davidyu
2014/08/21 04:08:24
Done.
| |
42 | 57 |
58 // Desktop notification constants. | |
59 const char* kEnrollmentNotificationId = "consumer_management.enroll"; | |
60 const char* kEnrollmentNotificationUrl = "chrome://consumer-management/enroll"; | |
61 | |
62 // URL | |
bartfab (slow)
2014/08/20 13:55:50
This is not a URL. This is a path to something. Pl
davidyu
2014/08/21 04:08:24
Done.
| |
63 const char* kConsumerManagementOverlay = "/consumer-management-overlay"; | |
oshima
2014/08/20 13:24:01
ditto
davidyu
2014/08/21 04:08:24
Done.
| |
64 | |
43 } // namespace | 65 } // namespace |
44 | 66 |
45 namespace policy { | 67 namespace policy { |
46 | 68 |
47 ConsumerManagementService::ConsumerManagementService( | 69 ConsumerManagementService::ConsumerManagementService( |
48 chromeos::CryptohomeClient* client) | 70 chromeos::CryptohomeClient* client) |
49 : Consumer("consumer_management_service"), | 71 : Consumer("consumer_management_service"), |
50 client_(client), | 72 client_(client), |
51 enrolling_token_service_(NULL), | 73 enrolling_token_service_(NULL), |
52 is_observing_token_service_(false), | 74 is_observing_token_service_(false), |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 case ENROLLMENT_OWNER_STORED: | 234 case ENROLLMENT_OWNER_STORED: |
213 // Continue the enrollment process after the owner signs in. | 235 // Continue the enrollment process after the owner signs in. |
214 ContinueEnrollmentProcess(profile); | 236 ContinueEnrollmentProcess(profile); |
215 return; | 237 return; |
216 | 238 |
217 case ENROLLMENT_SUCCESS: | 239 case ENROLLMENT_SUCCESS: |
218 case ENROLLMENT_CANCELED: | 240 case ENROLLMENT_CANCELED: |
219 case ENROLLMENT_BOOT_LOCKBOX_FAILED: | 241 case ENROLLMENT_BOOT_LOCKBOX_FAILED: |
220 case ENROLLMENT_DM_SERVER_FAILED: | 242 case ENROLLMENT_DM_SERVER_FAILED: |
221 case ENROLLMENT_GET_TOKEN_FAILED: | 243 case ENROLLMENT_GET_TOKEN_FAILED: |
222 ShowDesktopNotificationAndResetState(state); | 244 ShowDesktopNotificationAndResetState(state, profile); |
223 return; | 245 return; |
224 | 246 |
225 case ENROLLMENT_REQUESTED: | 247 case ENROLLMENT_REQUESTED: |
226 case ENROLLMENT_LAST: | 248 case ENROLLMENT_LAST: |
227 NOTREACHED() << "Unexpected enrollment state " << state; | 249 NOTREACHED() << "Unexpected enrollment state " << state; |
228 return; | 250 return; |
229 } | 251 } |
230 } | 252 } |
231 | 253 |
232 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { | 254 void ConsumerManagementService::ContinueEnrollmentProcess(Profile* profile) { |
233 // First, we need to ensure that the refresh token is available. | 255 // First, we need to ensure that the refresh token is available. |
234 SigninManagerBase* signin_manager = | 256 SigninManagerBase* signin_manager = |
235 SigninManagerFactory::GetForProfile(profile); | 257 SigninManagerFactory::GetForProfile(profile); |
258 | |
236 enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId(); | 259 enrolling_account_id_ = signin_manager->GetAuthenticatedAccountId(); |
237 | 260 enrolling_profile_ = profile; |
238 enrolling_token_service_ = | 261 enrolling_token_service_ = |
239 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 262 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
263 | |
240 if (enrolling_token_service_->RefreshTokenIsAvailable( | 264 if (enrolling_token_service_->RefreshTokenIsAvailable( |
241 enrolling_account_id_)) { | 265 enrolling_account_id_)) { |
242 OnOwnerRefreshTokenAvailable(); | 266 OnOwnerRefreshTokenAvailable(); |
243 } else { | 267 } else { |
244 is_observing_token_service_ = true; | 268 is_observing_token_service_ = true; |
245 enrolling_token_service_->AddObserver(this); | 269 enrolling_token_service_->AddObserver(this); |
246 } | 270 } |
247 } | 271 } |
248 | 272 |
249 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() { | 273 void ConsumerManagementService::OnOwnerRefreshTokenAvailable() { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 << " store_status=" << status.store_status() | 314 << " store_status=" << status.store_status() |
291 << " validation_status=" << status.validation_status(); | 315 << " validation_status=" << status.validation_status(); |
292 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED); | 316 EndEnrollment(ENROLLMENT_DM_SERVER_FAILED); |
293 return; | 317 return; |
294 } | 318 } |
295 | 319 |
296 EndEnrollment(ENROLLMENT_SUCCESS); | 320 EndEnrollment(ENROLLMENT_SUCCESS); |
297 } | 321 } |
298 | 322 |
299 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { | 323 void ConsumerManagementService::EndEnrollment(ConsumerEnrollmentState state) { |
324 Profile* profile = enrolling_profile_; | |
325 | |
326 enrolling_account_id_.clear(); | |
327 enrolling_profile_ = NULL; | |
328 enrolling_token_service_ = NULL; | |
329 | |
300 SetEnrollmentState(state); | 330 SetEnrollmentState(state); |
301 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) | 331 if (user_manager::UserManager::Get()->IsCurrentUserOwner()) |
302 ShowDesktopNotificationAndResetState(state); | 332 ShowDesktopNotificationAndResetState(state, profile); |
303 } | 333 } |
304 | 334 |
305 void ConsumerManagementService::ShowDesktopNotificationAndResetState( | 335 void ConsumerManagementService::ShowDesktopNotificationAndResetState( |
306 ConsumerEnrollmentState state) { | 336 ConsumerEnrollmentState state, Profile* profile) { |
307 // TODO(davidyu): Show a desktop notification to the current user, who should | 337 base::string16 title, body, button_label; |
bartfab (slow)
2014/08/20 13:55:49
Nit: Declare one variable per line.
davidyu
2014/08/21 04:08:24
Done.
| |
308 // be the owner. | 338 base::Closure button_click_callback; |
339 | |
340 if (state == ENROLLMENT_SUCCESS) { | |
341 title =l10n_util::GetStringUTF16( | |
bartfab (slow)
2014/08/20 13:55:50
Nit: s/=/= /
davidyu
2014/08/21 04:08:25
Done.
| |
342 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_TITLE); | |
343 body = l10n_util::GetStringUTF16( | |
344 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_NOTIFICATION_BODY); | |
345 button_label = l10n_util::GetStringUTF16( | |
346 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_MODIFY_SETTINGS_BUTTON); | |
347 button_click_callback = base::Bind( | |
348 &ConsumerManagementService::OpenSettingsPage, | |
349 weak_ptr_factory_.GetWeakPtr(), | |
350 profile); | |
351 } else { | |
352 title =l10n_util::GetStringUTF16( | |
bartfab (slow)
2014/08/20 13:55:50
Nit: s/=/= /
davidyu
2014/08/21 04:08:24
Done.
| |
353 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_TITLE); | |
354 body = l10n_util::GetStringUTF16( | |
355 IDS_CONSUMER_MANAGEMENT_ENROLLMENT_FAILURE_NOTIFICATION_BODY); | |
356 button_label = l10n_util::GetStringUTF16( | |
357 IDS_CONSUMER_MANAGEMENT_NOTIFICATION_TRY_AGAIN_BUTTON); | |
358 button_click_callback = base::Bind( | |
359 &ConsumerManagementService::TryEnrollmentAgain, | |
360 weak_ptr_factory_.GetWeakPtr(), | |
361 profile); | |
362 } | |
363 | |
364 ShowDesktopNotification( | |
365 profile, | |
366 kEnrollmentNotificationId, | |
367 kEnrollmentNotificationUrl, | |
368 title, | |
369 body, | |
370 button_label, | |
371 button_click_callback); | |
372 | |
309 SetEnrollmentState(ENROLLMENT_NONE); | 373 SetEnrollmentState(ENROLLMENT_NONE); |
310 } | 374 } |
311 | 375 |
376 void ConsumerManagementService::OpenSettingsPage(Profile* profile) const { | |
377 GURL url(chrome::kChromeUISettingsURL); | |
bartfab (slow)
2014/08/20 13:55:49
Nit: const.
davidyu
2014/08/21 04:08:25
Done.
| |
378 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); | |
379 params.disposition = NEW_FOREGROUND_TAB; | |
380 chrome::Navigate(¶ms); | |
381 return; | |
oshima
2014/08/20 13:24:01
remove this
bartfab (slow)
2014/08/20 13:55:50
Nit: No need for a return here.
davidyu
2014/08/21 04:08:24
Done.
| |
382 } | |
383 | |
384 void ConsumerManagementService::TryEnrollmentAgain(Profile* profile) const { | |
385 std::string url_string(chrome::kChromeUISettingsURL); | |
386 url_string.append(kConsumerManagementOverlay); | |
bartfab (slow)
2014/08/20 13:55:51
Nit: Instead of concatenating strings and then tur
davidyu
2014/08/21 04:08:25
Done.
| |
387 | |
388 GURL url(url_string); | |
bartfab (slow)
2014/08/20 13:55:51
Nit: const.
davidyu
2014/08/21 04:08:24
Removed.
| |
389 chrome::NavigateParams params(profile, url, content::PAGE_TRANSITION_LINK); | |
390 params.disposition = NEW_FOREGROUND_TAB; | |
391 chrome::Navigate(¶ms); | |
392 } | |
393 | |
394 void ConsumerManagementService::ShowDesktopNotification( | |
bartfab (slow)
2014/08/20 13:55:50
Nit: You could fold this into ShowDesktopNotificat
davidyu
2014/08/21 04:08:24
Done.
| |
395 Profile* profile, | |
396 const std::string& id, | |
bartfab (slow)
2014/08/20 13:55:49
Nit: This will always be kEnrollmentNotificationId
davidyu
2014/08/21 04:08:24
Done.
| |
397 const std::string& origin_url, | |
bartfab (slow)
2014/08/20 13:55:49
Nit: This will always be kEnrollmentNotificationUr
davidyu
2014/08/21 04:08:24
Done.
| |
398 const base::string16& title, | |
399 const base::string16& body, | |
400 const base::string16& button_label, | |
401 const base::Closure& button_click_callback) const { | |
402 message_center::RichNotificationData optional_field; | |
bartfab (slow)
2014/08/20 13:55:49
Nit: #include "ui/message_center/notification.h"
davidyu
2014/08/21 04:08:24
Done.
| |
403 optional_field.buttons.push_back(message_center::ButtonInfo(button_label)); | |
404 | |
405 scoped_ptr<Notification> notification( | |
bartfab (slow)
2014/08/20 13:55:50
Why do you use a scoped_ptr instead of a stack obj
davidyu
2014/08/21 04:08:25
Converted it back to a simple local variable.
| |
406 new Notification( | |
407 message_center::NOTIFICATION_TYPE_SIMPLE, | |
bartfab (slow)
2014/08/20 13:55:51
Nit: #include "ui/message_center/notification_type
davidyu
2014/08/21 04:08:24
Done.
| |
408 GURL(origin_url), | |
409 title, | |
410 body, | |
411 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | |
412 IDR_CONSUMER_MANAGEMENT_NOTIFICATION_ICON), | |
413 blink::WebTextDirectionDefault, | |
bartfab (slow)
2014/08/20 13:55:49
Nit: #include "third_party/WebKit/public/web/WebTe
davidyu
2014/08/21 04:08:24
Done.
| |
414 message_center::NotifierId( | |
415 message_center::NotifierId::SYSTEM_COMPONENT, id), | |
416 base::string16(), // display_source | |
417 base::UTF8ToUTF16(id), | |
418 optional_field, | |
419 new DesktopNotificationDelegate(id, button_click_callback))); | |
420 notification->SetSystemPriority(); | |
421 | |
422 g_browser_process->notification_ui_manager()->Add(*notification, profile); | |
423 } | |
424 | |
425 ConsumerManagementService::DesktopNotificationDelegate:: | |
bartfab (slow)
2014/08/20 13:55:50
Nit: Declaration and definition order should match
davidyu
2014/08/21 04:08:24
Done.
| |
426 DesktopNotificationDelegate( | |
bartfab (slow)
2014/08/20 13:55:49
Nit: Indent four spaces.
davidyu
2014/08/21 04:08:24
Done.
| |
427 const std::string& id, | |
428 const base::Closure& button_click_callback) | |
429 : id_(id), | |
430 button_click_callback_(button_click_callback) { | |
431 } | |
432 | |
433 void ConsumerManagementService::DesktopNotificationDelegate::ButtonClick( | |
434 int button_index) { | |
435 button_click_callback_.Run(); | |
436 } | |
437 | |
312 } // namespace policy | 438 } // namespace policy |
OLD | NEW |