| OLD | NEW |
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/file_util.h" | 12 #include "base/win/scoped_handle.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Deletes all the files on path that match search_name pattern. | 16 // Deletes all the files on path that match search_name pattern. |
| 16 void DeleteFiles(const wchar_t* path, const wchar_t* search_name) { | 17 void DeleteFiles(const wchar_t* path, const wchar_t* search_name) { |
| 17 std::wstring name(path); | 18 std::wstring name(path); |
| 18 file_util::AppendToPath(&name, search_name); | 19 file_util::AppendToPath(&name, search_name); |
| 19 | 20 |
| 20 WIN32_FIND_DATA data; | 21 WIN32_FIND_DATA data; |
| 21 HANDLE handle = FindFirstFile(name.c_str(), &data); | 22 HANDLE handle = FindFirstFile(name.c_str(), &data); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 bool DeleteCacheFile(const FilePath& name) { | 60 bool DeleteCacheFile(const FilePath& name) { |
| 60 // We do a simple delete, without ever falling back to SHFileOperation, as the | 61 // We do a simple delete, without ever falling back to SHFileOperation, as the |
| 61 // version from base does. | 62 // version from base does. |
| 62 if (!DeleteFile(name.value().c_str())) { | 63 if (!DeleteFile(name.value().c_str())) { |
| 63 // There is an error, but we share delete access so let's see if there is a | 64 // There is an error, but we share delete access so let's see if there is a |
| 64 // file to open. Note that this code assumes that we have a handle to the | 65 // file to open. Note that this code assumes that we have a handle to the |
| 65 // file at all times (even now), so nobody can have a handle that prevents | 66 // file at all times (even now), so nobody can have a handle that prevents |
| 66 // us from opening the file again (unless it was deleted). | 67 // us from opening the file again (unless it was deleted). |
| 67 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; | 68 DWORD sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; |
| 68 DWORD access = SYNCHRONIZE; | 69 DWORD access = SYNCHRONIZE; |
| 69 ScopedHandle file(CreateFile(name.value().c_str(), access, sharing, NULL, | 70 base::win::ScopedHandle file(CreateFile( |
| 70 OPEN_EXISTING, 0, NULL)); | 71 name.value().c_str(), access, sharing, NULL, OPEN_EXISTING, 0, NULL)); |
| 71 if (file.IsValid()) | 72 if (file.IsValid()) |
| 72 return false; | 73 return false; |
| 73 | 74 |
| 74 // Most likely there is no file to open... and that's what we wanted. | 75 // Most likely there is no file to open... and that's what we wanted. |
| 75 } | 76 } |
| 76 return true; | 77 return true; |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace disk_cache | 80 } // namespace disk_cache |
| OLD | NEW |