summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/cache_util_win.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 20:36:21 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-15 20:36:21 +0000
commita88d601f7f632a21afe88359d503559fa20d9e40 (patch)
tree23f4bd0f2492463cb6fadec07c845b5c0ca8e5e0 /net/disk_cache/cache_util_win.cc
parent5e40e26d39ea8bf3f6eb879e09e4e5b1f335b9ad (diff)
downloadchromium_src-a88d601f7f632a21afe88359d503559fa20d9e40.zip
chromium_src-a88d601f7f632a21afe88359d503559fa20d9e40.tar.gz
chromium_src-a88d601f7f632a21afe88359d503559fa20d9e40.tar.bz2
Second pass move the os dependent code apart on the disk cache.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@960 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/cache_util_win.cc')
-rw-r--r--net/disk_cache/cache_util_win.cc56
1 files changed, 33 insertions, 23 deletions
diff --git a/net/disk_cache/cache_util_win.cc b/net/disk_cache/cache_util_win.cc
index a66f2c3..cb38b5f 100644
--- a/net/disk_cache/cache_util_win.cc
+++ b/net/disk_cache/cache_util_win.cc
@@ -34,6 +34,33 @@
#include "base/scoped_handle.h"
#include "base/file_util.h"
+namespace {
+
+// Deletes all the files on path that match search_name pattern.
+// Do not call this function with "*" as search_name.
+bool DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
+ std::wstring name(path);
+ file_util::AppendToPath(&name, search_name);
+
+ WIN32_FIND_DATA data;
+ ScopedFindFileHandle handle(FindFirstFile(name.c_str(), &data));
+ if (!handle.IsValid()) {
+ DWORD error = GetLastError();
+ return ERROR_FILE_NOT_FOUND == error;
+ }
+ std::wstring adjusted_path(path);
+ adjusted_path += L'\\';
+ do {
+ std::wstring current(adjusted_path);
+ current += data.cFileName;
+ if (!DeleteFile(current.c_str()))
+ return false;
+ } while (FindNextFile(handle, &data));
+ return true;
+}
+
+} // namespace
+
namespace disk_cache {
int64 GetFreeDiskSpace(const std::wstring& path) {
@@ -66,29 +93,6 @@ bool MoveCache(const std::wstring& from_path, const std::wstring& to_path) {
return MoveFileEx(from_path.c_str(), to_path.c_str(), 0) != FALSE;
}
-// Deletes all the files on path that match search_name pattern.
-// Do not call this function with "*" as search_name.
-bool DeleteFiles(const wchar_t* path, const wchar_t* search_name) {
- std::wstring name(path);
- file_util::AppendToPath(&name, search_name);
-
- WIN32_FIND_DATA data;
- ScopedFindFileHandle handle(FindFirstFile(name.c_str(), &data));
- if (!handle.IsValid()) {
- DWORD error = GetLastError();
- return ERROR_FILE_NOT_FOUND == error;
- }
- std::wstring adjusted_path(path);
- adjusted_path += L'\\';
- do {
- std::wstring current(adjusted_path);
- current += data.cFileName;
- if (!DeleteFile(current.c_str()))
- return false;
- } while (FindNextFile(handle, &data));
- return true;
-}
-
void DeleteCache(const std::wstring& path, bool remove_folder) {
DeleteFiles(path.c_str(), L"f_*");
DeleteFiles(path.c_str(), L"data_*");
@@ -101,6 +105,12 @@ void DeleteCache(const std::wstring& path, bool remove_folder) {
RemoveDirectory(path.c_str());
}
+bool DeleteCacheFile(const std::wstring& name) {
+ // We do a simple delete, without ever falling back to SHFileOperation, as the
+ // version from base does.
+ return DeleteFile(name.c_str()) ? true : false;
+}
+
void WaitForPendingIO(int num_pending_io) {
while (num_pending_io) {
// Asynchronous IO operations may be in flight and the completion may end