Amin Hassani | a454eb6 | 2021-02-09 16:20:44 -0800 | [diff] [blame] | 1 | // 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 Fan | 713061e | 2021-03-08 15:45:12 +0900 | [diff] [blame^] | 9 | #include <base/check.h> |
Amin Hassani | a454eb6 | 2021-02-09 16:20:44 -0800 | [diff] [blame] | 10 | #include <base/logging.h> |
| 11 | #include <vboot/crossystem.h> |
| 12 | |
| 13 | namespace imageloader { |
| 14 | |
| 15 | // static |
| 16 | GlobalContext* GlobalContext::g_ctx_ = nullptr; |
| 17 | |
| 18 | // static |
| 19 | GlobalContext* GlobalContext::Current() { |
| 20 | CHECK(g_ctx_ != nullptr) << "The GlobalContext has not been set yet!"; |
| 21 | return g_ctx_; |
| 22 | } |
| 23 | |
| 24 | void GlobalContext::SetAsCurrent() { |
| 25 | g_ctx_ = this; |
| 26 | } |
| 27 | |
| 28 | bool 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 |