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