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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
16 #include "google_apis/gaia/gaia_auth_util.h" | 16 #include "google_apis/gaia/gaia_auth_util.h" |
17 | 17 |
18 namespace policy { | 18 namespace policy { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kPublicAccountDomainPrefix[] = "public-accounts"; | 22 const char kPublicAccountDomainPrefix[] = "public-accounts"; |
23 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; | 23 const char kKioskAppAccountDomainPrefix[] = "kiosk-apps"; |
24 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; | 24 const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost"; |
25 | 25 |
26 } // namespace | 26 } // namespace |
27 | 27 |
28 DeviceLocalAccount::DeviceLocalAccount(Type type, | 28 DeviceLocalAccount::DeviceLocalAccount(Type type, |
29 const std::string& account_id, | 29 const std::string& account_id, |
30 const std::string& kiosk_app_id, | 30 const std::string& kiosk_app_id) |
31 const std::string& kiosk_app_update_url) | |
32 : type(type), | 31 : type(type), |
33 account_id(account_id), | 32 account_id(account_id), |
34 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), | 33 user_id(GenerateDeviceLocalAccountUserId(account_id, type)), |
35 kiosk_app_id(kiosk_app_id), | 34 kiosk_app_id(kiosk_app_id) { |
36 kiosk_app_update_url(kiosk_app_update_url) { | |
37 } | 35 } |
38 | 36 |
39 DeviceLocalAccount::~DeviceLocalAccount() { | 37 DeviceLocalAccount::~DeviceLocalAccount() { |
40 } | 38 } |
41 | 39 |
42 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, | 40 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id, |
43 DeviceLocalAccount::Type type) { | 41 DeviceLocalAccount::Type type) { |
44 std::string domain_prefix; | 42 std::string domain_prefix; |
45 switch (type) { | 43 switch (type) { |
46 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: | 44 case DeviceLocalAccount::TYPE_PUBLIC_SESSION: |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 entry->SetStringWithoutPathExpansion( | 78 entry->SetStringWithoutPathExpansion( |
81 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, | 79 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, |
82 it->account_id); | 80 it->account_id); |
83 entry->SetIntegerWithoutPathExpansion( | 81 entry->SetIntegerWithoutPathExpansion( |
84 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, | 82 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, |
85 it->type); | 83 it->type); |
86 if (it->type == DeviceLocalAccount::TYPE_KIOSK_APP) { | 84 if (it->type == DeviceLocalAccount::TYPE_KIOSK_APP) { |
87 entry->SetStringWithoutPathExpansion( | 85 entry->SetStringWithoutPathExpansion( |
88 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 86 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
89 it->kiosk_app_id); | 87 it->kiosk_app_id); |
90 if (!it->kiosk_app_update_url.empty()) { | |
91 entry->SetStringWithoutPathExpansion( | |
92 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, | |
93 it->kiosk_app_update_url); | |
94 } | |
95 } | 88 } |
96 list.Append(entry.release()); | 89 list.Append(entry.release()); |
97 } | 90 } |
98 | 91 |
99 cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); | 92 cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, list); |
100 } | 93 } |
101 | 94 |
102 std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( | 95 std::vector<DeviceLocalAccount> GetDeviceLocalAccounts( |
103 chromeos::CrosSettings* cros_settings) { | 96 chromeos::CrosSettings* cros_settings) { |
104 std::vector<DeviceLocalAccount> accounts; | 97 std::vector<DeviceLocalAccount> accounts; |
(...skipping 24 matching lines...) Expand all Loading... |
129 int type; | 122 int type; |
130 if (!entry->GetIntegerWithoutPathExpansion( | 123 if (!entry->GetIntegerWithoutPathExpansion( |
131 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) || | 124 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) || |
132 type < 0 || type >= DeviceLocalAccount::TYPE_COUNT) { | 125 type < 0 || type >= DeviceLocalAccount::TYPE_COUNT) { |
133 LOG(ERROR) << "Missing or invalid account type in device-local account " | 126 LOG(ERROR) << "Missing or invalid account type in device-local account " |
134 << "list at index " << i << "."; | 127 << "list at index " << i << "."; |
135 continue; | 128 continue; |
136 } | 129 } |
137 | 130 |
138 std::string kiosk_app_id; | 131 std::string kiosk_app_id; |
139 std::string kiosk_app_update_url; | |
140 if (type == DeviceLocalAccount::TYPE_KIOSK_APP) { | 132 if (type == DeviceLocalAccount::TYPE_KIOSK_APP) { |
141 if (!entry->GetStringWithoutPathExpansion( | 133 if (!entry->GetStringWithoutPathExpansion( |
142 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, | 134 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId, |
143 &kiosk_app_id)) { | 135 &kiosk_app_id)) { |
144 LOG(ERROR) << "Missing app ID in device-local account entry at index " | 136 LOG(ERROR) << "Missing app ID in device-local account entry at index " |
145 << i << "."; | 137 << i << "."; |
146 continue; | 138 continue; |
147 } | 139 } |
148 entry->GetStringWithoutPathExpansion( | |
149 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL, | |
150 &kiosk_app_update_url); | |
151 } | 140 } |
152 | 141 |
153 if (!account_ids.insert(account_id).second) { | 142 if (!account_ids.insert(account_id).second) { |
154 LOG(ERROR) << "Duplicate entry in device-local account list at index " | 143 LOG(ERROR) << "Duplicate entry in device-local account list at index " |
155 << i << ": " << account_id << "."; | 144 << i << ": " << account_id << "."; |
156 continue; | 145 continue; |
157 } | 146 } |
158 | 147 |
159 accounts.push_back(DeviceLocalAccount( | 148 accounts.push_back(DeviceLocalAccount( |
160 static_cast<DeviceLocalAccount::Type>(type), | 149 static_cast<DeviceLocalAccount::Type>(type), account_id, kiosk_app_id)); |
161 account_id, kiosk_app_id, kiosk_app_update_url)); | |
162 } | 150 } |
163 return accounts; | 151 return accounts; |
164 } | 152 } |
165 | 153 |
166 } // namespace policy | 154 } // namespace policy |
OLD | NEW |