Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / fake_login_utils.cc
index 2f7a0f1..9caab9f 100644 (file)
@@ -4,21 +4,25 @@
 
 #include "chrome/browser/chromeos/login/fake_login_utils.h"
 
+#include "base/callback.h"
 #include "base/command_line.h"
-#include "base/path_service.h"
 #include "base/prefs/pref_service.h"
-#include "chrome/browser/browser_process.h"
 #include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/chromeos/login/login_display_host.h"
-#include "chrome/browser/chromeos/login/mock_authenticator.h"
-#include "chrome/browser/chromeos/login/supervised_user_manager.h"
+#include "chrome/browser/chromeos/login/ui/login_display_host.h"
+#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
+#include "chrome/browser/chromeos/login/user_flow.h"
+#include "chrome/browser/chromeos/login/users/chrome_user_manager.h"
+#include "chrome/browser/chromeos/login/users/supervised_user_manager.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
 #include "chrome/browser/first_run/first_run.h"
-#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/profiles/profile.h"
 #include "chrome/browser/ui/startup/startup_browser_creator.h"
-#include "chrome/common/chrome_constants.h"
-#include "chrome/common/chrome_paths.h"
 #include "chrome/common/pref_names.h"
 #include "chrome/test/base/testing_profile.h"
+#include "chromeos/login/auth/mock_authenticator.h"
+#include "chromeos/login/auth/user_context.h"
+#include "components/user_manager/user.h"
+#include "components/user_manager/user_manager.h"
 #include "content/public/browser/notification_service.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
@@ -30,9 +34,8 @@ FakeLoginUtils::~FakeLoginUtils() {}
 
 void FakeLoginUtils::DoBrowserLaunch(Profile* profile,
                                      LoginDisplayHost* login_host) {
-
-  if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) {
-      UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile);
+  if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) {
+    ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile);
       return;
   }
   login_host->BeforeSessionStart();
@@ -51,79 +54,80 @@ void FakeLoginUtils::DoBrowserLaunch(Profile* profile,
   }
   if (login_host)
     login_host->Finalize();
-  UserManager::Get()->SessionStarted();
+  user_manager::UserManager::Get()->SessionStarted();
 }
 
 void FakeLoginUtils::PrepareProfile(const UserContext& user_context,
-                                    const std::string& display_email,
                                     bool has_cookies,
                                     bool has_active_session,
                                     LoginUtils::Delegate* delegate) {
-  UserManager::Get()->UserLoggedIn(
-      user_context.username, user_context.username_hash, false);
-  Profile* profile = CreateProfile(user_context.username);
-
-  if (UserManager::Get()->IsLoggedInAsLocallyManagedUser()) {
-    User* active_user = UserManager::Get()->GetActiveUser();
-    std::string managed_user_sync_id =
-        UserManager::Get()->GetSupervisedUserManager()->
-            GetUserSyncId(active_user->email());
-    if (managed_user_sync_id.empty())
-      managed_user_sync_id = "DUMMY ID";
-    profile->GetPrefs()->SetString(prefs::kManagedUserId,
-                                   managed_user_sync_id);
+  user_manager::UserManager* user_manager = user_manager::UserManager::Get();
+  user_manager->UserLoggedIn(
+      user_context.GetUserID(), user_context.GetUserIDHash(), false);
+  user_manager::User* user =
+      user_manager->FindUserAndModify(user_context.GetUserID());
+  DCHECK(user);
+
+  // Make sure that we get the real Profile instead of the login Profile.
+  user->set_profile_is_created();
+  Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user);
+  profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
+                                 user_context.GetUserID());
+
+  if (user_manager->IsLoggedInAsSupervisedUser()) {
+    user_manager::User* active_user = user_manager->GetActiveUser();
+    std::string supervised_user_sync_id =
+        ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId(
+            active_user->email());
+    if (supervised_user_sync_id.empty())
+      supervised_user_sync_id = "DUMMY ID";
+    profile->GetPrefs()->SetString(prefs::kSupervisedUserId,
+                                   supervised_user_sync_id);
   }
 
   content::NotificationService::current()->Notify(
       chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED,
       content::NotificationService::AllSources(),
       content::Details<Profile>(profile));
-  if (delegate)
-    delegate->OnProfilePrepared(profile);
-}
 
-void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) {
-  NOTREACHED() << "Method not implemented.";
-}
+  // Emulate UserSessionManager::InitializeUserSession() for now till
+  // FakeLoginUtils are deprecated.
+  bool browser_launched = false;
+  if (!user_manager->IsLoggedInAsKioskApp()) {
+    if (user_manager->IsCurrentUserNew()) {
+      NOTREACHED() << "Method not implemented.";
+    } else {
+      browser_launched = true;
+      LoginUtils::Get()->DoBrowserLaunch(profile,
+                                         LoginDisplayHostImpl::default_host());
+    }
+  }
 
-void FakeLoginUtils::CompleteOffTheRecordLogin(const GURL& start_url) {
-  NOTREACHED() << "Method not implemented.";
+  if (delegate)
+    delegate->OnProfilePrepared(profile, browser_launched);
 }
 
-void FakeLoginUtils::SetFirstLoginPrefs(PrefService* prefs) {
+void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) {
   NOTREACHED() << "Method not implemented.";
 }
 
 scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator(
-    LoginStatusConsumer* consumer) {
-  authenticator_ =
-      new MockAuthenticator(consumer, expected_username_, expected_password_);
+    AuthStatusConsumer* consumer) {
+  authenticator_ = new MockAuthenticator(consumer, expected_user_context_);
   return authenticator_;
 }
 
-void FakeLoginUtils::RestoreAuthenticationSession(Profile* profile) {
+bool FakeLoginUtils::RestartToApplyPerSessionFlagsIfNeed(Profile* profile,
+                                                         bool early_restart) {
   NOTREACHED() << "Method not implemented.";
+  return false;
 }
 
-void FakeLoginUtils::InitRlzDelayed(Profile* user_profile) {
-  NOTREACHED() << "Method not implemented.";
-}
-
-Profile* FakeLoginUtils::CreateProfile(const std::string& username_hash) {
-  base::FilePath path;
-  PathService::Get(chrome::DIR_USER_DATA, &path);
-  path = path.AppendASCII(chrome::kProfileDirPrefix + username_hash);
-  Profile* profile = g_browser_process->profile_manager()->GetProfile(path);
-  return profile;
-}
-
-void FakeLoginUtils::SetExpectedCredentials(const std::string& username,
-                                            const std::string& password) {
-  expected_username_ = username;
-  expected_password_ = password;
+void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) {
+  expected_user_context_ = user_context;
   if (authenticator_.get()) {
     static_cast<MockAuthenticator*>(authenticator_.get())->
-        SetExpectedCredentials(username, password);
+        SetExpectedCredentials(user_context);
   }
 }