Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Unified Diff: net/disk_cache/simple/simple_synchronous_entry.h

Issue 12192005: Add new simple disk cache backend. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase before remediation Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/disk_cache/simple/simple_synchronous_entry.h
diff --git a/net/disk_cache/simple/simple_synchronous_entry.h b/net/disk_cache/simple/simple_synchronous_entry.h
new file mode 100644
index 0000000000000000000000000000000000000000..af4b1e0bcb9627bd36ff78a859b9f54e8721f479
--- /dev/null
+++ b/net/disk_cache/simple/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_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_
+#define NET_DISK_CACHE_SIMPLE_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 SimpleSynchronousEntry {
+ public:
+ // All callbacks include the pointer to the SynchronousEntry being operated on
+ // if it is valid after the operation.
+ typedef base::Callback<void(SimpleSynchronousEntry*, 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;
+ };
+
+ SimpleSynchronousEntry(
+ const scoped_refptr<base::TaskRunner>& callback_runner,
+ const FilePath& path,
+ const std::string& key);
+
+ // Like Entry, the SimpleSynchronousEntry self releases when Close() is
+ // called.
+ ~SimpleSynchronousEntry();
+
+ 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_SIMPLE_SIMPLE_SYNCHRONOUS_ENTRY_H_

Powered by Google App Engine
This is Rietveld 408576698