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

Side by Side Diff: chrome/install_static/install_details.h

Issue 2422643002: Windows install_static refactor. (Closed)
Patch Set: sync to position 428354 Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
(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 {
Sigurður Ásgeirsson 2016/10/28 15:44:16 this structure also goes across modules and may al
grt (UTC plus 2) 2016/10/31 10:44:30 Done.
31 // The brand-specific install mode for this install; see kInstallModes.
32 const InstallConstants* mode;
33
34 // The friendly name of this Chrome's channel, or "unknown" if the brand
35 // does not integrate with Google Update.
36 const wchar_t* channel;
37
38 // The string length of |channel| (not including the string terminator).
39 size_t channel_length;
40
41 // True if installed in C:\Program Files{, {x86)}; otherwise, false.
42 bool system_level;
43
44 // True if multi-install.
45 bool multi_install;
46 };
47
48 InstallDetails(const InstallDetails&) = delete;
49 InstallDetails(InstallDetails&&) = delete;
50 InstallDetails& operator=(const InstallDetails&) = delete;
51 virtual ~InstallDetails() = default;
52
53 // Returns the instance for this module.
54 static const InstallDetails& Get();
55
56 // This mode's index into the brand's array of install modes. This will match
57 // a brand-specific InstallConstantIndex enumerator.
58 int install_mode_index() const { return payload_->mode->index; }
59
60 // The mode's install suffix (e.g., " SxS" for canary Chrome), or an empty
61 // string for a brand's primary install mode.
62 const wchar_t* install_suffix() const {
63 return payload_->mode->install_suffix;
64 }
65
66 // The app GUID with which this mode is registered with Google Update, or an
67 // empty string if this brand does not integrate with Google Update.
68 const wchar_t* app_guid() const { return payload_->mode->app_guid; }
69
70 // True if the mode supports installation at system-level.
71 bool supports_system_level() const {
72 return payload_->mode->supports_system_level;
73 }
74
75 // True if the mode supports multi-install.
76 bool supports_multi_install() const {
77 return payload_->mode->supports_multi_install;
78 }
79
80 // The install's update channel, or the string "unknown" if the brand does not
81 // integrate with Google Update.
82 std::wstring channel() const {
83 return std::wstring(payload_->channel, payload_->channel_length);
84 }
85 bool system_level() const { return payload_->system_level; }
86 bool multi_install() const { return payload_->multi_install; }
87
88 // Returns the path to the ClientState key for the installation. Returns the
89 // path for the binaries if |binaries| and Chrome is multi-install. Otherwise,
Sigurður Ásgeirsson 2016/10/28 15:44:16 as an outside reader, I don't quite understand the
grt (UTC plus 2) 2016/10/31 10:44:30 Registry only. I've added a little more color to t
90 // returns the path for Chrome itself.
91 std::wstring GetClientStateKeyPath(bool binaries) const;
92
93 // Returns the path to the ClientStateMedium key for the installation. Returns
94 // the path for the binaries if |binaries| and Chrome is multi-install.
95 // Otherwise, returns the path for Chrome itself.
96 std::wstring GetClientStateMediumKeyPath(bool binaries) const;
97
98 // Sets the instance for the process. This must be called only once per
99 // process during startup.
100 static void SetForProcess(std::unique_ptr<PrimaryInstallDetails> details);
101
102 // Returns a pointer to the module's payload so that it may be shared with
103 // other modules in the process.
104 static const Payload* GetPayload();
105
106 // Initializes this module's instance with the payload owned by the process's
107 // primary module (the one that used SetForProcess). Said primary module must
108 // export the function:
109 // extern "C" const install_static::InstallDetails::Payload*
110 // GetInstallDetailsPayload();
111 static void InitializeFromPrimaryModule(const wchar_t* primary_module_name);
112
113 protected:
114 explicit InstallDetails(const Payload* payload) : payload_(payload) {}
115 const wchar_t* default_channel_name() const {
116 return payload_->mode->default_channel_name;
117 }
118
119 private:
120 const Payload* const payload_;
121 };
122
123 // A kind of InstallDetails that owns its payload. A single instance of this
124 // class is initialized early on in process startup (e.g., in chrome_elf for the
125 // case of chrome.exe; see InitializeProductDetailsForPrimaryModule). Its
126 // underlying data (its "payload") is shared with other interested modules in
127 // the process.
128 class PrimaryInstallDetails : public InstallDetails {
129 public:
130 PrimaryInstallDetails() : InstallDetails(&payload_) {}
131 PrimaryInstallDetails(const PrimaryInstallDetails&) = delete;
132 PrimaryInstallDetails(PrimaryInstallDetails&&) = delete;
133 PrimaryInstallDetails& operator=(const PrimaryInstallDetails&) = delete;
134
135 void set_mode(const InstallConstants* mode) { payload_.mode = mode; }
136 void set_channel(const std::wstring& channel) {
137 channel_ = channel;
138 payload_.channel = channel_.c_str();
139 payload_.channel_length = channel_.size();
140 }
141 void set_system_level(bool system_level) {
142 payload_.system_level = system_level;
143 }
144 void set_multi_install(bool multi_install) {
145 payload_.multi_install = multi_install;
146 }
147
148 private:
149 std::wstring channel_;
150 Payload payload_ = Payload();
151 };
152
153 } // namespace install_static
154
155 #endif // CHROME_INSTALL_STATIC_INSTALL_DETAILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698