root/chrome/browser/chromeos/login/fake_user_manager.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. primary_user_
  2. AddUser
  3. AddKioskAppUser
  4. LoginUser
  5. SetProfileForUser
  6. GetUsers
  7. GetUsersAdmittedForMultiProfile
  8. GetLoggedInUsers
  9. UserLoggedIn
  10. GetActiveUserInternal
  11. GetActiveUser
  12. GetActiveUser
  13. SwitchActiveUser
  14. SaveUserDisplayName
  15. GetMultiProfileUserController
  16. GetSupervisedUserManager
  17. GetUserImageManager
  18. GetLRULoggedInUsers
  19. GetUnlockUsers
  20. GetOwnerEmail
  21. IsKnownUser
  22. FindUser
  23. FindUserAndModify
  24. GetLoggedInUser
  25. GetLoggedInUser
  26. GetPrimaryUser
  27. GetUserByProfile
  28. GetProfileByUser
  29. GetUserDisplayName
  30. GetUserDisplayEmail
  31. IsCurrentUserOwner
  32. IsCurrentUserNew
  33. IsCurrentUserNonCryptohomeDataEphemeral
  34. CanCurrentUserLock
  35. IsUserLoggedIn
  36. IsLoggedInAsRegularUser
  37. IsLoggedInAsDemoUser
  38. IsLoggedInAsPublicAccount
  39. IsLoggedInAsGuest
  40. IsLoggedInAsLocallyManagedUser
  41. IsLoggedInAsKioskApp
  42. IsLoggedInAsStub
  43. IsSessionStarted
  44. UserSessionsRestored
  45. HasBrowserRestarted
  46. IsUserNonCryptohomeDataEphemeral
  47. GetCurrentUserFlow
  48. GetUserFlow
  49. GetAppModeChromeClientOAuthInfo
  50. AreLocallyManagedUsersAllowed
  51. GetUserProfileDir
  52. RespectLocalePreference

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/login/fake_user_manager.h"

#include "chrome/browser/chromeos/login/fake_supervised_user_manager.h"

namespace {

// As defined in /chromeos/dbus/cryptohome_client.cc.
static const char kUserIdHashSuffix[] = "-hash";

}  // namespace

