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" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
16 #include "google_apis/gaia/gaia_auth_util.h" | 17 #include "google_apis/gaia/gaia_auth_util.h" |
17 | 18 |
18 namespace policy { | 19 namespace policy { |
(...skipping 30 matching lines...) Expand all Loading... | |
49 break; | 50 break; |
50 case DeviceLocalAccount::TYPE_COUNT: | 51 case DeviceLocalAccount::TYPE_COUNT: |
51 NOTREACHED(); | 52 NOTREACHED(); |
52 break; | 53 break; |
53 } | 54 } |
54 return gaia::CanonicalizeEmail( | 55 return gaia::CanonicalizeEmail( |
55 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + | 56 base::HexEncode(account_id.c_str(), account_id.size()) + "@" + |
56 domain_prefix + kDeviceLocalAccountDomainSuffix); | 57 domain_prefix + kDeviceLocalAccountDomainSuffix); |
57 } | 58 } |
58 | 59 |
59 bool IsDeviceLocalAccountUser(const std::string& user_id) { | 60 bool IsDeviceLocalAccountUser(const std::string& user_id, |
60 return EndsWith(gaia::ExtractDomainName(user_id), | 61 DeviceLocalAccount::Type* type) { |
61 kDeviceLocalAccountDomainSuffix, | 62 const std::string domain = gaia::ExtractDomainName(user_id); |
62 true); | 63 if (!EndsWith(domain, kDeviceLocalAccountDomainSuffix, true)) |
63 } | 64 return false; |
64 | 65 |
65 bool IsKioskAppUser(const std::string& user_id) { | 66 const std::string domain_prefix = domain.substr( |
66 return gaia::ExtractDomainName(user_id) == | 67 0, domain.size() - arraysize(kDeviceLocalAccountDomainSuffix) + 1); |
67 std::string(kKioskAppAccountDomainPrefix) + | 68 |
68 kDeviceLocalAccountDomainSuffix; | 69 if (domain_prefix == kPublicAccountDomainPrefix) { |
70 if (type) | |
71 *type = DeviceLocalAccount::TYPE_PUBLIC_SESSION; | |
72 return true; | |
73 } | |
74 if (domain_prefix == kKioskAppAccountDomainPrefix) { | |
75 if (type) | |
76 *type = DeviceLocalAccount::TYPE_KIOSK_APP; | |
77 return true; | |
78 } | |
79 | |
80 // |user_id| is a device-local account but its type is not recognized. | |
81 NOTREACHED(); | |
pastarmovj
2013/10/02 14:44:50
I think it will be still good to set |type| to som
bartfab (slow)
2013/10/02 14:48:35
Done.
| |
82 return true; | |
69 } | 83 } |
70 | 84 |
71 void SetDeviceLocalAccounts( | 85 void SetDeviceLocalAccounts( |
72 chromeos::CrosSettings* cros_settings, | 86 chromeos::CrosSettings* cros_settings, |
73 const std::vector<DeviceLocalAccount>& accounts) { | 87 const std::vector<DeviceLocalAccount>& accounts) { |
74 base::ListValue list; | 88 base::ListValue list; |
75 for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin(); | 89 for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin(); |
76 it != accounts.end(); ++it) { | 90 it != accounts.end(); ++it) { |
77 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); | 91 scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue); |
78 entry->SetStringWithoutPathExpansion( | 92 entry->SetStringWithoutPathExpansion( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 continue; | 159 continue; |
146 } | 160 } |
147 | 161 |
148 accounts.push_back(DeviceLocalAccount( | 162 accounts.push_back(DeviceLocalAccount( |
149 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); | 163 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); |
150 } | 164 } |
151 return accounts; | 165 return accounts; |
152 } | 166 } |
153 | 167 |
154 } // namespace policy | 168 } // namespace policy |
OLD | NEW |