Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/policy/device_local_account.h"
6
7 #include <set>
8
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/values.h"
12 #include "chrome/browser/chromeos/settings/cros_settings_names.h"
13 #include "crypto/sha2.h"
14
15 namespace policy {
16
17 namespace {
18
19 static const char kPublicAccountDomainPrefix[] = "public-accounts";
Mattias Nissler (ping if slow) 2013/05/15 08:46:40 no need for static
bartfab (slow) 2013/05/17 11:14:28 Done.
20
21 static const char kKioskAppAccountDomainPrefix[] = "kiosk-apps";
22
23 static const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost";
24
25 } // namespace
26
27 DeviceLocalAccount::DeviceLocalAccount(Type type,
28 const std::string& account_id,
29 const std::string& kiosk_app_id,
30 const std::string& kiosk_app_update_url)
31 : type(type),
32 account_id(account_id),
33 user_id(GenerateDeviceLocalAccountUserId(account_id, type)),
34 kiosk_app_id(kiosk_app_id),
35 kiosk_app_update_url(kiosk_app_update_url) {
36 }
37
38 std::string GenerateDeviceLocalAccountUserId(const std::string& account_id,
39 DeviceLocalAccount::Type type) {
40 std::string domain_prefix;
41 switch (type) {
42 case DeviceLocalAccount::TYPE_PUBLIC_SESSION:
43 domain_prefix = kPublicAccountDomainPrefix;
44 break;
45 case DeviceLocalAccount::TYPE_KIOSK_APP:
46 domain_prefix = kKioskAppAccountDomainPrefix;
47 break;
48 case DeviceLocalAccount::TYPE_COUNT:
49 NOTREACHED();
50 break;
51 }
52 char hash[crypto::kSHA256Length];
53 crypto::SHA256HashString(account_id, &hash, sizeof(hash));
Mattias Nissler (ping if slow) 2013/05/15 08:46:40 Is this fast enough?
bartfab (slow) 2013/05/17 11:14:28 Good point. Actually, hashing is completely unnece
54 return base::HexEncode(&hash, sizeof(hash)) + "@" +
Mattias Nissler (ping if slow) 2013/05/15 08:46:40 I think Xiyuan mentioned something about requiring
bartfab (slow) 2013/05/17 11:14:28 Thanks for reminding me of that. I talked to Xiyua
55 domain_prefix + kDeviceLocalAccountDomainSuffix;
56 }
57
58 std::vector<DeviceLocalAccount> DecodeDeviceLocalAccountsList(
59 const base::ListValue* list) {
60 std::vector<DeviceLocalAccount> accounts;
61 if (!list)
62 return accounts;
63
64 std::set<std::string> account_ids;
65 for (size_t i = 0; i < list->GetSize(); ++i) {
66 const base::DictionaryValue* entry = NULL;
67 std::string account_id;
68 int type;
69 std::string kiosk_app_id;
70 if (!list->GetDictionary(i, &entry) ||
71 !entry->GetStringWithoutPathExpansion(
72 chromeos::kAccountsPrefDeviceLocalAccountsKeyId, &account_id) ||
73 account_id.empty() ||
74 !entry->GetIntegerWithoutPathExpansion(
75 chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) ||
76 type < 0 || type >= DeviceLocalAccount::TYPE_COUNT ||
77 (type == DeviceLocalAccount::TYPE_KIOSK_APP &&
78 !entry->GetStringWithoutPathExpansion(
79 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
80 &kiosk_app_id))) {
Mattias Nissler (ping if slow) 2013/05/15 08:46:40 This conditional is too long. Please break it up -
bartfab (slow) 2013/05/17 11:14:28 Done.
81 LOG(ERROR) << "Corrupt entry in device-local account list at index " << i
82 << ".";
83 continue;
84 }
85 std::string kiosk_app_update_url;
86 if (type == DeviceLocalAccount::TYPE_KIOSK_APP) {
87 entry->GetStringWithoutPathExpansion(
88 chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
89 &kiosk_app_update_url);
90 }
91 if (!account_ids.insert(account_id).second) {
Mattias Nissler (ping if slow) 2013/05/15 08:46:40 account_ids is a set - how can this access second?
bartfab (slow) 2013/05/17 11:14:28 std::set::insert() returns an std::pair. The secon
92 LOG(ERROR) << "Duplicate entry in device-local account list at index "
93 << i << ": " << account_id << ".";
94 continue;
95 }
96 accounts.push_back(DeviceLocalAccount(
97 static_cast<DeviceLocalAccount::Type>(type),
98 account_id, kiosk_app_id, kiosk_app_update_url));
99 }
100 return accounts;
101 }
102
103 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698