blob: bdb38f90c51fa060cb4648624e212e14964a88d3 [file] [log] [blame]
Amin Hassania454eb62021-02-09 16:20:44 -08001// Copyright 2021 The Chromium OS 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 "imageloader/global_context.h"
6
7#include <optional>
8
Qijiang Fan713061e2021-03-08 15:45:12 +09009#include <base/check.h>
Amin Hassania454eb62021-02-09 16:20:44 -080010#include <base/logging.h>
11#include <vboot/crossystem.h>
12
13namespace imageloader {
14
15// static
16GlobalContext* GlobalContext::g_ctx_ = nullptr;
17
18// static
19GlobalContext* GlobalContext::Current() {
20 CHECK(g_ctx_ != nullptr) << "The GlobalContext has not been set yet!";
21 return g_ctx_;
22}
23
24void GlobalContext::SetAsCurrent() {
25 g_ctx_ = this;
26}
27
28bool GlobalContext::IsOfficialBuild() const {
29 // TODO(ahassani): Save this value in an `std::optional` instance so we don't
30 // have to query this several times during the runtime.
31 return VbGetSystemPropertyInt("debug_build") == 0;
32}
33
34} // namespace imageloader