Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / session_state_delegate_chromeos.cc
index 2f7c840..8a85450 100644 (file)
@@ -6,6 +6,9 @@
 
 #include "ash/multi_profile_uma.h"
 #include "ash/session/session_state_observer.h"
+#include "ash/system/chromeos/multi_user/user_switch_util.h"
+#include "base/bind.h"
+#include "base/callback.h"
 #include "base/command_line.h"
 #include "base/logging.h"
 #include "base/prefs/pref_service.h"
@@ -80,6 +83,18 @@ int SessionStateDelegateChromeos::NumberOfLoggedInUsers() const {
   return user_manager::UserManager::Get()->GetLoggedInUsers().size();
 }
 
+bool SessionStateDelegateChromeos::CanAddUserToMultiProfile(
+    AddUserError* error) const {
+  if (user_manager::UserManager::Get()
+          ->GetUsersAdmittedForMultiProfile()
+          .size() == 0) {
+    if (error)
+      *error = ADD_USER_ERROR_OUT_OF_USERS;
+    return false;
+  }
+  return SessionStateDelegate::CanAddUserToMultiProfile(error);
+}
+
 bool SessionStateDelegateChromeos::IsActiveUserSessionStarted() const {
   return user_manager::UserManager::Get()->IsSessionStarted();
 }
@@ -164,7 +179,7 @@ void SessionStateDelegateChromeos::SwitchActiveUser(
             gaia::CanonicalizeEmail(gaia::SanitizeEmail(user_id)));
   if (user_id == user_manager::UserManager::Get()->GetActiveUser()->email())
     return;
-  user_manager::UserManager::Get()->SwitchActiveUser(user_id);
+  TryToSwitchUser(user_id);
 }
 
 void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) {
@@ -207,7 +222,7 @@ void SessionStateDelegateChromeos::CycleActiveUser(CycleUser cycle_user) {
   }
 
   // Switch using the transformed |user_id|.
-  user_manager::UserManager::Get()->SwitchActiveUser(user_id);
+  TryToSwitchUser(user_id);
 }
 
 bool SessionStateDelegateChromeos::IsMultiProfileAllowedByPrimaryUserPolicy()
@@ -267,3 +282,12 @@ void SessionStateDelegateChromeos::NotifySessionStateChanged() {
                     session_state_observer_list_,
                     SessionStateChanged(session_state_));
 }
+
+void DoSwitchUser(const std::string& user_id) {
+  user_manager::UserManager::Get()->SwitchActiveUser(user_id);
+}
+
+void SessionStateDelegateChromeos::TryToSwitchUser(
+    const std::string& user_id) {
+  ash::TrySwitchingActiveUser(base::Bind(&DoSwitchUser, user_id));
+}