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

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

Issue 2476573004: Use InstallDetails in installer_util. (Closed)
Patch Set: sync to position 451835 Created 3 years, 10 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
« no previous file with comments | « chrome/installer/util/channel_info.h ('k') | chrome/installer/util/channel_info_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/string_piece.h"
12 #include "base/strings/string_util.h"
13 #include "base/win/registry.h" 11 #include "base/win/registry.h"
14 #include "chrome/installer/util/google_update_constants.h" 12 #include "chrome/installer/util/google_update_constants.h"
15 #include "chrome/installer/util/util_constants.h" 13 #include "chrome/installer/util/util_constants.h"
16 14
17 using base::win::RegKey; 15 using base::win::RegKey;
18 16
19 namespace { 17 namespace {
20 18
21 const wchar_t kModChrome[] = L"-chrome"; 19 const wchar_t kModChrome[] = L"-chrome";
22 const wchar_t kModChromeFrame[] = L"-chromeframe"; 20 const wchar_t kModChromeFrame[] = L"-chromeframe";
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 } 129 }
132 } else { 130 } else {
133 if (have_modifier) { 131 if (have_modifier) {
134 ap_value->erase(position, length); 132 ap_value->erase(position, length);
135 return true; 133 return true;
136 } 134 }
137 } 135 }
138 return false; 136 return false;
139 } 137 }
140 138
141 // Returns the position of the first case-insensitive match of |pattern| found
142 // in |str|, or base::string16::npos if none found. |pattern| must be non-empty
143 // lower-case ASCII, and may contain any number of '.' wildcard characters.
144 size_t FindSubstringMatch(const base::string16& str,
145 base::StringPiece16 pattern) {
146 DCHECK(!pattern.empty());
147 DCHECK(base::IsStringASCII(pattern));
148 DCHECK(pattern == base::StringPiece16(base::ToLowerASCII(pattern)));
149
150 if (str.size() < pattern.size())
151 return base::string16::npos;
152
153 for (size_t i = 0; i < str.size() - pattern.size() + 1; ++i) {
154 size_t j = 0;
155 while (j < pattern.size() &&
156 (pattern[j] == L'.' ||
157 pattern[j] == base::ToLowerASCII(str[i+j]))) {
158 ++j;
159 }
160 if (j == pattern.size())
161 return i;
162 }
163 return base::string16::npos;
164 }
165
166 // Returns the value of a modifier - that is for a modifier of the form 139 // Returns the value of a modifier - that is for a modifier of the form
167 // "-foo:bar", returns "bar". Returns an empty string if the modifier 140 // "-foo:bar", returns "bar". Returns an empty string if the modifier
168 // is not present or does not have a value. 141 // is not present or does not have a value.
169 base::string16 GetModifierValue(ModifierIndex modifier_index, 142 base::string16 GetModifierValue(ModifierIndex modifier_index,
170 const base::string16& value) { 143 const base::string16& value) {
171 base::string16::size_type position; 144 base::string16::size_type position;
172 base::string16::size_type length; 145 base::string16::size_type length;
173 146
174 if (FindModifier(modifier_index, value, &position, &length)) { 147 if (FindModifier(modifier_index, value, &position, &length)) {
175 // Return the portion after the prefix. 148 // Return the portion after the prefix.
(...skipping 21 matching lines...) Expand all
197 LONG result = value_.empty() ? 170 LONG result = value_.empty() ?
198 key->DeleteValue(google_update::kRegApField) : 171 key->DeleteValue(google_update::kRegApField) :
199 key->WriteValue(google_update::kRegApField, value_.c_str()); 172 key->WriteValue(google_update::kRegApField, value_.c_str());
200 if (result != ERROR_SUCCESS) { 173 if (result != ERROR_SUCCESS) {
201 LOG(ERROR) << "Failed writing channel info; result: " << result; 174 LOG(ERROR) << "Failed writing channel info; result: " << result;
202 return false; 175 return false;
203 } 176 }
204 return true; 177 return true;
205 } 178 }
206 179
207 bool ChannelInfo::GetChannelName(base::string16* channel_name) const {
208 static const wchar_t kChromeChannelBetaPattern[] = L"1.1-";
209 static const wchar_t kChromeChannelBetaX64Pattern[] = L"x64-beta";
210 static const wchar_t kChromeChannelDevPattern[] = L"2.0-d";
211 static const wchar_t kChromeChannelDevX64Pattern[] = L"x64-dev";
212
213 DCHECK(channel_name);
214 // Report channels that are empty string or contain "stable" as stable
215 // (empty string).
216 if (value_.empty() || value_.find(installer::kChromeChannelStableExplicit) !=
217 base::string16::npos) {
218 channel_name->erase();
219 return true;
220 }
221 // Report channels that match "/^2.0-d.*/i" as dev.
222 if (FindSubstringMatch(value_, kChromeChannelDevPattern) == 0) {
223 channel_name->assign(installer::kChromeChannelDev);
224 return true;
225 }
226 // Report channels that match "/.*x64-dev.*/" as dev.
227 if (value_.find(kChromeChannelDevX64Pattern) != base::string16::npos) {
228 channel_name->assign(installer::kChromeChannelDev);
229 return true;
230 }
231 // Report channels that match "/^1.1-.*/i" as beta.
232 if (FindSubstringMatch(value_, kChromeChannelBetaPattern) == 0) {
233 channel_name->assign(installer::kChromeChannelBeta);
234 return true;
235 }
236 // Report channels that match "/.*x64-beta.*/" as beta.
237 if (value_.find(kChromeChannelBetaX64Pattern) != base::string16::npos) {
238 channel_name->assign(installer::kChromeChannelBeta);
239 return true;
240 }
241
242 // There may be modifiers present. Strip them off and see if we're left
243 // with the empty string (stable channel).
244 base::string16 tmp_value = value_;
245 for (int i = 0; i != NUM_MODIFIERS; ++i) {
246 SetModifier(static_cast<ModifierIndex>(i), false, &tmp_value);
247 }
248 if (tmp_value.empty()) {
249 channel_name->erase();
250 return true;
251 }
252
253 return false;
254 }
255
256 bool ChannelInfo::IsChrome() const { 180 bool ChannelInfo::IsChrome() const {
257 return HasModifier(MOD_CHROME, value_); 181 return HasModifier(MOD_CHROME, value_);
258 } 182 }
259 183
260 bool ChannelInfo::SetChrome(bool value) { 184 bool ChannelInfo::SetChrome(bool value) {
261 return SetModifier(MOD_CHROME, value, &value_); 185 return SetModifier(MOD_CHROME, value, &value_);
262 } 186 }
263 187
264 bool ChannelInfo::IsChromeFrame() const { 188 bool ChannelInfo::IsChromeFrame() const {
265 return HasModifier(MOD_CHROME_FRAME, value_); 189 return HasModifier(MOD_CHROME_FRAME, value_);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 265
342 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) { 266 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) {
343 ModifierIndex index = static_cast<ModifierIndex>(scan); 267 ModifierIndex index = static_cast<ModifierIndex>(scan);
344 modified = SetModifier(index, false, &value_) || modified; 268 modified = SetModifier(index, false, &value_) || modified;
345 } 269 }
346 270
347 return modified; 271 return modified;
348 } 272 }
349 273
350 } // namespace installer 274 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/channel_info.h ('k') | chrome/installer/util/channel_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698