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

Unified 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: Comments addressed. Kiosk apps fixed. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/device_local_account.cc
diff --git a/chrome/browser/chromeos/policy/device_local_account.cc b/chrome/browser/chromeos/policy/device_local_account.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4cfcf5c0014a89bcaa9f909ba2dfaebddd7bbb9
--- /dev/null
+++ b/chrome/browser/chromeos/policy/device_local_account.cc
@@ -0,0 +1,157 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/device_local_account.h"
+
+#include <set>
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_number_conversions.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/settings/cros_settings.h"
+#include "chrome/browser/chromeos/settings/cros_settings_names.h"
+#include "google_apis/gaia/gaia_auth_util.h"
+
+namespace policy {
+
+namespace {
+
+const char kPublicAccountDomainPrefix[] = "public-accounts";
+
Mattias Nissler (ping if slow) 2013/05/17 14:29:44 nit: you can nuke the newlines between the constan
bartfab (slow) 2013/05/17 16:08:47 Done.
+const char kKioskAppAccountDomainPrefix[] = "kiosk-apps";
+
+const char kDeviceLocalAccountDomainSuffix[] = ".device-local.localhost";
+
+} // namespace
+
+DeviceLocalAccount::DeviceLocalAccount(Type type,
+ const std::string& account_id,
+ const std::string& kiosk_app_id,
+ const std::string& kiosk_app_update_url)
+ : type(type),
+ account_id(account_id),
+ user_id(GenerateDeviceLocalAccountUserId(account_id, type)),
+ kiosk_app_id(kiosk_app_id),
+ kiosk_app_update_url(kiosk_app_update_url) {
+}
+
+std::string GenerateDeviceLocalAccountUserId(const std::string& account_id,
+ DeviceLocalAccount::Type type) {
+ std::string domain_prefix;
+ switch (type) {
+ case DeviceLocalAccount::TYPE_PUBLIC_SESSION:
+ domain_prefix = kPublicAccountDomainPrefix;
+ break;
+ case DeviceLocalAccount::TYPE_KIOSK_APP:
+ domain_prefix = kKioskAppAccountDomainPrefix;
+ break;
+ case DeviceLocalAccount::TYPE_COUNT:
+ NOTREACHED();
+ break;
+ }
+ return base::HexEncode(account_id.c_str(), account_id.size()) + "@" +
+ domain_prefix + kDeviceLocalAccountDomainSuffix;
+}
+
+bool IsKioskAppUser(const std::string& user_id) {
+ return gaia::ExtractDomainName(user_id) ==
+ std::string(kKioskAppAccountDomainPrefix) +
+ kDeviceLocalAccountDomainSuffix;
+}
+
+void SetDeviceLocalAccounts(
+ chromeos::CrosSettings* cros_settings,
+ const std::vector<DeviceLocalAccount>& accounts) {
+ scoped_ptr<base::ListValue> list(new base::ListValue);
+ for (std::vector<DeviceLocalAccount>::const_iterator it = accounts.begin();
+ it != accounts.end(); ++it) {
+ scoped_ptr<base::DictionaryValue> entry(new base::DictionaryValue);
+ entry->SetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyId,
+ it->account_id);
+ entry->SetIntegerWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyType,
+ it->type);
+ if (it->type == DeviceLocalAccount::TYPE_KIOSK_APP) {
+ entry->SetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
+ it->kiosk_app_id);
+ if (!it->kiosk_app_update_url.empty()) {
+ entry->SetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
+ it->kiosk_app_update_url);
+ }
+ }
+ list->Append(entry.release());
+ }
+
+ cros_settings->Set(chromeos::kAccountsPrefDeviceLocalAccounts, *list);
+}
+
+std::vector<DeviceLocalAccount> GetDeviceLocalAccounts(
+ chromeos::CrosSettings* cros_settings) {
+ std::vector<DeviceLocalAccount> accounts;
+
+ const base::ListValue* list = NULL;
+ cros_settings->GetList(chromeos::kAccountsPrefDeviceLocalAccounts, &list);
+ if (!list)
+ return accounts;
+
+ std::set<std::string> account_ids;
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ const base::DictionaryValue* entry = NULL;
+ if (!list->GetDictionary(i, &entry)) {
+ LOG(ERROR) << "Corrupt entry in device-local account list at index " << i
+ << ".";
+ continue;
+ }
+
+ std::string account_id;
+ if (!entry->GetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyId, &account_id) ||
+ account_id.empty()) {
+ LOG(ERROR) << "Missing account ID in device-local account list at index "
+ << i << ".";
+ continue;
+ }
+
+ int type;
+ if (!entry->GetIntegerWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyType, &type) ||
+ type < 0 || type >= DeviceLocalAccount::TYPE_COUNT) {
+ LOG(ERROR) << "Missing or invalid account type in device-local account "
+ << "list at index " << i << ".";
+ continue;
+ }
+
+ std::string kiosk_app_id;
+ std::string kiosk_app_update_url;
+ if (type == DeviceLocalAccount::TYPE_KIOSK_APP) {
+ if (!entry->GetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppId,
+ &kiosk_app_id)) {
+ LOG(ERROR) << "Missing app ID in device-local account entry at index "
+ << i << ".";
+ continue;
+ }
+ entry->GetStringWithoutPathExpansion(
+ chromeos::kAccountsPrefDeviceLocalAccountsKeyKioskAppUpdateURL,
+ &kiosk_app_update_url);
+ }
+
+ if (!account_ids.insert(account_id).second) {
+ LOG(ERROR) << "Duplicate entry in device-local account list at index "
+ << i << ": " << account_id << ".";
+ continue;
+ }
+
+ accounts.push_back(DeviceLocalAccount(
+ static_cast<DeviceLocalAccount::Type>(type),
+ account_id, kiosk_app_id, kiosk_app_update_url));
+ }
+ return accounts;
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698