| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 const char kPublicAccountDomainPrefix[] = "public-accounts"; | 24 const char kPublicAccountDomainPrefix[] = "public-accounts"; |
| 25 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; | 25 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; |
| 26 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; | 26 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 DeviceLocalAccount::DeviceLocalAccount(Type type, | 30 DeviceLocalAccount::DeviceLocalAccount(Type type, |
| 31 const std::string& account_id, | 31 const std::string& account_id, |
| 32 const std::string& kiosk_app_id) | 32 const std::string& kiosk_app_id, |
| 33 const std::string& kiosk_app_update_url) |
| 33 : type(type), | 34 : type(type), |
| 34 account_id(account_id), | 35 account_id(account_id), |
| 35 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), | 36 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), |
| 36 kiosk_app_id(kiosk_app_id) { | 37 kiosk_app_id(kiosk_app_id), |
| 38 kiosk_app_update_url(kiosk_app_update_url) { |
| 37 } | 39 } |
| 38 | 40 |
| 39 DeviceLocalAccount::~DeviceLocalAccount() { | 41 DeviceLocalAccount::~DeviceLocalAccount() { |
| 40 } | 42 } |
| 41 | 43 |
| 42 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, | 44 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, |
| 43 DeviceLocalAccount::Type type) { | 45 DeviceLocalAccount::Type type) { |
| 44 std::string domain_prefix; | 46 std::string domain_prefix; |
| 45 switch (type) { | 47 switch (type) { |
| 46 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: | 48 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 entry->SetStringWithoutPathExpansion( | 101 entry->SetStringWithoutPathExpansion( |
| 100 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, | 102 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, |
| 101 it->account_id); | 103 it->account_id); |
| 102 entry->SetIntegerWithoutPathExpansion( | 104 entry->SetIntegerWithoutPathExpansion( |
| 103 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, | 105 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, |
| 104 it->type); | 106 it->type); |
| 105 if (it->type == DeviceLocalAccount::TYPE_KIOSK_APP) { | 107 if (it->type == DeviceLocalAccount::TYPE_KIOSK_APP) { |
| 106 entry->SetStringWithoutPathExpansion( | 108 entry->SetStringWithoutPathExpansion( |
| 107 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 109 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| 108 it->kiosk_app_id); | 110 it->kiosk_app_id); |
| 111 if (!it->kiosk_app_update_url.empty()) { |
| 112 entry->SetStringWithoutPathExpansion( |
| 113 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, |
| 114 it->kiosk_app_update_url); |
| 115 } |
| 109 } | 116 } |
| 110 list.Append(entry.release()); | 117 list.Append(entry.release()); |
| 111 } | 118 } |
| 112 | 119 |
| 113 cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); | 120 cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); |
| 114 } | 121 } |
| 115 | 122 |
| 116 std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( | 123 std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( |
| 117 chromeos::CrosSettings* cros_settings) { | 124 chromeos::CrosSettings* cros_settings) { |
| 118 std::vector<DeviceLocalAccount> accounts; | 125 std::vector<DeviceLocalAccount> accounts; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 143 int type; | 150 int type; |
| 144 if (!entry->GetIntegerWithoutPathExpansion( | 151 if (!entry->GetIntegerWithoutPathExpansion( |
| 145 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) || | 152 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) || |
| 146 type < 0 || type >= DeviceLocalAccount::TYPE_COUNT) { | 153 type < 0 || type >= DeviceLocalAccount::TYPE_COUNT) { |
| 147 LOG(ERROR) << "Missing or invalid account type in device-local account " | 154 LOG(ERROR) << "Missing or invalid account type in device-local account " |
| 148 << "list at index " << i << "."; | 155 << "list at index " << i << "."; |
| 149 continue; | 156 continue; |
| 150 } | 157 } |
| 151 | 158 |
| 152 std::string kiosk_app_id; | 159 std::string kiosk_app_id; |
| 160 std::string kiosk_app_update_url; |
| 153 if (type == DeviceLocalAccount::TYPE_KIOSK_APP) { | 161 if (type == DeviceLocalAccount::TYPE_KIOSK_APP) { |
| 154 if (!entry->GetStringWithoutPathExpansion( | 162 if (!entry->GetStringWithoutPathExpansion( |
| 155 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 163 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
| 156 &kiosk_app_id)) { | 164 &kiosk_app_id)) { |
| 157 LOG(ERROR) << "Missing app ID in device-local account entry at index " | 165 LOG(ERROR) << "Missing app ID in device-local account entry at index " |
| 158 << i << "."; | 166 << i << "."; |
| 159 continue; | 167 continue; |
| 160 } | 168 } |
| 169 entry->GetStringWithoutPathExpansion( |
| 170 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, |
| 171 &kiosk_app_update_url); |
| 161 } | 172 } |
| 162 | 173 |
| 163 if (!account_ids.insert(account_id).second) { | 174 if (!account_ids.insert(account_id).second) { |
| 164 LOG(ERROR) << "Duplicate entry in device-local account list at index " | 175 LOG(ERROR) << "Duplicate entry in device-local account list at index " |
| 165 << i << ": " << account_id << "."; | 176 << i << ": " << account_id << "."; |
| 166 continue; | 177 continue; |
| 167 } | 178 } |
| 168 | 179 |
| 169 accounts.push_back(DeviceLocalAccount( | 180 accounts.push_back( |
| 170 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); | 181 DeviceLocalAccount(static_cast<DeviceLocalAccount::Type>(type), |
| 182 account_id, |
| 183 kiosk_app_id, |
| 184 kiosk_app_update_url)); |
| 171 } | 185 } |
| 172 return accounts; | 186 return accounts; |
| 173 } | 187 } |
| 174 | 188 |
| 175 } // namespace policy | 189 } // namespace policy |
| OLD | NEW |