| 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 |
| 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/file_util.h" | |
| 19 #include "base/files/file_enumerator.h" | 18 #include "base/files/file_enumerator.h" |
| 19 #include "base/files/file_util.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/win/registry.h" | 21 #include "base/win/registry.h" |
| 22 | 22 |
| 23 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the | 23 // The moves-pending-reboot is a MULTISZ registry key in the HKLM part of the |
| 24 // registry. | 24 // registry. |
| 25 const wchar_t kSessionManagerKey[] = | 25 const wchar_t kSessionManagerKey[] = |
| 26 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; | 26 L"SYSTEM\\CurrentControlSet\\Control\\Session Manager"; |
| 27 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; | 27 const wchar_t kPendingFileRenameOps[] = L"PendingFileRenameOperations"; |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 #ifndef NDEBUG | 76 #ifndef NDEBUG |
| 77 // Useful debugging code to track down what files are in use. | 77 // Useful debugging code to track down what files are in use. |
| 78 if (flags & MOVEFILE_REPLACE_EXISTING) { | 78 if (flags & MOVEFILE_REPLACE_EXISTING) { |
| 79 // Attempt to open the file exclusively. | 79 // Attempt to open the file exclusively. |
| 80 HANDLE file = ::CreateFileW(path.value().c_str(), | 80 HANDLE file = ::CreateFileW(path.value().c_str(), |
| 81 GENERIC_READ | GENERIC_WRITE, 0, NULL, | 81 GENERIC_READ | GENERIC_WRITE, 0, NULL, |
| 82 OPEN_EXISTING, 0, NULL); | 82 OPEN_EXISTING, 0, NULL); |
| 83 if (file != INVALID_HANDLE_VALUE) { | 83 if (file != INVALID_HANDLE_VALUE) { |
| 84 LOG(INFO) << " file not in use: " << path.value(); | 84 VLOG(1) << " file not in use: " << path.value(); |
| 85 ::CloseHandle(file); | 85 ::CloseHandle(file); |
| 86 } else { | 86 } else { |
| 87 PLOG(INFO) << " file in use (or not found?): " << path.value(); | 87 PLOG(WARNING) << " file in use (or not found?): " << path.value(); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 #endif | 90 #endif |
| 91 | 91 |
| 92 VLOG(1) << "Scheduled for deletion: " << path.value(); | 92 VLOG(1) << "Scheduled for deletion: " << path.value(); |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ScheduleDirectoryForDeletion(const base::FilePath& dir_name) { | 96 bool ScheduleDirectoryForDeletion(const base::FilePath& dir_name) { |
| 97 if (!IsSafeDirectoryNameForDeletion(dir_name)) { | 97 if (!IsSafeDirectoryNameForDeletion(dir_name)) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 ERROR_SUCCESS); | 389 ERROR_SUCCESS); |
| 390 } | 390 } |
| 391 std::vector<char> buffer; | 391 std::vector<char> buffer; |
| 392 StringArrayToMultiSZBytes(strings_to_keep, &buffer); | 392 StringArrayToMultiSZBytes(strings_to_keep, &buffer); |
| 393 DCHECK_GT(buffer.size(), 0U); | 393 DCHECK_GT(buffer.size(), 0U); |
| 394 if (buffer.empty()) | 394 if (buffer.empty()) |
| 395 return false; | 395 return false; |
| 396 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], | 396 return (session_manager_key.WriteValue(kPendingFileRenameOps, &buffer[0], |
| 397 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); | 397 buffer.size(), REG_MULTI_SZ) == ERROR_SUCCESS); |
| 398 } | 398 } |
| OLD | NEW |