Index: net/disk_cache/very_simple/very_simple_synchronous_entry.h |
diff --git a/net/disk_cache/very_simple/very_simple_synchronous_entry.h b/net/disk_cache/very_simple/very_simple_synchronous_entry.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7b4a0253671cbc8aae595e08b82d8ddcfd478b02 |
--- /dev/null |
+++ b/net/disk_cache/very_simple/very_simple_synchronous_entry.h |
@@ -0,0 +1,124 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_DISK_CACHE_VERY_SIMPLE_VERY_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
+#define NET_DISK_CACHE_VERY_SIMPLE_VERY_SIMPLE_SYNCHRONOUS_ENTRY_H_ |
+ |
+#include <string> |
+ |
+#include "base/callback_forward.h" |
+#include "base/file_path.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/platform_file.h" |
+#include "base/task_runner.h" |
+#include "base/time.h" |
+#include "net/base/completion_callback.h" |
+ |
+namespace base { |
+class SingleThreadTaskRunner; |
+} |
+ |
+namespace net { |
+class IOBuffer; |
+} |
+ |
+namespace disk_cache { |
+ |
+// Worker thread interface to the very simple cache. This interface is not |
+// thread safe, and callers must insure that it is only ever accessed from |
+// a single thread between synchronization points. |
+class VerySimpleSynchronousEntry { |
+ public: |
+ // All callbacks include the pointer to the SynchronousEntry being operated on |
+ // if it is valid after the operation. |
+ typedef base::Callback<void(VerySimpleSynchronousEntry*, int)> |
+ SynchronousEntryCallback; |
+ |
+ static void OpenEntry( |
+ const FilePath& path, |
+ const std::string& key, |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const SynchronousEntryCallback& callback); |
+ |
+ static void CreateEntry( |
+ const FilePath& path, |
+ const std::string& key, |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const SynchronousEntryCallback& callback); |
+ |
+ // Deletes an entry without first Opening it. Does not check if there is |
+ // already an Entry object in memory holding the open files. Be careful! This |
+ // is meant to be used by the Backend::DoomEntry() call. |callback| will be |
+ // run by |callback_runner|. |
+ static void DoomEntry(const FilePath& path, |
+ const std::string& key, |
+ scoped_refptr<base::TaskRunner> callback_runner, |
+ const net::CompletionCallback& callback); |
+ |
+ // N.B. DoomAndClose(), Close(), ReadData() and WriteData() may block on IO. |
+ void DoomAndClose(); |
+ void Close(); |
+ void ReadData(int index, |
+ int offset, |
+ net::IOBuffer* buf, |
+ int buf_len, |
+ const SynchronousEntryCallback& callback); |
+ void WriteData(int index, |
+ int offset, |
+ net::IOBuffer* buf, |
+ int buf_len, |
+ const SynchronousEntryCallback& callback, |
+ bool truncate); |
+ |
+ std::string key() const { return key_; } |
+ base::Time last_used() const { return last_used_; } |
+ base::Time last_modified() const { return last_modified_; } |
+ int32 data_size(int index) const { return data_size_[index]; } |
+ |
+ private: |
+ static const int kIndexCount = 3; |
+ |
+ struct EntryStatus { |
+ enum Mode { |
+ ENTRY_UNINITIALIZED, |
+ ENTRY_READER, |
+ ENTRY_WRITER, |
+ }; |
+ |
+ EntryStatus(); |
+ |
+ Mode mode; |
+ int64 data_offset; |
+ }; |
+ |
+ VerySimpleSynchronousEntry( |
+ const scoped_refptr<base::TaskRunner>& callback_runner, |
+ const FilePath& path, |
+ const std::string& key); |
+ |
+ // Like Entry, the VerySimpleSynchronousEntry self releases when Close() is |
+ // called. |
+ ~VerySimpleSynchronousEntry(); |
+ |
+ bool OpenOrCreateFiles(bool create); |
+ bool InitializeForOpen(); |
+ bool InitializeForCreate(); |
+ |
+ scoped_refptr<base::TaskRunner> callback_runner_; |
+ const FilePath path_; |
+ const std::string key_; |
+ |
+ bool initialized_; |
+ |
+ base::Time last_used_; |
+ base::Time last_modified_; |
+ int32 data_size_[kIndexCount]; |
+ |
+ base::PlatformFile files_[kIndexCount]; |
+ EntryStatus status_[kIndexCount]; |
+}; |
+ |
+} // namespace disk_cache |
+ |
+#endif // NET_DISK_CACHE_VERY_SIMPLE_VERY_SIMPLE_SYNCHRONOUS_ENTRY_H_ |