This source file includes following definitions.
- GetUserIDFromProfile
- GetUserIDFromEmail
- GetProfileFromUserID
- GetProfileFromWindow
- IsProfileFromActiveUser
- GetCurrentUserId
- MoveWindowToCurrentDesktop
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include <vector>
#include "base/strings/string_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "google_apis/gaia/gaia_auth_util.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#endif
namespace multi_user_util {
std::string GetUserIDFromProfile(Profile* profile) {
return GetUserIDFromEmail(profile->GetOriginalProfile()->GetProfileName());
}
std::string GetUserIDFromEmail(const std::string& email) {
return email.empty() ?
email : gaia::CanonicalizeEmail(gaia::SanitizeEmail(email));
}
Profile* GetProfileFromUserID(const std::string& user_id) {
if (!g_browser_process || !g_browser_process->profile_manager())
return NULL;
std::vector<Profile*> profiles =
g_browser_process->profile_manager()->GetLoadedProfiles();
std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
for (; profile_iterator != profiles.end(); ++profile_iterator) {
if (GetUserIDFromProfile(*profile_iterator) == user_id)
return *profile_iterator;
}
return NULL;
}
Profile* GetProfileFromWindow(aura::Window* window) {
#if defined(OS_CHROMEOS)
chrome::MultiUserWindowManager* manager =
chrome::MultiUserWindowManager::GetInstance();
if (!manager)
return NULL;
const std::string user_id = manager->GetUserPresentingWindow(window);
return user_id.empty() ? NULL :
multi_user_util::GetProfileFromUserID(user_id);
#else
return NULL;
#endif
}
bool IsProfileFromActiveUser(Profile* profile) {
#if defined(OS_CHROMEOS)
return GetUserIDFromProfile(profile) ==
chromeos::UserManager::Get()->GetActiveUser()->email();
#else
return true;
#endif
}
const std::string& GetCurrentUserId() {
#if defined(OS_CHROMEOS)
return chromeos::UserManager::Get()->GetActiveUser()->email();
#else
return base::EmptyString();
#endif
}
void MoveWindowToCurrentDesktop(aura::Window* window) {
#if defined(OS_CHROMEOS)
chrome::MultiUserWindowManager::GetInstance()->ShowWindowForUser(
window,
GetCurrentUserId());
#endif
}
}