| 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 #ifndef CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_ | |
| 6 #define CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "chrome/install_static/install_constants.h" | |
| 12 | |
| 13 namespace install_static { | |
| 14 | |
| 15 class PrimaryInstallDetails; | |
| 16 | |
| 17 // Details relating to how Chrome is installed. This class and | |
| 18 // PrimaryInstallDetails (below) are used in tandem so that one instance of the | |
| 19 // latter may be initialized early during process startup and then shared with | |
| 20 // other modules in the process. For example, chrome_elf creates the instance | |
| 21 // for a Chrome process and exports a GetInstallDetailsPayload function used by | |
| 22 // chrome.exe and chrome.dll to create their own module-specific instances | |
| 23 // referring to the same underlying payload. See install_modes.h for a gentle | |
| 24 // introduction to such terms as "brand" and "mode". | |
| 25 class InstallDetails { | |
| 26 public: | |
| 27 // A POD-struct containing the underlying data for an InstallDetails | |
| 28 // instance. Multiple InstallDetails instances (e.g., one per module in a | |
| 29 // process) share a single underlying Payload. | |
| 30 struct Payload { | |
| 31 // The size (in bytes) of this structure. This serves to verify that all | |
| 32 // modules in a process have the same definition of the struct. | |
| 33 size_t size; | |
| 34 | |
| 35 // The compile-time version of the product at the time that the process's | |
| 36 // primary module was built. This is used to detect version skew across | |
| 37 // modules in the process. | |
| 38 const char* product_version; | |
| 39 | |
| 40 // The brand-specific install mode for this install; see kInstallModes. | |
| 41 const InstallConstants* mode; | |
| 42 | |
| 43 // The friendly name of this Chrome's channel, or an empty string if the | |
| 44 // brand does not integrate with Google Update. | |
| 45 const wchar_t* channel; | |
| 46 | |
| 47 // The string length of |channel| (not including the string terminator). | |
| 48 size_t channel_length; | |
| 49 | |
| 50 // True if installed in C:\Program Files{, {x86)}; otherwise, false. | |
| 51 bool system_level; | |
| 52 | |
| 53 // True if multi-install. | |
| 54 bool multi_install; | |
| 55 }; | |
| 56 | |
| 57 InstallDetails(const InstallDetails&) = delete; | |
| 58 InstallDetails(InstallDetails&&) = delete; | |
| 59 InstallDetails& operator=(const InstallDetails&) = delete; | |
| 60 virtual ~InstallDetails() = default; | |
| 61 | |
| 62 // Returns the instance for this module. | |
| 63 static const InstallDetails& Get(); | |
| 64 | |
| 65 // This mode's index into the brand's array of install modes. This will match | |
| 66 // a brand-specific InstallConstantIndex enumerator. | |
| 67 int install_mode_index() const { return payload_->mode->index; } | |
| 68 | |
| 69 // The mode's install suffix (e.g., " SxS" for canary Chrome), or an empty | |
| 70 // string for a brand's primary install mode. | |
| 71 const wchar_t* install_suffix() const { | |
| 72 return payload_->mode->install_suffix; | |
| 73 } | |
| 74 | |
| 75 // The app GUID with which this mode is registered with Google Update, or an | |
| 76 // empty string if this brand does not integrate with Google Update. | |
| 77 const wchar_t* app_guid() const { return payload_->mode->app_guid; } | |
| 78 | |
| 79 // True if the mode supports installation at system-level. | |
| 80 bool supports_system_level() const { | |
| 81 return payload_->mode->supports_system_level; | |
| 82 } | |
| 83 | |
| 84 // True if the mode supports multi-install. | |
| 85 bool supports_multi_install() const { | |
| 86 return payload_->mode->supports_multi_install; | |
| 87 } | |
| 88 | |
| 89 // The install's update channel, or an empty string if the brand does not | |
| 90 // integrate with Google Update. | |
| 91 std::wstring channel() const { | |
| 92 return std::wstring(payload_->channel, payload_->channel_length); | |
| 93 } | |
| 94 bool system_level() const { return payload_->system_level; } | |
| 95 bool multi_install() const { return payload_->multi_install; } | |
| 96 | |
| 97 // Returns the path to the installation's ClientState registry key. Returns | |
| 98 // the path for the binaries if |binaries| and Chrome is | |
| 99 // multi-install. Otherwise, returns the path for Chrome itself. This registry | |
| 100 // key is used to hold various installation-related values, including an | |
| 101 // indication of consent for usage stats. | |
| 102 std::wstring GetClientStateKeyPath(bool binaries) const; | |
| 103 | |
| 104 // Returns the path to the installation's ClientStateMedium registry key. | |
| 105 // Returns the path for the binaries if |binaries| and Chrome is | |
| 106 // multi-install. Otherwise, returns the path for Chrome itself. This | |
| 107 // registry key is used to hold various installation-related values, including | |
| 108 // an indication of consent for usage stats for a system-level install. | |
| 109 std::wstring GetClientStateMediumKeyPath(bool binaries) const; | |
| 110 | |
| 111 // Returns true if there is an indication of a mismatch between the primary | |
| 112 // module and this module. | |
| 113 bool VersionMismatch() const; | |
| 114 | |
| 115 // Sets the instance for the process. This must be called only once per | |
| 116 // process during startup. | |
| 117 static void SetForProcess(std::unique_ptr<PrimaryInstallDetails> details); | |
| 118 | |
| 119 // Returns a pointer to the module's payload so that it may be shared with | |
| 120 // other modules in the process. | |
| 121 static const Payload* GetPayload(); | |
| 122 | |
| 123 // Initializes this module's instance with the payload owned by the process's | |
| 124 // primary module (the one that used SetForProcess). Said primary module must | |
| 125 // export the function: | |
| 126 // extern "C" const install_static::InstallDetails::Payload* | |
| 127 // GetInstallDetailsPayload(); | |
| 128 static void InitializeFromPrimaryModule(const wchar_t* primary_module_name); | |
| 129 | |
| 130 protected: | |
| 131 explicit InstallDetails(const Payload* payload) : payload_(payload) {} | |
| 132 const wchar_t* default_channel_name() const { | |
| 133 return payload_->mode->default_channel_name; | |
| 134 } | |
| 135 | |
| 136 private: | |
| 137 const Payload* const payload_; | |
| 138 }; | |
| 139 | |
| 140 // A kind of InstallDetails that owns its payload. A single instance of this | |
| 141 // class is initialized early on in process startup (e.g., in chrome_elf for the | |
| 142 // case of chrome.exe; see InitializeProductDetailsForPrimaryModule). Its | |
| 143 // underlying data (its "payload") is shared with other interested modules in | |
| 144 // the process. | |
| 145 class PrimaryInstallDetails : public InstallDetails { | |
| 146 public: | |
| 147 PrimaryInstallDetails(); | |
| 148 PrimaryInstallDetails(const PrimaryInstallDetails&) = delete; | |
| 149 PrimaryInstallDetails(PrimaryInstallDetails&&) = delete; | |
| 150 PrimaryInstallDetails& operator=(const PrimaryInstallDetails&) = delete; | |
| 151 | |
| 152 void set_mode(const InstallConstants* mode) { payload_.mode = mode; } | |
| 153 void set_channel(const std::wstring& channel) { | |
| 154 channel_ = channel; | |
| 155 payload_.channel = channel_.c_str(); | |
| 156 payload_.channel_length = channel_.size(); | |
| 157 } | |
| 158 void set_system_level(bool system_level) { | |
| 159 payload_.system_level = system_level; | |
| 160 } | |
| 161 void set_multi_install(bool multi_install) { | |
| 162 payload_.multi_install = multi_install; | |
| 163 } | |
| 164 | |
| 165 private: | |
| 166 std::wstring channel_; | |
| 167 Payload payload_ = Payload(); | |
| 168 }; | |
| 169 | |
| 170 } // namespace install_static | |
| 171 | |
| 172 #endif // CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_ | |
| OLD | NEW |