diff options
author | oshima <oshima@chromium.org> | 2015-06-23 13:27:57 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-23 20:28:34 +0000 |
commit | 6becec22159c9ff9d670c5527cf1d49e97f47c61 (patch) | |
tree | 18a1289c72c99ccd9298c6de166957019ae1245e | |
parent | 640ec4d4fbb0a8f825eb35bf995501950339b98d (diff) | |
download | chromium_src-6becec22159c9ff9d670c5527cf1d49e97f47c61.zip chromium_src-6becec22159c9ff9d670c5527cf1d49e97f47c61.tar.gz chromium_src-6becec22159c9ff9d670c5527cf1d49e97f47c61.tar.bz2 |
Use GetProfileByUser instead of GetProfileByUserUnsafe in SessionStateDelegateChromeos.
minor changes:
* make ChromeLauncherControllerUserSwitchObserver cros specific because multi profile is cros only feature
* log unsafe use of profile as ERROR because it should not happen.
This CL depends on https://codereview.chromium.org/1178953004/
This CL is separated from above CL to minimize the risk of merge.
BUG=496875
Review URL: https://codereview.chromium.org/1196433004
Cr-Commit-Position: refs/heads/master@{#335734}
4 files changed, 29 insertions, 36 deletions
diff --git a/chrome/browser/chromeos/profiles/profile_helper.cc b/chrome/browser/chromeos/profiles/profile_helper.cc index e04a5cd..24411c3 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.cc +++ b/chrome/browser/chromeos/profiles/profile_helper.cc @@ -281,11 +281,11 @@ Profile* ProfileHelper::GetProfileByUserUnsafe(const user_manager::User* user) { if (user->is_profile_created()) { profile = ProfileHelper::GetProfileByUserIdHash(user->username_hash()); } else { - LOG(WARNING) << "ProfileHelper::GetProfileByUserUnsafe is called when " - "|user|'s profile is not created. It probably means that " - "something is wrong with a calling code. Please report in " - "http://crbug.com/361528 if you see this message. user_id: " - << user->email(); + LOG(ERROR) << "ProfileHelper::GetProfileByUserUnsafe is called when " + "|user|'s profile is not created. It probably means that " + "something is wrong with a calling code. Please report in " + "http://crbug.com/361528 if you see this message. user_id: " + << user->email(); profile = ProfileManager::GetActiveUserProfile(); } diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc index 4be5c65..59d5e42 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.cc @@ -271,17 +271,16 @@ std::string GetSourceFromAppListSource(ash::LaunchSource source) { #if defined(OS_CHROMEOS) // A class to get events from ChromeOS when a user gets changed or added. -class ChromeLauncherControllerUserSwitchObserverChromeOS - : public ChromeLauncherControllerUserSwitchObserver, - public user_manager::UserManager::UserSessionStateObserver { +class ChromeLauncherControllerUserSwitchObserver + : public user_manager::UserManager::UserSessionStateObserver { public: - ChromeLauncherControllerUserSwitchObserverChromeOS( + ChromeLauncherControllerUserSwitchObserver( ChromeLauncherController* controller) : controller_(controller) { DCHECK(user_manager::UserManager::IsInitialized()); user_manager::UserManager::Get()->AddSessionStateObserver(this); } - ~ChromeLauncherControllerUserSwitchObserverChromeOS() override { + ~ChromeLauncherControllerUserSwitchObserver() override { user_manager::UserManager::Get()->RemoveSessionStateObserver(this); } @@ -289,7 +288,7 @@ class ChromeLauncherControllerUserSwitchObserverChromeOS void UserAddedToSession(const user_manager::User* added_user) override; // ChromeLauncherControllerUserSwitchObserver: - void OnUserProfileReadyToSwitch(Profile* profile) override; + void OnUserProfileReadyToSwitch(Profile* profile); private: // Add a user to the session. @@ -302,10 +301,10 @@ class ChromeLauncherControllerUserSwitchObserverChromeOS // (fully) loaded. std::set<std::string> added_user_ids_waiting_for_profiles_; - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerUserSwitchObserverChromeOS); + DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerUserSwitchObserver); }; -void ChromeLauncherControllerUserSwitchObserverChromeOS::UserAddedToSession( +void ChromeLauncherControllerUserSwitchObserver::UserAddedToSession( const user_manager::User* active_user) { Profile* profile = multi_user_util::GetProfileFromUserID( active_user->email()); @@ -317,8 +316,8 @@ void ChromeLauncherControllerUserSwitchObserverChromeOS::UserAddedToSession( AddUser(profile); } -void ChromeLauncherControllerUserSwitchObserverChromeOS:: - OnUserProfileReadyToSwitch(Profile* profile) { +void ChromeLauncherControllerUserSwitchObserver::OnUserProfileReadyToSwitch( + Profile* profile) { if (!added_user_ids_waiting_for_profiles_.empty()) { // Check if the profile is from a user which was on the waiting list. std::string user_id = multi_user_util::GetUserIDFromProfile(profile); @@ -333,8 +332,7 @@ void ChromeLauncherControllerUserSwitchObserverChromeOS:: } } -void ChromeLauncherControllerUserSwitchObserverChromeOS::AddUser( - Profile* profile) { +void ChromeLauncherControllerUserSwitchObserver::AddUser(Profile* profile) { if (chrome::MultiUserWindowManager::GetMultiProfileMode() == chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) chrome::MultiUserWindowManager::GetInstance()->AddUser(profile); @@ -378,7 +376,7 @@ ChromeLauncherController::ChromeLauncherController(Profile* profile, if (chrome::MultiUserWindowManager::GetMultiProfileMode() != chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_OFF) { user_switch_observer_.reset( - new ChromeLauncherControllerUserSwitchObserverChromeOS(this)); + new ChromeLauncherControllerUserSwitchObserver(this)); } // Create our v1/v2 application / browser monitors which will inform the @@ -1505,8 +1503,10 @@ bool ChromeLauncherController::ShelfBoundsChangesProbablyWithUser( } void ChromeLauncherController::OnUserProfileReadyToSwitch(Profile* profile) { +#if defined(OS_CHROMEOS) if (user_switch_observer_.get()) user_switch_observer_->OnUserProfileReadyToSwitch(profile); +#endif } void ChromeLauncherController::LauncherItemClosed(ash::ShelfID id) { diff --git a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h index 4207b59..da8900d 100644 --- a/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h +++ b/chrome/browser/ui/ash/launcher/chrome_launcher_controller.h @@ -68,23 +68,13 @@ namespace ui { class BaseWindow; } +#if defined(OS_CHROMEOS) +class ChromeLauncherControllerUserSwitchObserver; +#endif + // A list of the elements which makes up a simple menu description. typedef ScopedVector<ChromeLauncherAppMenuItem> ChromeLauncherAppMenuItems; -// A class which needs to be overwritten dependent on the used OS to moitor -// user switching. -// TODO(oshima): move this to .cc -class ChromeLauncherControllerUserSwitchObserver { - public: - ChromeLauncherControllerUserSwitchObserver() {} - virtual ~ChromeLauncherControllerUserSwitchObserver() {} - - virtual void OnUserProfileReadyToSwitch(Profile* profile) = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerUserSwitchObserver); -}; - // ChromeLauncherController manages the launcher items needed for content // windows. Launcher items have a type, an optional app id, and a controller. // This incarnation groups running tabs/windows in application specific lists. @@ -607,8 +597,10 @@ class ChromeLauncherController : public ash::ShelfDelegate, // The owned browser status monitor. scoped_ptr<BrowserStatusMonitor> browser_status_monitor_; +#if defined(OS_CHROMEOS) // A special observer class to detect user switches. scoped_ptr<ChromeLauncherControllerUserSwitchObserver> user_switch_observer_; +#endif // If true, incoming pinned state changes should be ignored. bool ignore_persist_pinned_state_change_; diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc index f7dcc0a..a0082c1 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc @@ -57,7 +57,7 @@ content::BrowserContext* SessionStateDelegateChromeos::GetBrowserContextByIndex( user_manager::User* user = user_manager::UserManager::Get()->GetLRULoggedInUsers()[index]; CHECK(user); - return chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); + return chromeos::ProfileHelper::Get()->GetProfileByUser(user); } content::BrowserContext* @@ -126,10 +126,11 @@ bool SessionStateDelegateChromeos::ShouldLockScreenBeforeSuspending() const { it != logged_in_users.end(); ++it) { user_manager::User* user = (*it); - Profile* profile = - chromeos::ProfileHelper::Get()->GetProfileByUserUnsafe(user); - if (profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) + Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(user); + if (profile && + profile->GetPrefs()->GetBoolean(prefs::kEnableAutoScreenLock)) { return true; + } } return false; } |