| 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 |
| 9 #include <type_traits> |
| 10 |
| 11 #include "chrome/install_static/install_modes.h" |
| 12 #include "chrome/install_static/install_util.h" |
| 13 #include "chrome_elf/nt_registry/nt_registry.h" |
| 14 |
| 15 namespace install_static { |
| 16 |
| 17 namespace { |
| 18 |
| 19 // This module's instance (intentionally leaked at shutdown). |
| 20 InstallDetails* g_module_details = nullptr; |
| 21 |
| 22 } // namespace |
| 23 |
| 24 std::wstring InstallDetails::GetClientStateKeyPath(bool binaries) const { |
| 25 return binaries && multi_install() |
| 26 ? GetBinariesClientStateKeyPath() |
| 27 : install_static::GetClientStateKeyPath(app_guid()); |
| 28 } |
| 29 |
| 30 std::wstring InstallDetails::GetClientStateMediumKeyPath(bool binaries) const { |
| 31 return binaries && multi_install() |
| 32 ? GetBinariesClientStateMediumKeyPath() |
| 33 : install_static::GetClientStateMediumKeyPath(app_guid()); |
| 34 } |
| 35 |
| 36 // static |
| 37 const InstallDetails& InstallDetails::Get() { |
| 38 assert(g_module_details); |
| 39 return *g_module_details; |
| 40 } |
| 41 |
| 42 // static |
| 43 void InstallDetails::SetForProcess( |
| 44 std::unique_ptr<PrimaryInstallDetails> details) { |
| 45 assert(!details || !g_module_details); |
| 46 // Tests may set then reset via null. In this case, delete the old instance. |
| 47 delete g_module_details; |
| 48 // Intentionally leaked at shutdown. |
| 49 g_module_details = details.release(); |
| 50 } |
| 51 |
| 52 // static |
| 53 const InstallDetails::Payload* InstallDetails::GetPayload() { |
| 54 assert(g_module_details); |
| 55 static_assert(std::is_pod<Payload>::value, "Payload must be a POD-struct"); |
| 56 static_assert(std::is_pod<InstallConstants>::value, |
| 57 "InstallConstants must be a POD-struct"); |
| 58 return g_module_details->payload_; |
| 59 } |
| 60 |
| 61 // static |
| 62 void InstallDetails::InitializeForModule(const wchar_t* primary_module_name, |
| 63 const char* export_name) { |
| 64 assert(!g_module_details); |
| 65 using GetInstallDetailsPayloadFunction = const Payload*(__cdecl*)(); |
| 66 GetInstallDetailsPayloadFunction payload_getter = |
| 67 reinterpret_cast<GetInstallDetailsPayloadFunction>(::GetProcAddress( |
| 68 ::GetModuleHandle(primary_module_name), export_name)); |
| 69 assert(payload_getter); |
| 70 // Intentionally leaked at shutdown. |
| 71 g_module_details = new InstallDetails(payload_getter()); |
| 72 } |
| 73 |
| 74 } // namespace install_static |
| OLD | NEW |