Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | 11 #include "base/strings/string_piece.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
|
gab
2017/02/14 16:57:56
rm these two and add string16.h
grt (UTC plus 2)
2017/02/14 21:04:23
Removed! string16.h is included in channel_info.h,
| |
| 13 #include "base/win/registry.h" | 13 #include "base/win/registry.h" |
| 14 #include "chrome/installer/util/google_update_constants.h" | 14 #include "chrome/installer/util/google_update_constants.h" |
| 15 #include "chrome/installer/util/util_constants.h" | 15 #include "chrome/installer/util/util_constants.h" |
| 16 | 16 |
| 17 using base::win::RegKey; | 17 using base::win::RegKey; |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const wchar_t kModChrome[] = L"-chrome"; | 21 const wchar_t kModChrome[] = L"-chrome"; |
| 22 const wchar_t kModChromeFrame[] = L"-chromeframe"; | 22 const wchar_t kModChromeFrame[] = L"-chromeframe"; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } | 131 } |
| 132 } else { | 132 } else { |
| 133 if (have_modifier) { | 133 if (have_modifier) { |
| 134 ap_value->erase(position, length); | 134 ap_value->erase(position, length); |
| 135 return true; | 135 return true; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 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 | 141 // 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 | 142 // "-foo:bar", returns "bar". Returns an empty string if the modifier |
| 168 // is not present or does not have a value. | 143 // is not present or does not have a value. |
| 169 base::string16 GetModifierValue(ModifierIndex modifier_index, | 144 base::string16 GetModifierValue(ModifierIndex modifier_index, |
| 170 const base::string16& value) { | 145 const base::string16& value) { |
| 171 base::string16::size_type position; | 146 base::string16::size_type position; |
| 172 base::string16::size_type length; | 147 base::string16::size_type length; |
| 173 | 148 |
| 174 if (FindModifier(modifier_index, value, &position, &length)) { | 149 if (FindModifier(modifier_index, value, &position, &length)) { |
| 175 // Return the portion after the prefix. | 150 // Return the portion after the prefix. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 197 LONG result = value_.empty() ? | 172 LONG result = value_.empty() ? |
| 198 key->DeleteValue(google_update::kRegApField) : | 173 key->DeleteValue(google_update::kRegApField) : |
| 199 key->WriteValue(google_update::kRegApField, value_.c_str()); | 174 key->WriteValue(google_update::kRegApField, value_.c_str()); |
| 200 if (result != ERROR_SUCCESS) { | 175 if (result != ERROR_SUCCESS) { |
| 201 LOG(ERROR) << "Failed writing channel info; result: " << result; | 176 LOG(ERROR) << "Failed writing channel info; result: " << result; |
| 202 return false; | 177 return false; |
| 203 } | 178 } |
| 204 return true; | 179 return true; |
| 205 } | 180 } |
| 206 | 181 |
| 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 { | 182 bool ChannelInfo::IsChrome() const { |
| 257 return HasModifier(MOD_CHROME, value_); | 183 return HasModifier(MOD_CHROME, value_); |
| 258 } | 184 } |
| 259 | 185 |
| 260 bool ChannelInfo::SetChrome(bool value) { | 186 bool ChannelInfo::SetChrome(bool value) { |
| 261 return SetModifier(MOD_CHROME, value, &value_); | 187 return SetModifier(MOD_CHROME, value, &value_); |
| 262 } | 188 } |
| 263 | 189 |
| 264 bool ChannelInfo::IsChromeFrame() const { | 190 bool ChannelInfo::IsChromeFrame() const { |
| 265 return HasModifier(MOD_CHROME_FRAME, value_); | 191 return HasModifier(MOD_CHROME_FRAME, value_); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 | 267 |
| 342 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) { | 268 for (int scan = 0; scan < NUM_MODIFIERS; ++scan) { |
| 343 ModifierIndex index = static_cast<ModifierIndex>(scan); | 269 ModifierIndex index = static_cast<ModifierIndex>(scan); |
| 344 modified = SetModifier(index, false, &value_) || modified; | 270 modified = SetModifier(index, false, &value_) || modified; |
| 345 } | 271 } |
| 346 | 272 |
| 347 return modified; | 273 return modified; |
| 348 } | 274 } |
| 349 | 275 |
| 350 } // namespace installer | 276 } // namespace installer |
| OLD | NEW |