OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/login/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/browser/chromeos/login/login_display.h" | 25 #include "chrome/browser/chromeos/login/login_display.h" |
26 #include "chrome/browser/chromeos/login/ownership_service.h" | 26 #include "chrome/browser/chromeos/login/ownership_service.h" |
27 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 27 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
28 #include "chrome/browser/chromeos/wm_ipc.h" | 28 #include "chrome/browser/chromeos/wm_ipc.h" |
29 #include "chrome/browser/defaults.h" | 29 #include "chrome/browser/defaults.h" |
30 #include "chrome/browser/prefs/pref_service.h" | 30 #include "chrome/browser/prefs/pref_service.h" |
31 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 31 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
32 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
34 #include "content/browser/browser_thread.h" | 34 #include "content/browser/browser_thread.h" |
| 35 #include "content/common/content_notification_types.h" |
35 #include "content/common/notification_service.h" | 36 #include "content/common/notification_service.h" |
36 #include "content/common/notification_type.h" | |
37 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
38 #include "ui/gfx/codec/png_codec.h" | 38 #include "ui/gfx/codec/png_codec.h" |
39 | 39 |
40 namespace chromeos { | 40 namespace chromeos { |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 // A vector pref of the users who have logged into the device. | 44 // A vector pref of the users who have logged into the device. |
45 const char kLoggedInUsers[] = "LoggedInUsers"; | 45 const char kLoggedInUsers[] = "LoggedInUsers"; |
46 // A dictionary that maps usernames to file paths to their images. | 46 // A dictionary that maps usernames to file paths to their images. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 LOG(ERROR) << "Failed to remove user image."; | 96 LOG(ERROR) << "Failed to remove user image."; |
97 return; | 97 return; |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 // Updates current user ownership on UI thread. | 101 // Updates current user ownership on UI thread. |
102 void UpdateOwnership(bool is_owner) { | 102 void UpdateOwnership(bool is_owner) { |
103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
104 | 104 |
105 g_user_manager.Get().set_current_user_is_owner(is_owner); | 105 g_user_manager.Get().set_current_user_is_owner(is_owner); |
106 NotificationService::current()->Notify(NotificationType::OWNERSHIP_CHECKED, | 106 NotificationService::current()->Notify(chrome::OWNERSHIP_CHECKED, |
107 NotificationService::AllSources(), | 107 NotificationService::AllSources(), |
108 NotificationService::NoDetails()); | 108 NotificationService::NoDetails()); |
109 if (is_owner) { | 109 if (is_owner) { |
110 // Also update cached value. | 110 // Also update cached value. |
111 UserCrosSettingsProvider::UpdateCachedOwner( | 111 UserCrosSettingsProvider::UpdateCachedOwner( |
112 g_user_manager.Get().logged_in_user().email()); | 112 g_user_manager.Get().logged_in_user().email()); |
113 } | 113 } |
114 } | 114 } |
115 | 115 |
116 // Checks current user's ownership on file thread. | 116 // Checks current user's ownership on file thread. |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 DVLOG(1) << "Loaded image for " << username; | 530 DVLOG(1) << "Loaded image for " << username; |
531 user_images_[username] = image; | 531 user_images_[username] = image; |
532 User user; | 532 User user; |
533 user.set_email(username); | 533 user.set_email(username); |
534 user.set_image(image); | 534 user.set_image(image); |
535 if (logged_in_user_.email() == username) | 535 if (logged_in_user_.email() == username) |
536 logged_in_user_.set_image(image); | 536 logged_in_user_.set_image(image); |
537 if (should_save_image) | 537 if (should_save_image) |
538 SaveUserImage(username, image); | 538 SaveUserImage(username, image); |
539 NotificationService::current()->Notify( | 539 NotificationService::current()->Notify( |
540 NotificationType::LOGIN_USER_IMAGE_CHANGED, | 540 chrome::LOGIN_USER_IMAGE_CHANGED, |
541 Source<UserManager>(this), | 541 Source<UserManager>(this), |
542 Details<const User>(&user)); | 542 Details<const User>(&user)); |
543 } | 543 } |
544 | 544 |
545 bool UserManager::IsLoggedInAsGuest() const { | 545 bool UserManager::IsLoggedInAsGuest() const { |
546 return logged_in_user().email() == kGuestUser; | 546 return logged_in_user().email() == kGuestUser; |
547 } | 547 } |
548 | 548 |
549 // Private constructor and destructor. Do nothing. | 549 // Private constructor and destructor. Do nothing. |
550 UserManager::UserManager() | 550 UserManager::UserManager() |
551 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader(this))), | 551 : ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_(new UserImageLoader(this))), |
552 current_user_is_owner_(false), | 552 current_user_is_owner_(false), |
553 current_user_is_new_(false), | 553 current_user_is_new_(false), |
554 user_is_logged_in_(false) { | 554 user_is_logged_in_(false) { |
555 registrar_.Add(this, NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, | 555 registrar_.Add(this, chrome::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED, |
556 NotificationService::AllSources()); | 556 NotificationService::AllSources()); |
557 } | 557 } |
558 | 558 |
559 UserManager::~UserManager() { | 559 UserManager::~UserManager() { |
560 image_loader_->set_delegate(NULL); | 560 image_loader_->set_delegate(NULL); |
561 } | 561 } |
562 | 562 |
563 FilePath UserManager::GetImagePathForUser(const std::string& username) { | 563 FilePath UserManager::GetImagePathForUser(const std::string& username) { |
564 std::string filename = username + ".png"; | 564 std::string filename = username + ".png"; |
565 FilePath user_data_dir; | 565 FilePath user_data_dir; |
(...skipping 29 matching lines...) Expand all Loading... |
595 CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11GetTpmTokenInfo( | 595 CrosLibrary::Get()->GetCryptohomeLibrary()->Pkcs11GetTpmTokenInfo( |
596 &local_token_name, &local_user_pin); | 596 &local_token_name, &local_user_pin); |
597 if (token_name) | 597 if (token_name) |
598 *token_name = local_token_name; | 598 *token_name = local_token_name; |
599 if (user_pin) | 599 if (user_pin) |
600 *user_pin = local_user_pin; | 600 *user_pin = local_user_pin; |
601 } | 601 } |
602 | 602 |
603 void UserManager::NotifyOnLogin() { | 603 void UserManager::NotifyOnLogin() { |
604 NotificationService::current()->Notify( | 604 NotificationService::current()->Notify( |
605 NotificationType::LOGIN_USER_CHANGED, | 605 chrome::LOGIN_USER_CHANGED, |
606 Source<UserManager>(this), | 606 Source<UserManager>(this), |
607 Details<const User>(&logged_in_user_)); | 607 Details<const User>(&logged_in_user_)); |
608 | 608 |
609 chromeos::input_method::InputMethodManager::GetInstance()-> | 609 chromeos::input_method::InputMethodManager::GetInstance()-> |
610 SetDeferImeStartup(false); | 610 SetDeferImeStartup(false); |
611 // Shut down the IME so that it will reload the user's settings. | 611 // Shut down the IME so that it will reload the user's settings. |
612 chromeos::input_method::InputMethodManager::GetInstance()-> | 612 chromeos::input_method::InputMethodManager::GetInstance()-> |
613 StopInputMethodDaemon(); | 613 StopInputMethodDaemon(); |
614 // Let the window manager know that we're logged in now. | 614 // Let the window manager know that we're logged in now. |
615 WmIpc::instance()->SetLoggedInProperty(true); | 615 WmIpc::instance()->SetLoggedInProperty(true); |
616 // Ensure we've opened the real user's key/certificate database. | 616 // Ensure we've opened the real user's key/certificate database. |
617 crypto::OpenPersistentNSSDB(); | 617 crypto::OpenPersistentNSSDB(); |
618 | 618 |
619 // Only load the Opencryptoki library into NSS if we have this switch. | 619 // Only load the Opencryptoki library into NSS if we have this switch. |
620 // TODO(gspencer): Remove this switch once cryptohomed work is finished: | 620 // TODO(gspencer): Remove this switch once cryptohomed work is finished: |
621 // http://crosbug.com/12295 and http://crosbug.com/12304 | 621 // http://crosbug.com/12295 and http://crosbug.com/12304 |
622 if (CommandLine::ForCurrentProcess()->HasSwitch( | 622 if (CommandLine::ForCurrentProcess()->HasSwitch( |
623 switches::kLoadOpencryptoki)) { | 623 switches::kLoadOpencryptoki)) { |
624 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); | 624 crypto::EnableTPMTokenForNSS(new RealTPMTokenInfoDelegate()); |
625 } | 625 } |
626 | 626 |
627 // Schedules current user ownership check on file thread. | 627 // Schedules current user ownership check on file thread. |
628 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 628 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
629 NewRunnableFunction(&CheckOwnership)); | 629 NewRunnableFunction(&CheckOwnership)); |
630 } | 630 } |
631 | 631 |
632 void UserManager::Observe(NotificationType type, | 632 void UserManager::Observe(int type, |
633 const NotificationSource& source, | 633 const NotificationSource& source, |
634 const NotificationDetails& details) { | 634 const NotificationDetails& details) { |
635 if (type == NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { | 635 if (type == chrome::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED) { |
636 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 636 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
637 NewRunnableFunction(&CheckOwnership)); | 637 NewRunnableFunction(&CheckOwnership)); |
638 } | 638 } |
639 } | 639 } |
640 | 640 |
641 bool UserManager::current_user_is_owner() const { | 641 bool UserManager::current_user_is_owner() const { |
642 base::AutoLock lk(current_user_is_owner_lock_); | 642 base::AutoLock lk(current_user_is_owner_lock_); |
643 return current_user_is_owner_; | 643 return current_user_is_owner_; |
644 } | 644 } |
645 | 645 |
646 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { | 646 void UserManager::set_current_user_is_owner(bool current_user_is_owner) { |
647 base::AutoLock lk(current_user_is_owner_lock_); | 647 base::AutoLock lk(current_user_is_owner_lock_); |
648 current_user_is_owner_ = current_user_is_owner; | 648 current_user_is_owner_ = current_user_is_owner; |
649 } | 649 } |
650 | 650 |
651 } // namespace chromeos | 651 } // namespace chromeos |
OLD | NEW |