Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 // null-terminated wchar_t strings terminated by an additional null character. | 319 // null-terminated wchar_t strings terminated by an additional null character. |
| 320 // Stick this into a vector of strings for clarity. | 320 // Stick this into a vector of strings for clarity. |
| 321 HRESULT hr = MultiSZBytesToStringArray(&buffer[0], buffer.size(), | 321 HRESULT hr = MultiSZBytesToStringArray(&buffer[0], buffer.size(), |
| 322 pending_moves); | 322 pending_moves); |
| 323 return hr; | 323 return hr; |
| 324 } | 324 } |
| 325 | 325 |
| 326 bool MatchPendingDeletePath(const base::FilePath& short_form_needle, | 326 bool MatchPendingDeletePath(const base::FilePath& short_form_needle, |
| 327 const base::FilePath& reg_path) { | 327 const base::FilePath& reg_path) { |
| 328 // Stores the path stored in each entry. | 328 // Stores the path stored in each entry. |
| 329 std::wstring match_path(reg_path.value()); | 329 base::string16 match_path(reg_path.value()); |
| 330 | 330 |
| 331 // First chomp the prefix since that will mess up GetShortPathName. | 331 // First chomp the prefix since that will mess up GetShortPathName. |
| 332 std::wstring prefix(L"\\??\\"); | 332 base::string16 prefix(L"\\??\\"); |
|
grt (UTC plus 2)
2015/07/01 17:55:42
nit: base::StringPiece16 prefix(L"\\??\\"); to avo
| |
| 333 if (base::StartsWith(match_path, prefix, false)) | 333 if (base::StartsWith(match_path, prefix, base::CompareCase::SENSITIVE)) |
| 334 match_path = match_path.substr(4); | 334 match_path = match_path.substr(4); |
|
grt (UTC plus 2)
2015/07/01 17:55:41
nit: 4 -> prefix.size()
| |
| 335 | 335 |
| 336 // Get the short path name of the entry. | 336 // Get the short path name of the entry. |
| 337 base::FilePath short_match_path(GetShortPathName(base::FilePath(match_path))); | 337 base::FilePath short_match_path(GetShortPathName(base::FilePath(match_path))); |
| 338 | 338 |
| 339 // Now compare the paths. If it isn't one we're looking for, add it | 339 // Now compare the paths. It's a match if short_form_needle is a |
| 340 // to the list to keep. | 340 // case-insensitive prefix of short_match_path. |
| 341 return base::StartsWith(short_match_path.value(), short_form_needle.value(), | 341 if (short_match_path.value().size() < short_form_needle.value().size()) |
| 342 false); | 342 return false; |
| 343 DWORD prefix_len = static_cast<DWORD>(short_form_needle.value().size()); | |
|
grt (UTC plus 2)
2015/07/01 17:55:42
base::saturated_cast<DWORD, size_t>()?
| |
| 344 return ::CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE, | |
| 345 short_match_path.value().data(), prefix_len, | |
| 346 short_form_needle.value().data(), prefix_len) == | |
| 347 CSTR_EQUAL; | |
| 343 } | 348 } |
| 344 | 349 |
| 345 // Removes all pending moves for the given |directory| and any contained | 350 // Removes all pending moves for the given |directory| and any contained |
| 346 // files or subdirectories. Returns true on success | 351 // files or subdirectories. Returns true on success |
| 347 bool RemoveFromMovesPendingReboot(const base::FilePath& directory) { | 352 bool RemoveFromMovesPendingReboot(const base::FilePath& directory) { |
| 348 std::vector<PendingMove> pending_moves; | 353 std::vector<PendingMove> pending_moves; |
| 349 HRESULT hr = GetPendingMovesValue(&pending_moves); | 354 HRESULT hr = GetPendingMovesValue(&pending_moves); |
| 350 if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { | 355 if (hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)) { |
| 351 // No pending moves, nothing to do. | 356 // No pending moves, nothing to do. |
| 352 return true; | 357 return true; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 ERROR_SUCCESS); | 395 ERROR_SUCCESS); |
| 391 } | 396 } |
| 392 std::vector<char> buffer; | 397 std::vector<char> buffer; |
| 393 StringArrayToMultiSZBytes(strings_to_keep, &buffer); | 398 StringArrayToMultiSZBytes(strings_to_keep, &buffer); |
| 394 DCHECK_GT(buffer.size(), 0U); | 399 DCHECK_GT(buffer.size(), 0U); |
| 395 if (buffer.empty()) | 400 if (buffer.empty()) |
| 396 return false; | 401 return false; |
| 397 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], | 402 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], |
| 398 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); | 403 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); |
| 399 } | 404 } |
| OLD | NEW |