Chromium Code Reviews| 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(); | |
|
Sigurður Ásgeirsson
2016/10/14 21:09:12
I'm not sure I understand why this can't profitabl
grt (UTC plus 2)
2016/10/16 09:15:25
Yes. I figure that Payload* is an implementation d
Sigurður Ásgeirsson
2016/10/24 15:04:06
I generally lean towards compiler-enforced typing
grt (UTC plus 2)
2016/10/24 19:36:00
Okay. I've made Payload public but not done any ot
Sigurður Ásgeirsson
2016/10/28 15:44:16
SGTM - I'm not sure what action is best, DumpWitho
grt (UTC plus 2)
2016/10/31 10:44:30
Went with DWC from ChromeMain. We can do something
| |
| 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 }; | |
|
Sigurður Ásgeirsson
2016/10/14 21:09:13
maybe you want a static_assert(std::is_pod<Payload
grt (UTC plus 2)
2016/10/16 09:15:25
Cool, thanks!
| |
| 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. Its underlying data (its | |
|
Sigurður Ásgeirsson
2016/10/14 21:09:13
in a single module - like chrome_elf?
grt (UTC plus 2)
2016/10/16 09:15:25
Comment tweaked a bit. WDYT?
| |
| 123 // "payload") is shared with other interested modules in the process. | |
| 124 class PrimaryInstallDetails : public InstallDetails { | |
| 125 public: | |
| 126 PrimaryInstallDetails() : InstallDetails(&payload_) {} | |
| 127 PrimaryInstallDetails(const PrimaryInstallDetails&) = delete; | |
| 128 PrimaryInstallDetails(PrimaryInstallDetails&&) = delete; | |
| 129 PrimaryInstallDetails& operator=(const PrimaryInstallDetails&) = delete; | |
| 130 | |
| 131 void set_mode(const InstallConstants* mode) { payload_.mode = mode; } | |
| 132 void set_channel(const std::wstring& channel) { | |
| 133 channel_ = channel; | |
| 134 payload_.channel = channel_.c_str(); | |
| 135 payload_.channel_length = channel_.size(); | |
| 136 } | |
| 137 void set_system_level(bool system_level) { | |
| 138 payload_.system_level = system_level; | |
| 139 } | |
| 140 void set_multi_install(bool multi_install) { | |
| 141 payload_.multi_install = multi_install; | |
| 142 } | |
| 143 | |
| 144 private: | |
| 145 std::wstring channel_; | |
| 146 Payload payload_ = Payload(); | |
| 147 }; | |
| 148 | |
| 149 } // namespace install_static | |
| 150 | |
| 151 #endif // CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_ | |
| OLD | NEW |