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

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

Issue 397543005: Encapsulate data-format constants in EnterpriseInstallAttributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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
« no previous file with comments | « chrome/browser/chromeos/policy/enterprise_install_attributes.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/enterprise_install_attributes.h" 5 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" 14 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h"
15 #include "chromeos/cryptohome/cryptohome_util.h" 15 #include "chromeos/cryptohome/cryptohome_util.h"
16 #include "chromeos/dbus/dbus_thread_manager.h" 16 #include "chromeos/dbus/dbus_thread_manager.h"
17 #include "google_apis/gaia/gaia_auth_util.h" 17 #include "google_apis/gaia/gaia_auth_util.h"
18 18
19 namespace policy { 19 namespace policy {
20 20
21 namespace cryptohome_util = chromeos::cryptohome_util; 21 namespace cryptohome_util = chromeos::cryptohome_util;
22 22
23 namespace { 23 namespace {
24 24
25 // Translates DeviceMode constants to strings used in the lockbox.
26 std::string GetDeviceModeString(DeviceMode mode) {
27 switch (mode) {
28 case DEVICE_MODE_CONSUMER:
29 return EnterpriseInstallAttributes::kConsumerDeviceMode;
30 case DEVICE_MODE_ENTERPRISE:
31 return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
32 case DEVICE_MODE_RETAIL_KIOSK:
33 return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
34 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
35 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
36 case DEVICE_MODE_PENDING:
37 case DEVICE_MODE_NOT_SET:
38 break;
39 }
40 NOTREACHED() << "Invalid device mode: " << mode;
41 return EnterpriseInstallAttributes::kUnknownDeviceMode;
42 }
43
44 // Translates strings used in the lockbox to DeviceMode values.
45 DeviceMode GetDeviceModeFromString(
46 const std::string& mode) {
47 if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
48 return DEVICE_MODE_CONSUMER;
49 else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
50 return DEVICE_MODE_ENTERPRISE;
51 else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
52 return DEVICE_MODE_RETAIL_KIOSK;
53 else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
54 return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
55 NOTREACHED() << "Unknown device mode string: " << mode;
56 return DEVICE_MODE_NOT_SET;
57 }
58
59 bool ReadMapKey(const std::map<std::string, std::string>& map, 25 bool ReadMapKey(const std::map<std::string, std::string>& map,
60 const std::string& key, 26 const std::string& key,
61 std::string* value) { 27 std::string* value) {
62 std::map<std::string, std::string>::const_iterator entry = map.find(key); 28 std::map<std::string, std::string>::const_iterator entry = map.find(key);
63 if (entry == map.end()) 29 if (entry == map.end())
64 return false; 30 return false;
65 31
66 *value = entry->second; 32 *value = entry->second;
67 return true; 33 return true;
68 } 34 }
69 35
70 } // namespace 36 } // namespace
71 37
72 const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer"; 38 // static
73 const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise"; 39 std::string
74 const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk"; 40 EnterpriseInstallAttributes::GetEnterpriseOwnedInstallAttributesBlobForTesting(
75 const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] = 41 const std::string& user_name) {
76 "consumer_kiosk"; 42 cryptohome::SerializedInstallAttributes install_attrs_proto;
77 const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown"; 43 cryptohome::SerializedInstallAttributes::Attribute* attribute = NULL;
78 44
79 const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] = 45 attribute = install_attrs_proto.add_attributes();
80 "enterprise.device_id"; 46 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseOwned);
81 const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] = 47 attribute->set_value("true");
82 "enterprise.domain"; 48
83 const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] = 49 attribute = install_attrs_proto.add_attributes();
84 "enterprise.mode"; 50 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser);
85 const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] = 51 attribute->set_value(user_name);
86 "enterprise.owned"; 52
87 const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] = 53 return install_attrs_proto.SerializeAsString();
88 "enterprise.user"; 54 }
89 const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
90 "consumer.app_kiosk_enabled";
91 55
92 EnterpriseInstallAttributes::EnterpriseInstallAttributes( 56 EnterpriseInstallAttributes::EnterpriseInstallAttributes(
93 chromeos::CryptohomeClient* cryptohome_client) 57 chromeos::CryptohomeClient* cryptohome_client)
94 : device_locked_(false), 58 : device_locked_(false),
95 registration_mode_(DEVICE_MODE_PENDING), 59 registration_mode_(DEVICE_MODE_PENDING),
96 cryptohome_client_(cryptohome_client), 60 cryptohome_client_(cryptohome_client),
97 weak_ptr_factory_(this) { 61 weak_ptr_factory_(this) {
98 } 62 }
99 63
100 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {} 64 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {}
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 if (!IsEnterpriseDevice()) 290 if (!IsEnterpriseDevice())
327 return std::string(); 291 return std::string();
328 292
329 return registration_device_id_; 293 return registration_device_id_;
330 } 294 }
331 295
332 DeviceMode EnterpriseInstallAttributes::GetMode() { 296 DeviceMode EnterpriseInstallAttributes::GetMode() {
333 return registration_mode_; 297 return registration_mode_;
334 } 298 }
335 299
300 // Note that some of these constants have been copied to
301 // login_manager/device_policy_service.cc.
pastarmovj 2014/07/16 15:01:57 Please add one more sentence along the lines that
Thiemo Nagel 2014/07/16 15:11:07 Done.
302 const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer";
303 const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise";
304 const char EnterpriseInstallAttributes::kRetailKioskDeviceMode[] = "kiosk";
305 const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] =
306 "consumer_kiosk";
307 const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown";
308
309 const char EnterpriseInstallAttributes::kAttrEnterpriseDeviceId[] =
310 "enterprise.device_id";
311 const char EnterpriseInstallAttributes::kAttrEnterpriseDomain[] =
312 "enterprise.domain";
313 const char EnterpriseInstallAttributes::kAttrEnterpriseMode[] =
314 "enterprise.mode";
315 const char EnterpriseInstallAttributes::kAttrEnterpriseOwned[] =
316 "enterprise.owned";
317 const char EnterpriseInstallAttributes::kAttrEnterpriseUser[] =
318 "enterprise.user";
319 const char EnterpriseInstallAttributes::kAttrConsumerKioskEnabled[] =
320 "consumer.app_kiosk_enabled";
321
322 std::string EnterpriseInstallAttributes::GetDeviceModeString(DeviceMode mode) {
323 switch (mode) {
324 case DEVICE_MODE_CONSUMER:
325 return EnterpriseInstallAttributes::kConsumerDeviceMode;
326 case DEVICE_MODE_ENTERPRISE:
327 return EnterpriseInstallAttributes::kEnterpriseDeviceMode;
328 case DEVICE_MODE_RETAIL_KIOSK:
329 return EnterpriseInstallAttributes::kRetailKioskDeviceMode;
330 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH:
331 return EnterpriseInstallAttributes::kConsumerKioskDeviceMode;
332 case DEVICE_MODE_PENDING:
333 case DEVICE_MODE_NOT_SET:
334 break;
335 }
336 NOTREACHED() << "Invalid device mode: " << mode;
337 return EnterpriseInstallAttributes::kUnknownDeviceMode;
338 }
339
340 DeviceMode EnterpriseInstallAttributes::GetDeviceModeFromString(
341 const std::string& mode) {
342 if (mode == EnterpriseInstallAttributes::kConsumerDeviceMode)
343 return DEVICE_MODE_CONSUMER;
344 else if (mode == EnterpriseInstallAttributes::kEnterpriseDeviceMode)
345 return DEVICE_MODE_ENTERPRISE;
346 else if (mode == EnterpriseInstallAttributes::kRetailKioskDeviceMode)
347 return DEVICE_MODE_RETAIL_KIOSK;
348 else if (mode == EnterpriseInstallAttributes::kConsumerKioskDeviceMode)
349 return DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
350 NOTREACHED() << "Unknown device mode string: " << mode;
351 return DEVICE_MODE_NOT_SET;
352 }
353
336 void EnterpriseInstallAttributes::DecodeInstallAttributes( 354 void EnterpriseInstallAttributes::DecodeInstallAttributes(
337 const std::map<std::string, std::string>& attr_map) { 355 const std::map<std::string, std::string>& attr_map) {
338 std::string enterprise_owned; 356 std::string enterprise_owned;
339 std::string enterprise_user; 357 std::string enterprise_user;
340 std::string consumer_kiosk_enabled; 358 std::string consumer_kiosk_enabled;
341 if (ReadMapKey(attr_map, kAttrEnterpriseOwned, &enterprise_owned) && 359 if (ReadMapKey(attr_map, kAttrEnterpriseOwned, &enterprise_owned) &&
342 ReadMapKey(attr_map, kAttrEnterpriseUser, &enterprise_user) && 360 ReadMapKey(attr_map, kAttrEnterpriseUser, &enterprise_user) &&
343 enterprise_owned == "true" && 361 enterprise_owned == "true" &&
344 !enterprise_user.empty()) { 362 !enterprise_user.empty()) {
345 registration_user_ = gaia::CanonicalizeEmail(enterprise_user); 363 registration_user_ = gaia::CanonicalizeEmail(enterprise_user);
(...skipping 21 matching lines...) Expand all
367 &consumer_kiosk_enabled) && 385 &consumer_kiosk_enabled) &&
368 consumer_kiosk_enabled == "true") { 386 consumer_kiosk_enabled == "true") {
369 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; 387 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH;
370 } else if (enterprise_user.empty() && enterprise_owned != "true") { 388 } else if (enterprise_user.empty() && enterprise_owned != "true") {
371 // |registration_user_| is empty on consumer devices. 389 // |registration_user_| is empty on consumer devices.
372 registration_mode_ = DEVICE_MODE_CONSUMER; 390 registration_mode_ = DEVICE_MODE_CONSUMER;
373 } 391 }
374 } 392 }
375 393
376 } // namespace policy 394 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/policy/enterprise_install_attributes.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698