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

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

Issue 1220653002: Fix some case-insensitive cases for StartsWith (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: grt's review comments, Mac fix Created 5 years, 5 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/gcapi/gcapi_omaha_experiment.cc ('k') | chrome/installer/util/install_util.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 // This file defines helper methods used to schedule files for deletion 5 // This file defines helper methods used to schedule files for deletion
6 // on next reboot. The code here is heavily borrowed and simplified from 6 // on next reboot. The code here is heavily borrowed and simplified from
7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and 7 // http://code.google.com/p/omaha/source/browse/trunk/common/file.cc and
8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc 8 // http://code.google.com/p/omaha/source/browse/trunk/common/utils.cc
9 // 9 //
10 // This implementation really is not fast, so do not use it where that will 10 // This implementation really is not fast, so do not use it where that will
11 // matter. 11 // matter.
12 12
13 #include "chrome/installer/util/delete_after_reboot_helper.h" 13 #include "chrome/installer/util/delete_after_reboot_helper.h"
14 14
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/files/file_enumerator.h" 18 #include "base/files/file_enumerator.h"
19 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
20 #include "base/numerics/safe_conversions.h"
20 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
21 #include "base/win/registry.h" 22 #include "base/win/registry.h"
22 23
23 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the 24 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the
24 // registry. 25 // registry.
25 const wchar_t kSessionManagerKey[] = 26 const wchar_t kSessionManagerKey[] =
26 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; 27 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager";
27 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; 28 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations";
28 29
29 namespace { 30 namespace {
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 // null-terminated wchar_t strings terminated by an additional null character. 320 // null-terminated wchar_t strings terminated by an additional null character.
320 // Stick this into a vector of strings for clarity. 321 // Stick this into a vector of strings for clarity.
321 HRESULT hr = MultiSZBytesToStringArray(&buffer[0], buffer.size(), 322 HRESULT hr = MultiSZBytesToStringArray(&buffer[0], buffer.size(),
322 pending_moves); 323 pending_moves);
323 return hr; 324 return hr;
324 } 325 }
325 326
326 bool MatchPendingDeletePath(const base::FilePath& short_form_needle, 327 bool MatchPendingDeletePath(const base::FilePath& short_form_needle,
327 const base::FilePath& reg_path) { 328 const base::FilePath& reg_path) {
328 // Stores the path stored in each entry. 329 // Stores the path stored in each entry.
329 std::wstring match_path(reg_path.value()); 330 base::string16 match_path(reg_path.value());
330 331
331 // First chomp the prefix since that will mess up GetShortPathName. 332 // First chomp the prefix since that will mess up GetShortPathName.
332 std::wstring prefix(L"\\??\\"); 333 base::StringPiece16 prefix(L"\\??\\");
333 if (base::StartsWith(match_path, prefix, false)) 334 if (base::StartsWith(match_path, prefix, base::CompareCase::SENSITIVE))
334 match_path = match_path.substr(4); 335 match_path = match_path.substr(prefix.size());
335 336
336 // Get the short path name of the entry. 337 // Get the short path name of the entry.
337 base::FilePath short_match_path(GetShortPathName(base::FilePath(match_path))); 338 base::FilePath short_match_path(GetShortPathName(base::FilePath(match_path)));
338 339
339 // Now compare the paths. If it isn't one we're looking for, add it 340 // Now compare the paths. It's a match if short_form_needle is a
340 // to the list to keep. 341 // case-insensitive prefix of short_match_path.
341 return base::StartsWith(short_match_path.value(), short_form_needle.value(), 342 if (short_match_path.value().size() < short_form_needle.value().size())
342 false); 343 return false;
344 DWORD prefix_len =
345 base::saturated_cast<DWORD>(short_form_needle.value().size());
346 return ::CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
347 short_match_path.value().data(), prefix_len,
348 short_form_needle.value().data(), prefix_len) ==
349 CSTR_EQUAL;
343 } 350 }
344 351
345 // Removes all pending moves for the given |directory| and any contained 352 // Removes all pending moves for the given |directory| and any contained
346 // files or subdirectories. Returns true on success 353 // files or subdirectories. Returns true on success
347 bool RemoveFromMovesPendingReboot(const base::FilePath& directory) { 354 bool RemoveFromMovesPendingReboot(const base::FilePath& directory) {
348 std::vector<PendingMove> pending_moves; 355 std::vector<PendingMove> pending_moves;
349 HRESULT hr = GetPendingMovesValue(&pending_moves); 356 HRESULT hr = GetPendingMovesValue(&pending_moves);
350 if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { 357 if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) {
351 // No pending moves, nothing to do. 358 // No pending moves, nothing to do.
352 return true; 359 return true;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 ERROR_SUCCESS); 397 ERROR_SUCCESS);
391 } 398 }
392 std::vector<char> buffer; 399 std::vector<char> buffer;
393 StringArrayToMultiSZBytes(strings_to_keep, &buffer); 400 StringArrayToMultiSZBytes(strings_to_keep, &buffer);
394 DCHECK_GT(buffer.size(), 0U); 401 DCHECK_GT(buffer.size(), 0U);
395 if (buffer.empty()) 402 if (buffer.empty())
396 return false; 403 return false;
397 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], 404 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0],
398 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); 405 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS);
399 } 406 }
OLDNEW
« no previous file with comments | « chrome/installer/gcapi/gcapi_omaha_experiment.cc ('k') | chrome/installer/util/install_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698