OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium 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 "chrome/install_static/install_details.h" |
| 6 |
| 7 #include <assert.h> |
| 8 #include <string.h> |
| 9 |
| 10 #include <type_traits> |
| 11 |
| 12 #include "chrome/install_static/install_modes.h" |
| 13 #include "chrome/install_static/install_util.h" |
| 14 #include "chrome_elf/nt_registry/nt_registry.h" |
| 15 #include "components/version_info/version_info_values.h" |
| 16 |
| 17 namespace install_static { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // The version is set at compile-time to a W.X.Y.Z value. |
| 22 constexpr char kProductVersion[] = PRODUCT_VERSION; |
| 23 |
| 24 // This module's instance (intentionally leaked at shutdown). |
| 25 InstallDetails* g_module_details = nullptr; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 std::wstring InstallDetails::GetClientStateKeyPath(bool binaries) const { |
| 30 return binaries && multi_install() |
| 31 ? GetBinariesClientStateKeyPath() |
| 32 : install_static::GetClientStateKeyPath(app_guid()); |
| 33 } |
| 34 |
| 35 std::wstring InstallDetails::GetClientStateMediumKeyPath(bool binaries) const { |
| 36 return binaries && multi_install() |
| 37 ? GetBinariesClientStateMediumKeyPath() |
| 38 : install_static::GetClientStateMediumKeyPath(app_guid()); |
| 39 } |
| 40 |
| 41 bool InstallDetails::VersionMismatch() const { |
| 42 // Check the product version and the size of the mode structure. |
| 43 return payload_->size != sizeof(Payload) || |
| 44 strcmp(payload_->product_version, &kProductVersion[0]) != 0 || |
| 45 payload_->mode->size != sizeof(InstallConstants); |
| 46 } |
| 47 |
| 48 // static |
| 49 const InstallDetails& InstallDetails::Get() { |
| 50 assert(g_module_details); |
| 51 return *g_module_details; |
| 52 } |
| 53 |
| 54 // static |
| 55 void InstallDetails::SetForProcess( |
| 56 std::unique_ptr<PrimaryInstallDetails> details) { |
| 57 assert(!details || !g_module_details); |
| 58 // Tests may set then reset via null. In this case, delete the old instance. |
| 59 delete g_module_details; |
| 60 // Intentionally leaked at shutdown. |
| 61 g_module_details = details.release(); |
| 62 } |
| 63 |
| 64 // static |
| 65 const InstallDetails::Payload* InstallDetails::GetPayload() { |
| 66 assert(g_module_details); |
| 67 static_assert(std::is_pod<Payload>::value, "Payload must be a POD-struct"); |
| 68 static_assert(std::is_pod<InstallConstants>::value, |
| 69 "InstallConstants must be a POD-struct"); |
| 70 return g_module_details->payload_; |
| 71 } |
| 72 |
| 73 // static |
| 74 void InstallDetails::InitializeFromPrimaryModule( |
| 75 const wchar_t* primary_module_name) { |
| 76 assert(!g_module_details); |
| 77 using GetInstallDetailsPayloadFunction = const Payload*(__cdecl*)(); |
| 78 GetInstallDetailsPayloadFunction payload_getter = |
| 79 reinterpret_cast<GetInstallDetailsPayloadFunction>(::GetProcAddress( |
| 80 ::GetModuleHandle(primary_module_name), "GetInstallDetailsPayload")); |
| 81 assert(payload_getter); |
| 82 // Intentionally leaked at shutdown. |
| 83 g_module_details = new InstallDetails(payload_getter()); |
| 84 } |
| 85 |
| 86 PrimaryInstallDetails::PrimaryInstallDetails() : InstallDetails(&payload_) { |
| 87 payload_.size = sizeof(payload_); |
| 88 payload_.product_version = &kProductVersion[0]; |
| 89 } |
| 90 |
| 91 } // namespace install_static |
OLD | NEW |