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..e59cca37f756d2afcdcf1ac847a77141f178f12a 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" |
#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,54 @@ 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_; } |
+ |
gavinp
2013/04/15 15:59:19
Lose blank line.
gavinp
2013/04/15 19:27:46
Lose blank line.
felipeg
2013/04/15 20:05:03
Done.
|
+ |
+ 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; } |
+ |
+ // Serialize the data into the provided pickle. |
+ void Serialize(Pickle* pickle) const; |
+ bool DeSerialize(PickleIterator* it); |
+ |
+ // Merge two EntryMetadata instances. |
+ // The existing current valid data in this object will prevail. |
+ 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. |
+ // TODO(felipeg): Use Time() here. |
+ 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; |
gavinp
2013/04/15 15:59:19
Why can't these type definitions be public: in Sim
gavinp
2013/04/15 19:27:46
Why can't these type definitions be public: in Sim
felipeg
2013/04/15 20:05:03
Done.
|
+ |
+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,28 +99,17 @@ 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); |
+ const IndexCompletionCallback& completion_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); |
+ static scoped_ptr<EntrySet> RestoreFromDisk( |
+ const base::FilePath& index_filename); |
+ |
+ static void WriteToDiskInternal(const base::FilePath& index_filename, |
+ scoped_ptr<Pickle> pickle); |
// Must run on IO Thread. |
void MergeInitializingSet(scoped_ptr<EntrySet> index_file_entries); |
@@ -83,13 +118,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. |