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/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/chromeos/login/user_manager.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
16 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
17 | 19 |
18 namespace policy { | 20 namespace policy { |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 const char kPublicAccountDomainPrefix[] = "public-accounts"; | 24 const char kPublicAccountDomainPrefix[] = "public-accounts"; |
23 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; | 25 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; |
(...skipping 25 matching lines...) Expand all Loading... |
49 break; | 51 break; |
50 case DeviceLocalAccount::TYPE_COUNT: | 52 case DeviceLocalAccount::TYPE_COUNT: |
51 NOTREACHED(); | 53 NOTREACHED(); |
52 break; | 54 break; |
53 } | 55 } |
54 return gaia::CanonicalizeEmail( | 56 return gaia::CanonicalizeEmail( |
55 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + | 57 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + |
56 domain_prefix + kDeviceLocalAccountDomainSuffix); | 58 domain_prefix + kDeviceLocalAccountDomainSuffix); |
57 } | 59 } |
58 | 60 |
59 bool IsDeviceLocalAccountUser(const std::string& user_id) { | 61 bool IsDeviceLocalAccountUser(const std::string& user_id, |
60 return EndsWith(gaia::ExtractDomainName(user_id), | 62 DeviceLocalAccount::Type* type) { |
61 kDeviceLocalAccountDomainSuffix, | 63 // For historical reasons, the guest user ID does not contain an @ symbol and |
62 true); | 64 // therefore, cannot be parsed by gaia::ExtractDomainName(). |
63 } | 65 if (user_id == chromeos::UserManager::kGuestUserName) |
| 66 return false; |
| 67 const std::string domain = gaia::ExtractDomainName(user_id); |
| 68 if (!EndsWith(domain, kDeviceLocalAccountDomainSuffix, true)) |
| 69 return false; |
64 | 70 |
65 bool IsKioskAppUser(const std::string& user_id) { | 71 const std::string domain_prefix = domain.substr( |
66 return gaia::ExtractDomainName(user_id) == | 72 0, domain.size() - arraysize(kDeviceLocalAccountDomainSuffix) + 1); |
67 std::string(kKioskAppAccountDomainPrefix) + | 73 |
68 kDeviceLocalAccountDomainSuffix; | 74 if (domain_prefix == kPublicAccountDomainPrefix) { |
| 75 if (type) |
| 76 *type = DeviceLocalAccount::TYPE_PUBLIC_SESSION; |
| 77 return true; |
| 78 } |
| 79 if (domain_prefix == kKioskAppAccountDomainPrefix) { |
| 80 if (type) |
| 81 *type = DeviceLocalAccount::TYPE_KIOSK_APP; |
| 82 return true; |
| 83 } |
| 84 |
| 85 // |user_id| is a device-local account but its type is not recognized. |
| 86 NOTREACHED(); |
| 87 if (type) |
| 88 *type = DeviceLocalAccount::TYPE_COUNT; |
| 89 return true; |
69 } | 90 } |
70 | 91 |
71 void SetDeviceLocalAccounts( | 92 void SetDeviceLocalAccounts( |
72 chromeos::CrosSettings* cros_settings, | 93 chromeos::CrosSettings* cros_settings, |
73 const std::vector<DeviceLocalAccount>& accounts) { | 94 const std::vector<DeviceLocalAccount>& accounts) { |
74 base::ListValue list; | 95 base::ListValue list; |
75 for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin(); | 96 for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin(); |
76 it != accounts.end(); ++it) { | 97 it != accounts.end(); ++it) { |
77 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 98 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
78 entry->SetStringWithoutPathExpansion( | 99 entry->SetStringWithoutPathExpansion( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 continue; | 166 continue; |
146 } | 167 } |
147 | 168 |
148 accounts.push_back(DeviceLocalAccount( | 169 accounts.push_back(DeviceLocalAccount( |
149 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); | 170 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); |
150 } | 171 } |
151 return accounts; | 172 return accounts; |
152 } | 173 } |
153 | 174 |
154 } // namespace policy | 175 } // namespace policy |
OLD | NEW |