forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstub_install_attributes.cc
119 lines (99 loc) · 3.89 KB
/
stub_install_attributes.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 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 "chromeos/tpm/stub_install_attributes.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
namespace chromeos {
StubInstallAttributes::StubInstallAttributes() : InstallAttributes(nullptr) {
device_locked_ = true;
}
// static
std::unique_ptr<StubInstallAttributes> StubInstallAttributes::CreateUnset() {
auto result = std::make_unique<StubInstallAttributes>();
result->Clear();
return result;
}
// static
std::unique_ptr<StubInstallAttributes>
StubInstallAttributes::CreateConsumerOwned() {
auto result = std::make_unique<StubInstallAttributes>();
result->SetConsumerOwned();
return result;
}
// static
std::unique_ptr<StubInstallAttributes>
StubInstallAttributes::CreateCloudManaged(const std::string& domain,
const std::string& device_id) {
auto result = std::make_unique<StubInstallAttributes>();
result->SetCloudManaged(domain, device_id);
return result;
}
// static
std::unique_ptr<StubInstallAttributes>
StubInstallAttributes::CreateActiveDirectoryManaged(
const std::string& realm,
const std::string& device_id) {
auto result = std::make_unique<StubInstallAttributes>();
result->SetActiveDirectoryManaged(realm, device_id);
return result;
}
// static
std::unique_ptr<StubInstallAttributes> StubInstallAttributes::CreateDemoMode(
const std::string& device_id) {
auto result = std::make_unique<StubInstallAttributes>();
result->SetDemoMode(device_id);
return result;
}
void StubInstallAttributes::Clear() {
registration_mode_ = policy::DEVICE_MODE_NOT_SET;
registration_domain_.clear();
registration_realm_.clear();
registration_device_id_.clear();
}
void StubInstallAttributes::SetConsumerOwned() {
registration_mode_ = policy::DEVICE_MODE_CONSUMER;
registration_domain_.clear();
registration_realm_.clear();
registration_device_id_.clear();
}
void StubInstallAttributes::SetCloudManaged(const std::string& domain,
const std::string& device_id) {
registration_mode_ = policy::DEVICE_MODE_ENTERPRISE;
registration_domain_ = domain;
registration_realm_.clear();
registration_device_id_ = device_id;
}
void StubInstallAttributes::SetActiveDirectoryManaged(
const std::string& realm,
const std::string& device_id) {
registration_mode_ = policy::DEVICE_MODE_ENTERPRISE_AD;
registration_realm_ = realm;
registration_domain_.clear();
registration_device_id_ = device_id;
}
void StubInstallAttributes::SetDemoMode(const std::string& device_id) {
registration_mode_ = policy::DEVICE_MODE_DEMO;
registration_domain_ = policy::kDemoModeDomain;
registration_realm_.clear();
registration_device_id_ = device_id;
}
ScopedStubInstallAttributes::ScopedStubInstallAttributes()
: ScopedStubInstallAttributes(std::make_unique<StubInstallAttributes>()) {}
ScopedStubInstallAttributes::ScopedStubInstallAttributes(
std::unique_ptr<StubInstallAttributes> install_attributes)
: install_attributes_(std::move(install_attributes)) {
// The constructor calls SetForTesting with these install_attributes, so
// in the destructor we make the matching call to ShutdownForTesting.
InstallAttributes::SetForTesting(install_attributes_.get());
}
ScopedStubInstallAttributes::~ScopedStubInstallAttributes() {
// Make sure that the install_attributes_ that are held by this class
// are still the same as the global singleton - if not, then that singleton
// has been overwritten somewhere else, which is probably a bug.
CHECK_EQ(install_attributes_.get(), InstallAttributes::Get());
InstallAttributes::ShutdownForTesting(); // Unset the global singleton.
}
StubInstallAttributes* ScopedStubInstallAttributes::Get() {
return install_attributes_.get();
}
} // namespace chromeos