OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/policy/device_local_account.h" | 5 #include "chrome/browser/chromeos/policy/device_local_account.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
17 #include "chromeos/login/user_names.h" | 17 #include "chromeos/login/user_names.h" |
18 #include "chromeos/settings/cros_settings_names.h" | 18 #include "chromeos/settings/cros_settings_names.h" |
| 19 #include "components/user_manager/user_id.h" |
19 #include "google_apis/gaia/gaia_auth_util.h" | 20 #include "google_apis/gaia/gaia_auth_util.h" |
20 | 21 |
21 namespace policy { | 22 namespace policy { |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
25 const char kPublicAccountDomainPrefix[] = "public-accounts"; | 26 const char kPublicAccountDomainPrefix[] = "public-accounts"; |
26 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; | 27 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; |
27 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; | 28 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 DeviceLocalAccount::DeviceLocalAccount(Type type, | 32 DeviceLocalAccount::DeviceLocalAccount(Type type, |
32 const std::string& account_id, | 33 const std::string& account_id, |
33 const std::string& kiosk_app_id, | 34 const std::string& kiosk_app_id, |
34 const std::string& kiosk_app_update_url) | 35 const std::string& kiosk_app_update_url) |
35 : type(type), | 36 : type(type), |
36 account_id(account_id), | 37 account_id(account_id), |
37 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), | 38 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), |
38 kiosk_app_id(kiosk_app_id), | 39 kiosk_app_id(kiosk_app_id), |
39 kiosk_app_update_url(kiosk_app_update_url) { | 40 kiosk_app_update_url(kiosk_app_update_url) { |
40 } | 41 } |
41 | 42 |
42 DeviceLocalAccount::~DeviceLocalAccount() { | 43 DeviceLocalAccount::~DeviceLocalAccount() { |
43 } | 44 } |
44 | 45 |
45 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, | 46 user_manager::UserID GenerateDeviceLocalAccountUserId(const std::string& account
_id, |
46 DeviceLocalAccount::Type type) { | 47 DeviceLocalAccount::Type type) { |
47 std::string domain_prefix; | 48 std::string domain_prefix; |
48 switch (type) { | 49 switch (type) { |
49 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: | 50 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: |
50 domain_prefix = kPublicAccountDomainPrefix; | 51 domain_prefix = kPublicAccountDomainPrefix; |
51 break; | 52 break; |
52 case DeviceLocalAccount::TYPE_KIOSK_APP: | 53 case DeviceLocalAccount::TYPE_KIOSK_APP: |
53 domain_prefix = kKioskAppAccountDomainPrefix; | 54 domain_prefix = kKioskAppAccountDomainPrefix; |
54 break; | 55 break; |
55 case DeviceLocalAccount::TYPE_COUNT: | 56 case DeviceLocalAccount::TYPE_COUNT: |
56 NOTREACHED(); | 57 NOTREACHED(); |
57 break; | 58 break; |
58 } | 59 } |
59 return gaia::CanonicalizeEmail( | 60 |
| 61 const std::string email = gaia::CanonicalizeEmail( |
60 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + | 62 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + |
61 domain_prefix + kDeviceLocalAccountDomainSuffix); | 63 domain_prefix + kDeviceLocalAccountDomainSuffix); |
| 64 return user_manager::UserID(std::string() /* gaia_id */, email); |
62 } | 65 } |
63 | 66 |
64 bool IsDeviceLocalAccountUser(const std::string& user_id, | 67 bool IsDeviceLocalAccountUser(const user_manager::UserID& user_id, |
65 DeviceLocalAccount::Type* type) { | 68 DeviceLocalAccount::Type* type) { |
66 // For historical reasons, the guest user ID does not contain an @ symbol and | 69 // For historical reasons, the guest user ID does not contain an @ symbol and |
67 // therefore, cannot be parsed by gaia::ExtractDomainName(). | 70 // therefore, cannot be parsed by gaia::ExtractDomainName(). |
68 if (user_id == chromeos::login::kGuestUserName) | 71 if (user_id == chromeos::login::GetGuestUserID()) |
69 return false; | 72 return false; |
70 const std::string domain = gaia::ExtractDomainName(user_id); | 73 const std::string domain = gaia::ExtractDomainName(user_id.GetUserEmail()); |
71 if (!EndsWith(domain, kDeviceLocalAccountDomainSuffix, true)) | 74 if (!EndsWith(domain, kDeviceLocalAccountDomainSuffix, true)) |
72 return false; | 75 return false; |
73 | 76 |
74 const std::string domain_prefix = domain.substr( | 77 const std::string domain_prefix = domain.substr( |
75 0, domain.size() - arraysize(kDeviceLocalAccountDomainSuffix) + 1); | 78 0, domain.size() - arraysize(kDeviceLocalAccountDomainSuffix) + 1); |
76 | 79 |
77 if (domain_prefix == kPublicAccountDomainPrefix) { | 80 if (domain_prefix == kPublicAccountDomainPrefix) { |
78 if (type) | 81 if (type) |
79 *type = DeviceLocalAccount::TYPE_PUBLIC_SESSION; | 82 *type = DeviceLocalAccount::TYPE_PUBLIC_SESSION; |
80 return true; | 83 return true; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 accounts.push_back( | 183 accounts.push_back( |
181 DeviceLocalAccount(static_cast<DeviceLocalAccount::Type>(type), | 184 DeviceLocalAccount(static_cast<DeviceLocalAccount::Type>(type), |
182 account_id, | 185 account_id, |
183 kiosk_app_id, | 186 kiosk_app_id, |
184 kiosk_app_update_url)); | 187 kiosk_app_update_url)); |
185 } | 188 } |
186 return accounts; | 189 return accounts; |
187 } | 190 } |
188 | 191 |
189 } // namespace policy | 192 } // namespace policy |
OLD | NEW |