File: stub_install_attributes.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 3,324 bytes parent folder | download | duplicates (7)
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
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chromeos/ash/components/install_attributes/stub_install_attributes.h"

#include "components/policy/core/common/cloud/cloud_policy_constants.h"

namespace ash {

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::CreateDemoMode() {
  auto result = std::make_unique<StubInstallAttributes>();
  result->SetDemoMode();
  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::SetDemoMode() {
  registration_mode_ = policy::DEVICE_MODE_DEMO;
  registration_domain_ = policy::kDemoModeDomain;
  registration_realm_.clear();
  registration_device_id_ = "demo-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 ash