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

Side by Side Diff: chrome/installer/util/channel_info.cc

Issue 811283002: [Installer] Cleaning up dead code for App Launcher / App Host installs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove query-eula-acceptance; changing ChannelInfo cleanup approach. Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/channel_info.h" 5 #include "chrome/installer/util/channel_info.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/win/registry.h" 8 #include "base/win/registry.h"
9 #include "chrome/installer/util/google_update_constants.h" 9 #include "chrome/installer/util/google_update_constants.h"
10 #include "chrome/installer/util/install_util.h"
10 #include "chrome/installer/util/util_constants.h" 11 #include "chrome/installer/util/util_constants.h"
11 12
12 using base::win::RegKey; 13 using base::win::RegKey;
13 14
14 namespace { 15 namespace {
15 16
16 const wchar_t kModChrome[] = L"-chrome"; 17 const wchar_t kModChrome[] = L"-chrome";
17 const wchar_t kModChromeFrame[] = L"-chromeframe"; 18 const wchar_t kModChromeFrame[] = L"-chromeframe";
18 // TODO(huangs): Remove by M27.
19 const wchar_t kModAppHostDeprecated[] = L"-apphost"; 19 const wchar_t kModAppHostDeprecated[] = L"-apphost";
20 const wchar_t kModAppLauncher[] = L"-applauncher"; 20 const wchar_t kModAppLauncherDeprecated[] = L"-applauncher";
21 const wchar_t kModMultiInstall[] = L"-multi"; 21 const wchar_t kModMultiInstall[] = L"-multi";
22 const wchar_t kModReadyMode[] = L"-readymode"; 22 const wchar_t kModReadyMode[] = L"-readymode";
23 const wchar_t kModStage[] = L"-stage:"; 23 const wchar_t kModStage[] = L"-stage:";
24 const wchar_t kSfxFull[] = L"-full"; 24 const wchar_t kSfxFull[] = L"-full";
25 const wchar_t kSfxMigrating[] = L"-migrating"; 25 const wchar_t kSfxMigrating[] = L"-migrating";
26 const wchar_t kSfxMultiFail[] = L"-multifail"; 26 const wchar_t kSfxMultiFail[] = L"-multifail";
27 27
28 const wchar_t* const kChannels[] = { 28 const wchar_t* const kChannels[] = {
29 installer::kChromeChannelBeta, 29 installer::kChromeChannelBeta,
30 installer::kChromeChannelDev, 30 installer::kChromeChannelDev,
31 installer::kChromeChannelStableExplicit 31 installer::kChromeChannelStableExplicit
32 }; 32 };
33 33
34 const wchar_t* const kModifiers[] = { 34 const wchar_t* const kModifiers[] = {
35 kModStage, 35 kModStage,
36 kModMultiInstall, 36 kModMultiInstall,
37 kModChrome, 37 kModChrome,
38 kModChromeFrame, 38 kModChromeFrame,
39 kModAppHostDeprecated, // TODO(huangs): Remove by M27. 39 kModAppHostDeprecated,
40 kModAppLauncher, 40 kModAppLauncherDeprecated,
41 kModReadyMode, 41 kModReadyMode,
42 kSfxMultiFail, 42 kSfxMultiFail,
43 kSfxMigrating, 43 kSfxMigrating,
44 kSfxFull, 44 kSfxFull,
45 }; 45 };
46 46
47 enum ModifierIndex { 47 enum ModifierIndex {
48 MOD_STAGE, 48 MOD_STAGE,
49 MOD_MULTI_INSTALL, 49 MOD_MULTI_INSTALL,
50 MOD_CHROME, 50 MOD_CHROME,
51 MOD_CHROME_FRAME, 51 MOD_CHROME_FRAME,
52 MOD_APP_HOST_DEPRECATED, // TODO(huangs): Remove by M27. 52 MOD_APP_HOST_DEPRECATED,
53 MOD_APP_LAUNCHER, 53 MOD_APP_LAUNCHER_DEPRECATED,
54 MOD_READY_MODE, 54 MOD_READY_MODE,
55 SFX_MULTI_FAIL, 55 SFX_MULTI_FAIL,
56 SFX_MIGRATING, 56 SFX_MIGRATING,
57 SFX_FULL, 57 SFX_FULL,
58 NUM_MODIFIERS 58 NUM_MODIFIERS
59 }; 59 };
60 60
61 COMPILE_ASSERT(NUM_MODIFIERS == arraysize(kModifiers), 61 COMPILE_ASSERT(NUM_MODIFIERS == arraysize(kModifiers),
62 kModifiers_disagrees_with_ModifierIndex_comma_they_must_match_bang); 62 kModifiers_disagrees_with_ModifierIndex_comma_they_must_match_bang);
63 63
64 // Returns true if the modifier is found, in which case |position| holds the 64 // Returns true if the modifier is found, in which case |position| holds the
65 // location at which the modifier was found. The number of characters in the 65 // location at which the modifier was found. The number of characters in the
66 // modifier is returned in |length|, if non-NULL. 66 // modifier is returned in |length|, if non-NULL.
67 bool FindModifier(ModifierIndex index, 67 bool FindModifier(ModifierIndex index,
68 const std::wstring& ap_value, 68 const base::string16& ap_value,
69 std::wstring::size_type* position, 69 base::string16::size_type* position,
70 std::wstring::size_type* length) { 70 base::string16::size_type* length) {
71 DCHECK(position != NULL); 71 DCHECK(position != NULL);
72 std::wstring::size_type mod_position = std::wstring::npos; 72 base::string16::size_type mod_position = base::string16::npos;
73 std::wstring::size_type mod_length = 73 base::string16::size_type mod_length =
74 std::wstring::traits_type::length(kModifiers[index]); 74 base::string16::traits_type::length(kModifiers[index]);
75 const bool mod_takes_arg = (kModifiers[index][mod_length - 1] == L':'); 75 const bool mod_takes_arg = (kModifiers[index][mod_length - 1] == L':');
76 std::wstring::size_type pos = 0; 76 base::string16::size_type pos = 0;
77 do { 77 do {
78 mod_position = ap_value.find(kModifiers[index], pos, mod_length); 78 mod_position = ap_value.find(kModifiers[index], pos, mod_length);
79 if (mod_position == std::wstring::npos) 79 if (mod_position == base::string16::npos)
80 return false; // Modifier not found. 80 return false; // Modifier not found.
81 pos = mod_position + mod_length; 81 pos = mod_position + mod_length;
82 // Modifiers that take an argument gobble up to the next separator or to the 82 // Modifiers that take an argument gobble up to the next separator or to the
83 // end. 83 // end.
84 if (mod_takes_arg) { 84 if (mod_takes_arg) {
85 pos = ap_value.find(L'-', pos); 85 pos = ap_value.find(L'-', pos);
86 if (pos == std::wstring::npos) 86 if (pos == base::string16::npos)
87 pos = ap_value.size(); 87 pos = ap_value.size();
88 break; 88 break;
89 } 89 }
90 // Regular modifiers must be followed by '-' or the end of the string. 90 // Regular modifiers must be followed by '-' or the end of the string.
91 } while (pos != ap_value.size() && ap_value[pos] != L'-'); 91 } while (pos != ap_value.size() && ap_value[pos] != L'-');
92 DCHECK_NE(mod_position, std::wstring::npos); 92 DCHECK_NE(mod_position, base::string16::npos);
93 *position = mod_position; 93 *position = mod_position;
94 if (length != NULL) 94 if (length != NULL)
95 *length = pos - mod_position; 95 *length = pos - mod_position;
96 return true; 96 return true;
97 } 97 }
98 98
99 bool HasModifier(ModifierIndex index, const std::wstring& ap_value) { 99 bool HasModifier(ModifierIndex index, const base::string16& ap_value) {
100 DCHECK(index >= 0 && index < NUM_MODIFIERS); 100 DCHECK(index >= 0 && index < NUM_MODIFIERS);
101 std::wstring::size_type position; 101 base::string16::size_type position;
102 return FindModifier(index, ap_value, &position, NULL); 102 return FindModifier(index, ap_value, &position, NULL);
103 } 103 }
104 104
105 std::wstring::size_type FindInsertionPoint(ModifierIndex index, 105 base::string16::size_type FindInsertionPoint(ModifierIndex index,
106 const std::wstring& ap_value) { 106 const base::string16& ap_value) {
107 // Return the location of the next modifier. 107 // Return the location of the next modifier.
108 std::wstring::size_type result; 108 base::string16::size_type result;
109 109
110 for (int scan = index + 1; scan < NUM_MODIFIERS; ++scan) { 110 for (int scan = index + 1; scan < NUM_MODIFIERS; ++scan) {
111 if (FindModifier(static_cast<ModifierIndex>(scan), ap_value, &result, NULL)) 111 if (FindModifier(static_cast<ModifierIndex>(scan), ap_value, &result, NULL))
112 return result; 112 return result;
113 } 113 }
114 114
115 return ap_value.size(); 115 return ap_value.size();
116 } 116 }
117 117
118 // Returns true if |ap_value| is modified. 118 // Returns true if |ap_value| is modified.
119 bool SetModifier(ModifierIndex index, bool set, std::wstring* ap_value) { 119 bool SetModifier(ModifierIndex index, bool set, base::string16* ap_value) {
120 DCHECK(index >= 0 && index < NUM_MODIFIERS); 120 DCHECK(index >= 0 && index < NUM_MODIFIERS);
121 DCHECK(ap_value); 121 DCHECK(ap_value);
122 std::wstring::size_type position; 122 base::string16::size_type position;
123 std::wstring::size_type length; 123 base::string16::size_type length;
124 bool have_modifier = FindModifier(index, *ap_value, &position, &length); 124 bool have_modifier = FindModifier(index, *ap_value, &position, &length);
125 if (set) { 125 if (set) {
126 if (!have_modifier) { 126 if (!have_modifier) {
127 ap_value->insert(FindInsertionPoint(index, *ap_value), kModifiers[index]); 127 ap_value->insert(FindInsertionPoint(index, *ap_value), kModifiers[index]);
128 return true; 128 return true;
129 } 129 }
130 } else { 130 } else {
131 if (have_modifier) { 131 if (have_modifier) {
132 ap_value->erase(position, length); 132 ap_value->erase(position, length);
133 return true; 133 return true;
(...skipping 18 matching lines...) Expand all
152 LONG result = value_.empty() ? 152 LONG result = value_.empty() ?
153 key->DeleteValue(google_update::kRegApField) : 153 key->DeleteValue(google_update::kRegApField) :
154 key->WriteValue(google_update::kRegApField, value_.c_str()); 154 key->WriteValue(google_update::kRegApField, value_.c_str());
155 if (result != ERROR_SUCCESS) { 155 if (result != ERROR_SUCCESS) {
156 LOG(ERROR) << "Failed writing channel info; result: " << result; 156 LOG(ERROR) << "Failed writing channel info; result: " << result;
157 return false; 157 return false;
158 } 158 }
159 return true; 159 return true;
160 } 160 }
161 161
162 bool ChannelInfo::GetChannelName(std::wstring* channel_name) const { 162 bool ChannelInfo::GetChannelName(base::string16* channel_name) const {
163 DCHECK(channel_name); 163 DCHECK(channel_name);
164 if (value_.empty()) { 164 if (value_.empty()) {
165 channel_name->erase(); 165 channel_name->erase();
166 return true; 166 return true;
167 } else { 167 } else {
168 for (const wchar_t* const* scan = &kChannels[0], 168 for (const wchar_t* const* scan = &kChannels[0],
169 *const* end = &kChannels[arraysize(kChannels)]; scan != end; 169 *const* end = &kChannels[arraysize(kChannels)]; scan != end;
170 ++scan) { 170 ++scan) {
171 if (value_.find(*scan) != std::wstring::npos) { 171 if (value_.find(*scan) != base::string16::npos) {
172 // Report channels with "stable" in them as stable (empty string). 172 // Report channels with "stable" in them as stable (empty string).
173 if (*scan == installer::kChromeChannelStableExplicit) 173 if (*scan == installer::kChromeChannelStableExplicit)
174 channel_name->erase(); 174 channel_name->erase();
175 else 175 else
176 channel_name->assign(*scan); 176 channel_name->assign(*scan);
177 return true; 177 return true;
178 } 178 }
179 } 179 }
180 // There may be modifiers present. Strip them off and see if we're left 180 // There may be modifiers present. Strip them off and see if we're left
181 // with the empty string (stable channel). 181 // with the empty string (stable channel).
182 std::wstring tmp_value = value_; 182 base::string16 tmp_value = value_;
183 for (int i = 0; i != NUM_MODIFIERS; ++i) { 183 for (int i = 0; i != NUM_MODIFIERS; ++i) {
184 SetModifier(static_cast<ModifierIndex>(i), false, &tmp_value); 184 SetModifier(static_cast<ModifierIndex>(i), false, &tmp_value);
185 } 185 }
186 if (tmp_value.empty()) { 186 if (tmp_value.empty()) {
187 channel_name->erase(); 187 channel_name->erase();
188 return true; 188 return true;
189 } 189 }
190 } 190 }
191 191
192 return false; 192 return false;
193 } 193 }
194 194
195 bool ChannelInfo::IsChrome() const { 195 bool ChannelInfo::IsChrome() const {
196 return HasModifier(MOD_CHROME, value_); 196 return HasModifier(MOD_CHROME, value_);
197 } 197 }
198 198
199 bool ChannelInfo::SetChrome(bool value) { 199 bool ChannelInfo::SetChrome(bool value) {
200 return SetModifier(MOD_CHROME, value, &value_); 200 return SetModifier(MOD_CHROME, value, &value_);
201 } 201 }
202 202
203 bool ChannelInfo::IsChromeFrame() const { 203 bool ChannelInfo::IsChromeFrame() const {
204 return HasModifier(MOD_CHROME_FRAME, value_); 204 return HasModifier(MOD_CHROME_FRAME, value_);
205 } 205 }
206 206
207 bool ChannelInfo::SetChromeFrame(bool value) { 207 bool ChannelInfo::SetChromeFrame(bool value) {
208 return SetModifier(MOD_CHROME_FRAME, value, &value_); 208 return SetModifier(MOD_CHROME_FRAME, value, &value_);
209 } 209 }
210 210
211 bool ChannelInfo::IsAppLauncher() const { 211 bool ChannelInfo::IsAppLauncher() const {
212 return HasModifier(MOD_APP_LAUNCHER, value_); 212 // -apphost and -applauncher have been deprecated.
213 return false;
213 } 214 }
214 215
215 bool ChannelInfo::SetAppLauncher(bool value) { 216 bool ChannelInfo::SetAppLauncher(bool value) {
216 // Unconditionally remove -apphost since it has been deprecated. 217 // Unconditionally remove -apphost and -applauncher since they have been
218 // deprecated.
217 bool changed_app_host = SetModifier(MOD_APP_HOST_DEPRECATED, false, &value_); 219 bool changed_app_host = SetModifier(MOD_APP_HOST_DEPRECATED, false, &value_);
218 bool changed_app_launcher = SetModifier(MOD_APP_LAUNCHER, value, &value_); 220 bool changed_app_launcher = SetModifier(MOD_APP_LAUNCHER_DEPRECATED,
221 false, &value_);
219 return changed_app_host || changed_app_launcher; 222 return changed_app_host || changed_app_launcher;
220 } 223 }
221 224
222 bool ChannelInfo::IsMultiInstall() const { 225 bool ChannelInfo::IsMultiInstall() const {
223 return HasModifier(MOD_MULTI_INSTALL, value_); 226 return HasModifier(MOD_MULTI_INSTALL, value_);
224 } 227 }
225 228
226 bool ChannelInfo::SetMultiInstall(bool value) { 229 bool ChannelInfo::SetMultiInstall(bool value) {
227 return SetModifier(MOD_MULTI_INSTALL, value, &value_); 230 return SetModifier(MOD_MULTI_INSTALL, value, &value_);
228 } 231 }
229 232
230 bool ChannelInfo::IsReadyMode() const { 233 bool ChannelInfo::IsReadyMode() const {
231 return HasModifier(MOD_READY_MODE, value_); 234 return HasModifier(MOD_READY_MODE, value_);
232 } 235 }
233 236
234 bool ChannelInfo::SetReadyMode(bool value) { 237 bool ChannelInfo::SetReadyMode(bool value) {
235 return SetModifier(MOD_READY_MODE, value, &value_); 238 return SetModifier(MOD_READY_MODE, value, &value_);
236 } 239 }
237 240
238 bool ChannelInfo::SetStage(const wchar_t* stage) { 241 bool ChannelInfo::SetStage(const wchar_t* stage) {
239 std::wstring::size_type position; 242 base::string16::size_type position;
240 std::wstring::size_type length; 243 base::string16::size_type length;
241 bool have_modifier = FindModifier(MOD_STAGE, value_, &position, &length); 244 bool have_modifier = FindModifier(MOD_STAGE, value_, &position, &length);
242 if (stage != NULL && *stage != L'\0') { 245 if (stage != NULL && *stage != L'\0') {
243 std::wstring stage_str(kModStage); 246 base::string16 stage_str(kModStage);
244 stage_str.append(stage); 247 stage_str.append(stage);
245 if (!have_modifier) { 248 if (!have_modifier) {
246 value_.insert(FindInsertionPoint(MOD_STAGE, value_), stage_str); 249 value_.insert(FindInsertionPoint(MOD_STAGE, value_), stage_str);
247 return true; 250 return true;
248 } 251 }
249 if (value_.compare(position, length, stage_str) != 0) { 252 if (value_.compare(position, length, stage_str) != 0) {
250 value_.replace(position, length, stage_str); 253 value_.replace(position, length, stage_str);
251 return true; 254 return true;
252 } 255 }
253 } else { 256 } else {
254 if (have_modifier) { 257 if (have_modifier) {
255 value_.erase(position, length); 258 value_.erase(position, length);
256 return true; 259 return true;
257 } 260 }
258 } 261 }
259 return false; 262 return false;
260 } 263 }
261 264
262 std::wstring ChannelInfo::GetStage() const { 265 base::string16 ChannelInfo::GetStage() const {
263 std::wstring::size_type position; 266 base::string16::size_type position;
264 std::wstring::size_type length; 267 base::string16::size_type length;
265 268
266 if (FindModifier(MOD_STAGE, value_, &position, &length)) { 269 if (FindModifier(MOD_STAGE, value_, &position, &length)) {
267 // Return the portion after the prefix. 270 // Return the portion after the prefix.
268 std::wstring::size_type pfx_length = 271 base::string16::size_type pfx_length =
269 std::wstring::traits_type::length(kModStage); 272 base::string16::traits_type::length(kModStage);
270 DCHECK_LE(pfx_length, length); 273 DCHECK_LE(pfx_length, length);
271 return value_.substr(position + pfx_length, length - pfx_length); 274 return value_.substr(position + pfx_length, length - pfx_length);
272 } 275 }
273 return std::wstring(); 276 return base::string16();
274 } 277 }
275 278
276 bool ChannelInfo::HasFullSuffix() const { 279 bool ChannelInfo::HasFullSuffix() const {
277 return HasModifier(SFX_FULL, value_); 280 return HasModifier(SFX_FULL, value_);
278 } 281 }
279 282
280 bool ChannelInfo::SetFullSuffix(bool value) { 283 bool ChannelInfo::SetFullSuffix(bool value) {
281 return SetModifier(SFX_FULL, value, &value_); 284 return SetModifier(SFX_FULL, value, &value_);
282 } 285 }
283 286
(...skipping 18 matching lines...) Expand all
302 305
303 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) { 306 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) {
304 ModifierIndex index = static_cast<ModifierIndex>(scan); 307 ModifierIndex index = static_cast<ModifierIndex>(scan);
305 modified = SetModifier(index, false, &value_) || modified; 308 modified = SetModifier(index, false, &value_) || modified;
306 } 309 }
307 310
308 return modified; 311 return modified;
309 } 312 }
310 313
311 } // namespace installer 314 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698