| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 #include "net/disk_cache/cache_util.h" | 5 #include "net/disk_cache/cache_util.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/scoped_handle.h" | |
| 12 #include "base/file_util.h" | 11 #include "base/file_util.h" |
| 13 | 12 |
| 14 namespace { | 13 namespace { |
| 15 | 14 |
| 16 // Deletes all the files on path that match search_name pattern. | 15 // Deletes all the files on path that match search_name pattern. |
| 17 void DeleteFiles(const wchar_t* path, const wchar_t* search_name) { | 16 void DeleteFiles(const wchar_t* path, const wchar_t* search_name) { |
| 18 std::wstring name(path); | 17 std::wstring name(path); |
| 19 file_util::AppendToPath(&name, search_name); | 18 file_util::AppendToPath(&name, search_name); |
| 20 | 19 |
| 21 WIN32_FIND_DATA data; | 20 WIN32_FIND_DATA data; |
| 22 ScopedFindFileHandle handle(FindFirstFile(name.c_str(), &data)); | 21 HANDLE handle = FindFirstFile(name.c_str(), &data); |
| 23 if (!handle.IsValid()) | 22 if (handle == INVALID_HANDLE_VALUE) |
| 24 return; | 23 return; |
| 25 | 24 |
| 26 std::wstring adjusted_path(path); | 25 std::wstring adjusted_path(path); |
| 27 adjusted_path += L'\\'; | 26 adjusted_path += L'\\'; |
| 28 do { | 27 do { |
| 29 if (data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY || | 28 if (data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY || |
| 30 data.dwFileAttributes == FILE_ATTRIBUTE_REPARSE_POINT) | 29 data.dwFileAttributes == FILE_ATTRIBUTE_REPARSE_POINT) |
| 31 continue; | 30 continue; |
| 32 std::wstring current(adjusted_path); | 31 std::wstring current(adjusted_path); |
| 33 current += data.cFileName; | 32 current += data.cFileName; |
| 34 DeleteFile(current.c_str()); | 33 DeleteFile(current.c_str()); |
| 35 } while (FindNextFile(handle, &data)); | 34 } while (FindNextFile(handle, &data)); |
| 35 |
| 36 FindClose(handle); |
| 36 } | 37 } |
| 37 | 38 |
| 38 } // namespace | 39 } // namespace |
| 39 | 40 |
| 40 namespace disk_cache { | 41 namespace disk_cache { |
| 41 | 42 |
| 42 bool MoveCache(const FilePath& from_path, const FilePath& to_path) { | 43 bool MoveCache(const FilePath& from_path, const FilePath& to_path) { |
| 43 // I don't want to use the shell version of move because if something goes | 44 // I don't want to use the shell version of move because if something goes |
| 44 // wrong, that version will attempt to move file by file and fail at the end. | 45 // wrong, that version will attempt to move file by file and fail at the end. |
| 45 if (!MoveFileEx(from_path.value().c_str(), to_path.value().c_str(), 0)) { | 46 if (!MoveFileEx(from_path.value().c_str(), to_path.value().c_str(), 0)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 69 OPEN_EXISTING, 0, NULL)); | 70 OPEN_EXISTING, 0, NULL)); |
| 70 if (file.IsValid()) | 71 if (file.IsValid()) |
| 71 return false; | 72 return false; |
| 72 | 73 |
| 73 // Most likely there is no file to open... and that's what we wanted. | 74 // Most likely there is no file to open... and that's what we wanted. |
| 74 } | 75 } |
| 75 return true; | 76 return true; |
| 76 } | 77 } |
| 77 | 78 |
| 78 } // namespace disk_cache | 79 } // namespace disk_cache |
| OLD | NEW |