Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9256)

Unified Diff: chrome/install_static/install_details.h

Issue 2422643002: Windows install_static refactor. (Closed)
Patch Set: fix static build Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/install_static/install_constants.h ('k') | chrome/install_static/install_details.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/install_static/install_details.h
diff --git a/chrome/install_static/install_details.h b/chrome/install_static/install_details.h
new file mode 100644
index 0000000000000000000000000000000000000000..4ac61b8228f69c4fb9be301fda547238629c193f
--- /dev/null
+++ b/chrome/install_static/install_details.h
@@ -0,0 +1,151 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_
+#define CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_
+
+#include <stdint.h>
+
+#include <memory>
+#include <string>
+
+#include "chrome/install_static/install_constants.h"
+
+namespace install_static {
+
+class PrimaryInstallDetails;
+
+// Details relating to how Chrome is installed. This class and
+// PrimaryInstallDetails (below) are used in tandem so that one instance of the
+// latter may be initialized early during process startup and then shared with
+// other modules in the process. For example, chrome_elf creates the instance
+// for a Chrome process and exports a GetInstallDetailsPayload function used by
+// chrome.exe and chrome.dll to create their own module-specific instances
+// referring to the same underlying payload.
+class InstallDetails {
+ public:
+ InstallDetails(const InstallDetails&) = delete;
+ InstallDetails(InstallDetails&&) = delete;
+ InstallDetails& operator=(const InstallDetails&) = delete;
+ virtual ~InstallDetails() = default;
+
+ // Returns the instance for this module.
+ static const InstallDetails& Get();
+
+ // This mode's index into the brand's array of install modes. This will match
+ // a brand-specific InstallConstantIndex enumerator.
+ int install_mode_index() const { return payload_->mode->index; }
+
+ // The mode's install suffix (e.g., " SxS" for canary Chrome), or an empty
+ // string for a brand's primary install mode.
+ const wchar_t* install_suffix() const {
+ return payload_->mode->install_suffix;
+ }
+
+ // The app GUID with which this mode is registered with Google Update, or an
+ // empty string if this brand does not integrate with Google Update.
+ const wchar_t* app_guid() const { return payload_->mode->app_guid; }
+
+ // True if the mode supports installation at system-level.
+ bool supports_system_level() const {
+ return payload_->mode->supports_system_level;
+ }
+
+ // True if the mode supports multi-install.
+ bool supports_multi_install() const {
+ return payload_->mode->supports_multi_install;
+ }
+
+ // The install's update channel, or the string "unknown" if the brand does not
+ // integrate with Google Update.
+ std::wstring channel() const {
+ return std::wstring(payload_->channel, payload_->channel_length);
+ }
+ bool system_level() const { return payload_->system_level; }
+ bool multi_install() const { return payload_->multi_install; }
+
+ // Returns the path to the ClientState key for the installation. Returns the
+ // path for the binaries if |binaries| and Chrome is multi-install. Otherwise,
+ // returns the path for Chrome itself.
+ std::wstring GetClientStateKeyPath(bool binaries) const;
+
+ // Returns the path to the ClientStateMedium key for the installation. Returns
+ // the path for the binaries if |binaries| and Chrome is multi-install.
+ // Otherwise, returns the path for Chrome itself.
+ std::wstring GetClientStateMediumKeyPath(bool binaries) const;
+
+ // Sets the instance for the process. This must be called only once per
+ // process during startup.
+ static void SetForProcess(std::unique_ptr<PrimaryInstallDetails> details);
+
+ // Returns a pointer to the module's payload so that it may be shared with
+ // other modules in the process.
+ 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
+
+ // Initializes this module's instance with another module's payload.
+ static void ImportFromModule(const wchar_t* module_name,
+ const char* export_name);
+
+ protected:
+ // A POD-struct containing the underlying data for an InstallDetails
+ // instance. Multiple InstallDetails instances (e.g., one per module in a
+ // process) share a single underlying Payload.
+ struct Payload {
+ // The brand-specific install mode for this install; see kInstallModes.
+ const InstallConstants* mode;
+
+ // The friendly name of this Chrome's channel, or "unknown" if the brand
+ // does not integrate with Google Update.
+ const wchar_t* channel;
+
+ // The string length of |channel| (not including the string terminator).
+ size_t channel_length;
+
+ // True if installed in C:\Program Files{, {x86)}; otherwise, false.
+ bool system_level;
+
+ // True if multi-install.
+ bool multi_install;
+ };
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!
+
+ explicit InstallDetails(const Payload* payload) : payload_(payload) {}
+ const wchar_t* default_channel_name() const {
+ return payload_->mode->default_channel_name;
+ }
+
+ private:
+ const Payload* const payload_;
+};
+
+// A kind of InstallDetails that owns its payload. A single instance of this
+// 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?
+// "payload") is shared with other interested modules in the process.
+class PrimaryInstallDetails : public InstallDetails {
+ public:
+ PrimaryInstallDetails() : InstallDetails(&payload_) {}
+ PrimaryInstallDetails(const PrimaryInstallDetails&) = delete;
+ PrimaryInstallDetails(PrimaryInstallDetails&&) = delete;
+ PrimaryInstallDetails& operator=(const PrimaryInstallDetails&) = delete;
+
+ void set_mode(const InstallConstants* mode) { payload_.mode = mode; }
+ void set_channel(const std::wstring& channel) {
+ channel_ = channel;
+ payload_.channel = channel_.c_str();
+ payload_.channel_length = channel_.size();
+ }
+ void set_system_level(bool system_level) {
+ payload_.system_level = system_level;
+ }
+ void set_multi_install(bool multi_install) {
+ payload_.multi_install = multi_install;
+ }
+
+ private:
+ std::wstring channel_;
+ Payload payload_ = Payload();
+};
+
+} // namespace install_static
+
+#endif // CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_
« no previous file with comments | « chrome/install_static/install_constants.h ('k') | chrome/install_static/install_details.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698