namespace chromeos {

FakeUserManager::FakeUserManager()
    : supervised_user_manager_(new FakeSupervisedUserManager),
      primary_user_(NULL) {}

FakeUserManager::~FakeUserManager() {
  // Can't use STLDeleteElements because of the private destructor of User.
  for (UserList::iterator it = user_list_.begin(); it != user_list_.end();
       it = user_list_.erase(it)) {
    delete *it;
  }
}

const User* FakeUserManager::AddUser(const std::string& email) {
  User* user = User::CreateRegularUser(email);
  user->set_username_hash(email + kUserIdHashSuffix);
  user->SetStubImage(User::kProfileImageIndex, false);
  user_list_.push_back(user);
  return user;
}

void FakeUserManager::AddKioskAppUser(const std::string& kiosk_app_username) {
  User* user = User::CreateKioskAppUser(kiosk_app_username);
  user->set_username_hash(kiosk_app_username + kUserIdHashSuffix);
  user_list_.push_back(user);
}

void FakeUserManager::LoginUser(const std::string& email) {
  UserLoggedIn(email, email + kUserIdHashSuffix, false);
}

void FakeUserManager::SetProfileForUser(const User* user, Profile* profile) {
  user_to_profile_[user] = profile;
}

const UserList& FakeUserManager::GetUsers() const {
  return user_list_;
}

UserList FakeUserManager::GetUsersAdmittedForMultiProfile() const {
  UserList result;
  for (UserList::const_iterator it = user_list_.begin();
       it != user_list_.end();
       ++it) {
    if ((*it)->GetType() == User::USER_TYPE_REGULAR && !(*it)->is_logged_in())
      result.push_back(*it);
  }
  return result;
}

const UserList& FakeUserManager::GetLoggedInUsers() const {
  return logged_in_users_;
}

void FakeUserManager::UserLoggedIn(const std::string& email,
                                   const std::string& username_hash,
                                   bool browser_restart) {
  for (UserList::const_iterator it = user_list_.begin();
       it != user_list_.end();
       ++it) {
    if ((*it)->username_hash() == username_hash) {
      (*it)->set_is_logged_in(true);
      logged_in_users_.push_back(*it);

      if (!primary_user_)
        primary_user_ = *it;
      break;
    }
  }
}

User* FakeUserManager::GetActiveUserInternal() const {
  if (user_list_.size()) {
    if (!active_user_id_.empty()) {
      for (UserList::const_iterator it = user_list_.begin();
           it != user_list_.end(); ++it) {
        if ((*it)->email() == active_user_id_)
          return *it;
      }
    }
    return user_list_[0];
  }
  return NULL;
}

const User* FakeUserManager::GetActiveUser() const {
  return GetActiveUserInternal();
}

User* FakeUserManager::GetActiveUser() {
  return GetActiveUserInternal();
}

void FakeUserManager::SwitchActiveUser(const std::string& email) {
  active_user_id_ = email;
}

void FakeUserManager::SaveUserDisplayName(
    const std::string& username,
    const base::string16& display_name) {
  for (UserList::iterator it = user_list_.begin();
       it != user_list_.end(); ++it) {
    if ((*it)->email() == username) {
      (*it)->set_display_name(display_name);
      return;
    }
  }
}

MultiProfileUserController* FakeUserManager::GetMultiProfileUserController() {
  return NULL;
}

SupervisedUserManager* FakeUserManager::GetSupervisedUserManager() {
  return supervised_user_manager_.get();
}

UserImageManager* FakeUserManager::GetUserImageManager(
    const std::string& /* user_id */) {
  return NULL;
}

const UserList& FakeUserManager::GetLRULoggedInUsers() {
  return user_list_;
}

UserList FakeUserManager::GetUnlockUsers() const {
  return user_list_;
}

const std::string& FakeUserManager::GetOwnerEmail() {
  return owner_email_;
}

bool FakeUserManager::IsKnownUser(const std::string& email) const {
  return true;
}

const User* FakeUserManager::FindUser(const std::string& email) const {
  return NULL;
}

User* FakeUserManager::FindUserAndModify(const std::string& email) {
  return NULL;
}

const User* FakeUserManager::GetLoggedInUser() const {
  return NULL;
}

User* FakeUserManager::GetLoggedInUser() {
  return NULL;
}

const User* FakeUserManager::GetPrimaryUser() const {
  return primary_user_;
}

User* FakeUserManager::GetUserByProfile(Profile* profile) const {
  const std::string& user_name = profile->GetProfileName();
  for (UserList::const_iterator it = user_list_.begin();
       it != user_list_.end(); ++it) {
    if ((*it)->email() == user_name)
      return *it;
  }
  return primary_user_;
}

Profile* FakeUserManager::GetProfileByUser(const User* user) const {
  std::map<const User*, Profile*>::const_iterator it =
      user_to_profile_.find(user);
  return it == user_to_profile_.end() ? NULL : it->second;
}

base::string16 FakeUserManager::GetUserDisplayName(
    const std::string& username) const {
  return base::string16();
}

std::string FakeUserManager::GetUserDisplayEmail(
    const std::string& username) const {
  return std::string();
}

bool FakeUserManager::IsCurrentUserOwner() const {
  return false;
}

bool FakeUserManager::IsCurrentUserNew() const {
  return false;
}

bool FakeUserManager::IsCurrentUserNonCryptohomeDataEphemeral() const {
  return false;
}

bool FakeUserManager::CanCurrentUserLock() const {
  return false;
}

bool FakeUserManager::IsUserLoggedIn() const {
  return logged_in_users_.size() > 0;
}

bool FakeUserManager::IsLoggedInAsRegularUser() const {
  return true;
}

bool FakeUserManager::IsLoggedInAsDemoUser() const {
  return false;
}

bool FakeUserManager::IsLoggedInAsPublicAccount() const {
  return false;
}

bool FakeUserManager::IsLoggedInAsGuest() const {
  return false;
}

bool FakeUserManager::IsLoggedInAsLocallyManagedUser() const {
  return false;
}

bool FakeUserManager::IsLoggedInAsKioskApp() const {
  const User* active_user = GetActiveUser();
  return active_user ?
      active_user->GetType() == User::USER_TYPE_KIOSK_APP :
      false;
}

bool FakeUserManager::IsLoggedInAsStub() const {
  return false;
}

bool FakeUserManager::IsSessionStarted() const {
  return false;
}

bool FakeUserManager::UserSessionsRestored() const {
  return false;
}

bool FakeUserManager::HasBrowserRestarted() const {
  return false;
}

bool FakeUserManager::IsUserNonCryptohomeDataEphemeral(
    const std::string& email) const {
  return false;
}

UserFlow* FakeUserManager::GetCurrentUserFlow() const {
  return NULL;
}

UserFlow* FakeUserManager::GetUserFlow(const std::string& email) const {
  return NULL;
}

bool FakeUserManager::GetAppModeChromeClientOAuthInfo(
    std::string* chrome_client_id,
    std::string* chrome_client_secret) {
  return false;
}

bool FakeUserManager::AreLocallyManagedUsersAllowed() const {
  return true;
}

base::FilePath FakeUserManager::GetUserProfileDir(
    const std::string&email) const {
  return base::FilePath();
}

bool FakeUserManager::RespectLocalePreference(
    Profile* profile,
    const User* user,
    scoped_ptr<locale_util::SwitchLanguageCallback> callback) const {
  return false;
}

}  // namespace chromeos

/* [<][>][^][v][top][bottom][index][help] */