Disable TabDragController tests that fail with a real compositor.
[chromium-blink-merge.git] / chrome / browser / ui / ash / multi_user / multi_user_util.cc
blob0d9250d4c135ee952193679eb3745249965b5892
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
7 #include <vector>
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_manager.h"
12 #include "google_apis/gaia/gaia_auth_util.h"
14 #if defined(OS_CHROMEOS)
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
17 #endif
19 namespace multi_user_util {
21 std::string GetUserIDFromProfile(Profile* profile) {
22 return GetUserIDFromEmail(profile->GetOriginalProfile()->GetProfileName());
25 std::string GetUserIDFromEmail(const std::string& email) {
26 // |email| and profile name could be empty if not yet logged in or guest mode.
27 return email.empty() ?
28 email : gaia::CanonicalizeEmail(gaia::SanitizeEmail(email));
31 Profile* GetProfileFromUserID(const std::string& user_id) {
32 // Unit tests can end up here without a |g_browser_process|.
33 if (!g_browser_process || !g_browser_process->profile_manager())
34 return NULL;
36 std::vector<Profile*> profiles =
37 g_browser_process->profile_manager()->GetLoadedProfiles();
39 std::vector<Profile*>::const_iterator profile_iterator = profiles.begin();
40 for (; profile_iterator != profiles.end(); ++profile_iterator) {
41 if (GetUserIDFromProfile(*profile_iterator) == user_id)
42 return *profile_iterator;
44 return NULL;
47 Profile* GetProfileFromWindow(aura::Window* window) {
48 #if defined(OS_CHROMEOS)
49 chrome::MultiUserWindowManager* manager =
50 chrome::MultiUserWindowManager::GetInstance();
51 // We might come here before the manager got created - or in a unit test.
52 if (!manager)
53 return NULL;
54 const std::string user_id = manager->GetUserPresentingWindow(window);
55 return user_id.empty() ? NULL :
56 multi_user_util::GetProfileFromUserID(user_id);
57 #else
58 return NULL;
59 #endif
62 bool IsProfileFromActiveUser(Profile* profile) {
63 #if defined(OS_CHROMEOS)
64 return GetUserIDFromProfile(profile) ==
65 chromeos::UserManager::Get()->GetActiveUser()->email();
66 #else
67 // In non Chrome OS configurations this will be always true since this only
68 // makes sense in separate desktop mode.
69 return true;
70 #endif
73 } // namespace multi_user_util