diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 20:36:21 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-15 20:36:21 +0000 |
commit | a88d601f7f632a21afe88359d503559fa20d9e40 (patch) | |
tree | 23f4bd0f2492463cb6fadec07c845b5c0ca8e5e0 /net/disk_cache | |
parent | 5e40e26d39ea8bf3f6eb879e09e4e5b1f335b9ad (diff) | |
download | chromium_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')
-rw-r--r-- | net/disk_cache/block_files.cc | 1 | ||||
-rw-r--r-- | net/disk_cache/cache_util.h | 3 | ||||
-rw-r--r-- | net/disk_cache/cache_util_posix.cc | 15 | ||||
-rw-r--r-- | net/disk_cache/cache_util_win.cc | 56 | ||||
-rw-r--r-- | net/disk_cache/entry_impl.cc | 3 | ||||
-rw-r--r-- | net/disk_cache/file.h | 2 | ||||
-rw-r--r-- | net/disk_cache/file_posix.cc | 125 | ||||
-rw-r--r-- | net/disk_cache/file_win.cc (renamed from net/disk_cache/file.cc) | 2 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_posix.cc | 65 | ||||
-rw-r--r-- | net/disk_cache/mapped_file_win.cc (renamed from net/disk_cache/mapped_file.cc) | 0 | ||||
-rw-r--r-- | net/disk_cache/rankings.cc | 6 | ||||
-rw-r--r-- | net/disk_cache/trace.cc | 17 |
12 files changed, 261 insertions, 34 deletions
diff --git a/net/disk_cache/block_files.cc b/net/disk_cache/block_files.cc index db49e3a..3bf35f3 100644 --- a/net/disk_cache/block_files.cc +++ b/net/disk_cache/block_files.cc @@ -30,7 +30,6 @@ #include "net/disk_cache/block_files.h" #include "base/histogram.h" -#include "base/scoped_handle.h" #include "base/string_util.h" #include "base/time.h" #include "net/disk_cache/file_lock.h" diff --git a/net/disk_cache/cache_util.h b/net/disk_cache/cache_util.h index f6815c9..dcb82c2 100644 --- a/net/disk_cache/cache_util.h +++ b/net/disk_cache/cache_util.h @@ -51,6 +51,9 @@ bool MoveCache(const std::wstring& from_path, const std::wstring& to_path); // delete the folder itself. void DeleteCache(const std::wstring& path, bool remove_folder); +// Deletes a cache file. +bool DeleteCacheFile(const std::wstring& name); + // Blocks until |num_pending_io| IO operations complete. void WaitForPendingIO(int num_pending_io); diff --git a/net/disk_cache/cache_util_posix.cc b/net/disk_cache/cache_util_posix.cc index 10e0b93..a6055fa 100644 --- a/net/disk_cache/cache_util_posix.cc +++ b/net/disk_cache/cache_util_posix.cc @@ -27,10 +27,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include "net/cache_util.h" +#include "net/disk_cache/cache_util.h" #include "base/file_util.h" #include "base/logging.h" +#include "base/notimplemented.h" namespace disk_cache { @@ -54,9 +55,19 @@ void DeleteCache(const std::wstring& path, bool remove_folder) { file_util::Delete(path, false); } else { std::wstring name(path); - file_util::AppendToPath(name, L"*"); + file_util::AppendToPath(&name, L"*"); file_util::Delete(name, false); } } +bool DeleteCacheFile(const std::wstring& name) { + return file_util::Delete(name, false); +} + +void WaitForPendingIO(int num_pending_io) { + if (num_pending_io) { + NOTIMPLEMENTED(); + } +} + } // namespace disk_cache 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 diff --git a/net/disk_cache/entry_impl.cc b/net/disk_cache/entry_impl.cc index 3d3ada2..4baa869 100644 --- a/net/disk_cache/entry_impl.cc +++ b/net/disk_cache/entry_impl.cc @@ -34,6 +34,7 @@ #include "base/string_util.h" #include "net/base/net_errors.h" #include "net/disk_cache/backend_impl.h" +#include "net/disk_cache/cache_util.h" namespace { @@ -574,7 +575,7 @@ void EntryImpl::DeleteData(Addr address, int index) { if (files_[index]) files_[index] = NULL; // Releases the object. - if (!DeleteFile(backend_->GetFileName(address).c_str())) + if (!DeleteCacheFile(backend_->GetFileName(address))) LOG(ERROR) << "Failed to delete " << backend_->GetFileName(address) << " from the cache."; } else { diff --git a/net/disk_cache/file.h b/net/disk_cache/file.h index 93b9a0b..64a71b9 100644 --- a/net/disk_cache/file.h +++ b/net/disk_cache/file.h @@ -62,7 +62,7 @@ class File : public base::RefCounted<File> { // Initializes the object to point to a given file. The file must aready exist // on disk, and allow shared read and write. - bool Init(const std::wstring name); + bool Init(const std::wstring& name); // Returns the handle or file descriptor. OSFile os_file() const; diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc new file mode 100644 index 0000000..297fcab --- /dev/null +++ b/net/disk_cache/file_posix.cc @@ -0,0 +1,125 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "net/disk_cache/file.h" + +#include "base/notimplemented.h" +#include "net/disk_cache/disk_cache.h" + +namespace disk_cache { + +File::File(OSFile file) + : init_(true), os_file_(0) { +} + +bool File::Init(const std::wstring& name) { + NOTIMPLEMENTED(); + return false; +} + +File::~File() { +} + +OSFile File::os_file() const { + return os_file_; +} + +bool File::IsValid() const { + if (!init_) + return false; + return (0 != os_file_); +} + +bool File::Read(void* buffer, size_t buffer_len, size_t offset) { + DCHECK(init_); + if (buffer_len > ULONG_MAX || offset > LONG_MAX) + return false; + + NOTIMPLEMENTED(); + return false; +} + +bool File::Write(const void* buffer, size_t buffer_len, size_t offset) { + DCHECK(init_); + if (buffer_len > ULONG_MAX || offset > ULONG_MAX) + return false; + + NOTIMPLEMENTED(); + return false; +} + +// We have to increase the ref counter of the file before performing the IO to +// prevent the completion to happen with an invalid handle (if the file is +// closed while the IO is in flight). +bool File::Read(void* buffer, size_t buffer_len, size_t offset, + FileIOCallback* callback, bool* completed) { + DCHECK(init_); + if (buffer_len > ULONG_MAX || offset > ULONG_MAX) + return false; + + NOTIMPLEMENTED(); + return false; +} + +bool File::Write(const void* buffer, size_t buffer_len, size_t offset, + FileIOCallback* callback, bool* completed) { + DCHECK(init_); + return AsyncWrite(buffer, buffer_len, offset, true, callback, completed); +} + +bool File::PostWrite(const void* buffer, size_t buffer_len, size_t offset) { + DCHECK(init_); + return AsyncWrite(buffer, buffer_len, offset, false, NULL, NULL); +} + +bool File::AsyncWrite(const void* buffer, size_t buffer_len, size_t offset, + bool notify, FileIOCallback* callback, bool* completed) { + DCHECK(init_); + if (buffer_len > ULONG_MAX || offset > ULONG_MAX) + return false; + + NOTIMPLEMENTED(); + return false; +} + +bool File::SetLength(size_t length) { + DCHECK(init_); + if (length > ULONG_MAX) + return false; + + NOTIMPLEMENTED(); + return false; +} + +size_t File::GetLength() { + DCHECK(init_); + return 0; +} + +} // namespace disk_cache diff --git a/net/disk_cache/file.cc b/net/disk_cache/file_win.cc index 41ed2b7..eafdce5 100644 --- a/net/disk_cache/file.cc +++ b/net/disk_cache/file_win.cc @@ -118,7 +118,7 @@ File::File(OSFile file) sync_os_file_(file) { } -bool File::Init(const std::wstring name) { +bool File::Init(const std::wstring& name) { DCHECK(!init_); if (init_) return false; diff --git a/net/disk_cache/mapped_file_posix.cc b/net/disk_cache/mapped_file_posix.cc new file mode 100644 index 0000000..4c9d8b5 --- /dev/null +++ b/net/disk_cache/mapped_file_posix.cc @@ -0,0 +1,65 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "net/disk_cache/mapped_file.h" + +#include "net/disk_cache/disk_cache.h" + +namespace disk_cache { + +void* MappedFile::Init(const std::wstring name, size_t size) { + DCHECK(!init_); + if (init_ || !File::Init(name)) + return NULL; + + buffer_ = NULL; + init_ = true; + + return buffer_; +} + +MappedFile::~MappedFile() { + if (!init_) + return; + + if (buffer_) { + } +} + +bool MappedFile::Load(const FileBlock* block) { + size_t offset = block->offset() + view_size_; + return Read(block->buffer(), block->size(), offset); +} + +bool MappedFile::Store(const FileBlock* block) { + size_t offset = block->offset() + view_size_; + return Write(block->buffer(), block->size(), offset); +} + +} // namespace disk_cache diff --git a/net/disk_cache/mapped_file.cc b/net/disk_cache/mapped_file_win.cc index c963063..c963063 100644 --- a/net/disk_cache/mapped_file.cc +++ b/net/disk_cache/mapped_file_win.cc diff --git a/net/disk_cache/rankings.cc b/net/disk_cache/rankings.cc index 42667cc..9e14d04 100644 --- a/net/disk_cache/rankings.cc +++ b/net/disk_cache/rankings.cc @@ -35,7 +35,7 @@ #include "net/disk_cache/errors.h" // This is used by crash_cache.exe to generate unit test files. -extern disk_cache::RankCrashes g_rankings_crash = disk_cache::NO_CRASH; +disk_cache::RankCrashes g_rankings_crash = disk_cache::NO_CRASH; namespace { @@ -91,6 +91,7 @@ enum CrashLocation { // Generates a crash on debug builds, acording to the value of g_rankings_crash. // This used by crash_cache.exe to generate unit-test files. void GenerateCrash(CrashLocation location) { +#if defined(OS_WIN) #ifndef NDEBUG if (disk_cache::NO_CRASH == g_rankings_crash) return; @@ -169,7 +170,8 @@ void GenerateCrash(CrashLocation location) { NOTREACHED(); return; } -#endif +#endif // NDEBUG +#endif // OS_WIN } } // namespace diff --git a/net/disk_cache/trace.cc b/net/disk_cache/trace.cc index 5f97b7d..0339e35 100644 --- a/net/disk_cache/trace.cc +++ b/net/disk_cache/trace.cc @@ -27,17 +27,20 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#include <windows.h> - #include "net/disk_cache/trace.h" +#if defined(OS_WIN) +#include <windows.h> +#endif + #include "base/logging.h" +#include "base/notimplemented.h" // Change this value to 1 to enable tracing on a release build. By default, // tracing is enabled only on debug builds. #define ENABLE_TRACING 0 -#if _DEBUG +#ifndef NDEBUG #undef ENABLE_TRACING #define ENABLE_TRACING 1 #endif @@ -56,7 +59,11 @@ struct TraceBuffer { TraceBuffer* s_trace_buffer = NULL; void DebugOutput(char* msg) { +#if defined(OS_WIN) OutputDebugStringA(msg); +#else + NOTIMPLEMENTED(); +#endif } } // namespace @@ -86,7 +93,11 @@ void Trace(const char* format, ...) { va_list ap; va_start(ap, format); +#if defined(OS_WIN) vsprintf_s(s_trace_buffer->buffer[s_trace_buffer->current], format, ap); +#else + NOTIMPLEMENTED(); +#endif s_trace_buffer->num_traces++; s_trace_buffer->current++; if (s_trace_buffer->current == kNumberOfEntries) |