OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/user_manager.h" | 5 #include "chrome/browser/chromeos/login/user_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | |
8 #include "chrome/browser/chromeos/login/user_manager_impl.h" | 9 #include "chrome/browser/chromeos/login/user_manager_impl.h" |
10 #include "chrome/common/extensions/extension.h" | |
9 | 11 |
10 namespace chromeos { | 12 namespace chromeos { |
11 | 13 |
12 // static | 14 // static |
13 const char UserManager::kStubUser[] = "stub-user@example.com"; | 15 const char UserManager::kStubUser[] = "stub-user@example.com"; |
14 | 16 |
15 // static | 17 // static |
16 const char UserManager::kLocallyManagedUserDomain[] = | 18 const char UserManager::kLocallyManagedUserDomain[] = |
17 "locally-managed.localhost"; | 19 "locally-managed.localhost"; |
18 | 20 |
(...skipping 28 matching lines...) Expand all Loading... | |
47 UserManager::~UserManager() { | 49 UserManager::~UserManager() { |
48 } | 50 } |
49 | 51 |
50 // static | 52 // static |
51 UserManager* UserManager::SetForTesting(UserManager* user_manager) { | 53 UserManager* UserManager::SetForTesting(UserManager* user_manager) { |
52 UserManager* previous_user_manager = g_user_manager; | 54 UserManager* previous_user_manager = g_user_manager; |
53 g_user_manager = user_manager; | 55 g_user_manager = user_manager; |
54 return previous_user_manager; | 56 return previous_user_manager; |
55 } | 57 } |
56 | 58 |
59 // static | |
60 bool UserManager::ParseKioskAppUserId(const std::string& user_id, | |
61 std::string* app_id) { | |
62 const std::string suffix(std::string("@") + kKioskAppUserDomain); | |
bartfab (slow)
2013/04/23 15:59:40
Why not use gaia::ExtractDomainName()?
Mattias Nissler (ping if slow)
2013/04/23 18:28:10
Because I need the part left to the @ without, and
| |
63 if (EndsWith(user_id, suffix, false)) { | |
64 const std::string candidate_app_id( | |
65 user_id.substr(0, user_id.size() - suffix.size())); | |
66 if (extensions::Extension::IdIsValid(candidate_app_id)) { | |
67 *app_id = candidate_app_id; | |
68 return true; | |
69 } | |
70 } | |
71 | |
72 return false; | |
73 } | |
74 | |
75 // static | |
76 std::string UserManager::FormatKioskAppUserId(const std::string& app_id) { | |
77 DCHECK(extensions::Extension::IdIsValid(app_id)); | |
78 return app_id + '@' + kKioskAppUserDomain; | |
79 } | |
80 | |
57 ScopedUserManagerEnabler::ScopedUserManagerEnabler(UserManager* user_manager) | 81 ScopedUserManagerEnabler::ScopedUserManagerEnabler(UserManager* user_manager) |
58 : previous_user_manager_(UserManager::SetForTesting(user_manager)) { | 82 : previous_user_manager_(UserManager::SetForTesting(user_manager)) { |
59 } | 83 } |
60 | 84 |
61 ScopedUserManagerEnabler::~ScopedUserManagerEnabler() { | 85 ScopedUserManagerEnabler::~ScopedUserManagerEnabler() { |
62 UserManager::Get()->Shutdown(); | 86 UserManager::Get()->Shutdown(); |
63 UserManager::Destroy(); | 87 UserManager::Destroy(); |
64 UserManager::SetForTesting(previous_user_manager_); | 88 UserManager::SetForTesting(previous_user_manager_); |
65 } | 89 } |
66 | 90 |
67 ScopedTestUserManager::ScopedTestUserManager() | 91 ScopedTestUserManager::ScopedTestUserManager() |
68 : initialized_user_manager_(false) { | 92 : initialized_user_manager_(false) { |
69 if (!UserManager::IsInitialized()) { | 93 if (!UserManager::IsInitialized()) { |
70 UserManager::Initialize(); | 94 UserManager::Initialize(); |
71 initialized_user_manager_ = true; | 95 initialized_user_manager_ = true; |
72 } | 96 } |
73 } | 97 } |
74 | 98 |
75 ScopedTestUserManager::~ScopedTestUserManager() { | 99 ScopedTestUserManager::~ScopedTestUserManager() { |
76 if (initialized_user_manager_) { | 100 if (initialized_user_manager_) { |
77 UserManager::Get()->Shutdown(); | 101 UserManager::Get()->Shutdown(); |
78 UserManager::Destroy(); | 102 UserManager::Destroy(); |
79 } | 103 } |
80 } | 104 } |
81 | 105 |
82 } // namespace chromeos | 106 } // namespace chromeos |
OLD | NEW |