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

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

Issue 14263005: Refactor our SimpleIndex file format and serialization to use Pickle instead of the previously bugg… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Philippe's comments Created 7 years, 8 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_index.h
diff --git a/net/disk_cache/simple/simple_index.h b/net/disk_cache/simple/simple_index.h
index 71f5bb473a2355d5ca22b6d0400c7a878264a1f1..38d2781116c0dc46d310a45ecb2fac5216a09385 100644
--- a/net/disk_cache/simple/simple_index.h
+++ b/net/disk_cache/simple/simple_index.h
@@ -9,13 +9,11 @@
#include <string>
#include "base/basictypes.h"
-#include "base/file_util.h"
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/hash_tables.h"
gavinp 2013/04/15 15:40:54 needs #include "base/ref_counted.h"
felipeg 2013/04/15 15:56:09 Done.
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
-#include "net/disk_cache/disk_cache.h"
-#include "net/disk_cache/simple/simple_disk_format.h"
namespace base {
class TaskRunner;
@@ -23,6 +21,55 @@ class TaskRunner;
namespace disk_cache {
+class EntryMetadata {
+ public:
+ EntryMetadata();
+ EntryMetadata(uint64 hash_key,
+ base::Time last_used_time,
+ uint64 entry_size);
+
+ uint64 GetHashKey() const { return hash_key_; }
+
+
+ base::Time GetLastUsedTime() const;
+ void SetLastUsedTime(const base::Time& last_used_time);
+
+ uint64 GetEntrySize() const { return entry_size_; }
+ void SetEntrySize(uint64 entry_size) { entry_size_ = entry_size; }
+
+ // If we had cheese we could make a sandwitch if we had bread. But we got
+ // only pickles.
gavinp 2013/04/15 15:40:54 Lose this comment.
felipeg 2013/04/15 15:56:09 Done.
+ // Serialize the data into the provided pickle.
+ void Serialize(Pickle* pickle) const;
+ bool DeSerialize(PickleIterator* it);
gavinp 2013/04/15 15:40:54 gavin@avclub:~/chrome/src$ git grep -n -e Deserial
felipeg 2013/04/15 15:56:09 Done.
+
+ // Merge two EntryMetadata instances.
+ // The existing current valid data in this object will prevail.
gavinp 2013/04/15 15:40:54 Nit: // Any existing valid data in |this| will pre
felipeg 2013/04/15 15:56:09 Done.
+ void MergeWith(const EntryMetadata& entry_metadata);
+
+ private:
+ // When adding new members here, you should update the Serialize() and
+ // DeSerialize() methods.
+ uint64 hash_key_;
+
+ // This is the serialized format from Time::ToInternalValue().
+ // If you want to make calculations/comparisons, you should use the
+ // base::Time() class. Use the GetLastUsedTime() method above.
+ int64 last_used_time_;
+
+ uint64 entry_size_; // Storage size in bytes.
+};
+
+// TODO(felipeg): This way we are storing the hash_key twice, as the
+// hash_map::key and as a member of EntryMetadata. We could save space if we
+// use a hash_set.
+typedef base::hash_map<uint64, EntryMetadata> EntrySet;
+
+void InsertInEntrySet(const EntryMetadata& entry_metadata,
+ EntrySet* entry_set);
+
+typedef base::Callback<void(scoped_ptr<EntrySet>)> IndexCompletionCallback;
+
// This class is not Thread-safe.
class SimpleIndex
: public base::SupportsWeakPtr<SimpleIndex> {
@@ -53,29 +100,6 @@ class SimpleIndex
bool UpdateEntrySize(const std::string& key, uint64 entry_size);
private:
- // TODO(felipeg): This way we are storing the hash_key twice (as the
- // hash_map::key and as a member of EntryMetadata. We could save space if we
- // use a hash_set.
- typedef base::hash_map<uint64, SimpleIndexFile::EntryMetadata> EntrySet;
-
- typedef base::Callback<void(scoped_ptr<EntrySet>)> MergeCallback;
-
- static void InsertInternal(
- EntrySet* entry_set,
- const SimpleIndexFile::EntryMetadata& entry_metadata);
-
- // Load index from disk. If it is corrupted, call RestoreFromDisk().
- static void LoadFromDisk(
- const base::FilePath& index_filename,
- const scoped_refptr<base::TaskRunner>& io_thread,
- const MergeCallback& merge_callback);
-
- // Enumerates all entries' files on disk and regenerates the index.
- static void RestoreFromDisk(
- const base::FilePath& index_filename,
- const scoped_refptr<base::TaskRunner>& io_thread,
- const MergeCallback& merge_callback);
-
// Must run on IO Thread.
void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries);
@@ -83,13 +107,6 @@ class SimpleIndex
// |out_buffer|.
void Serialize(std::string* out_buffer);
- bool OpenIndexFile();
- bool CloseIndexFile();
-
- static void UpdateFile(const base::FilePath& index_filename,
- const base::FilePath& temp_filename,
- scoped_ptr<std::string> buffer);
-
EntrySet entries_set_;
uint64 cache_size_; // Total cache storage size in bytes.

Powered by Google App Engine
This is Rietveld 408576698