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

Side by Side Diff: net/disk_cache/mem_entry_impl.h

Issue 120004: Introduce parent and child entries for MemEntryImpl... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/mem_backend_impl.cc ('k') | net/disk_cache/mem_entry_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_DISK_CACHE_MEM_ENTRY_IMPL_H__ 5 #ifndef NET_DISK_CACHE_MEM_ENTRY_IMPL_H_
6 #define NET_DISK_CACHE_MEM_ENTRY_IMPL_H__ 6 #define NET_DISK_CACHE_MEM_ENTRY_IMPL_H_
7 7
8 #include "net/disk_cache/disk_cache.h" 8 #include "net/disk_cache/disk_cache.h"
9 #include "testing/gtest/include/gtest/gtest_prod.h"
9 10
10 namespace disk_cache { 11 namespace disk_cache {
11 12
12 class MemBackendImpl; 13 class MemBackendImpl;
13 14
14 // This class implements the Entry interface for the memory-only cache. An 15 // This class implements the Entry interface for the memory-only cache. An
15 // object of this class represents a single entry on the cache. 16 // object of this class represents a single entry on the cache. We use two
17 // types of entries, parent and child to support sparse caching.
18 // A parent entry is non-sparse until a sparse method is invoked (i.e.
19 // ReadSparseData, WriteSparseData, GetAvailableRange) when sparse information
20 // is initialized. It then manages a list of child entries and delegates the
21 // sparse API calls to the child entries. It creates and deletes child entries
22 // and updates the list when needed.
23 // A child entry is used to carry partial cache content, non-sparse methods like
24 // ReadData and WriteData cannot be applied to them. The lifetime of a child
25 // entry is managed by the parent entry that created it except that the entry
26 // can be evicted independently. A child entry does not have a key and it is not
27 // registered in the backend's entry map. It is registered in the backend's
28 // ranking list to enable eviction of a partial content.
16 class MemEntryImpl : public Entry { 29 class MemEntryImpl : public Entry {
17 public: 30 public:
31 enum EntryType {
32 kParentEntry,
33 kChildEntry,
34 };
35
18 explicit MemEntryImpl(MemBackendImpl* backend); 36 explicit MemEntryImpl(MemBackendImpl* backend);
19 37
20 // Entry interface. 38 // Entry interface.
21 virtual void Doom(); 39 virtual void Doom();
22 virtual void Close(); 40 virtual void Close();
23 virtual std::string GetKey() const; 41 virtual std::string GetKey() const;
24 virtual base::Time GetLastUsed() const; 42 virtual base::Time GetLastUsed() const;
25 virtual base::Time GetLastModified() const; 43 virtual base::Time GetLastModified() const;
26 virtual int32 GetDataSize(int index) const; 44 virtual int32 GetDataSize(int index) const;
27 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, 45 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len,
28 net::CompletionCallback* completion_callback); 46 net::CompletionCallback* completion_callback);
29 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, 47 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len,
30 net::CompletionCallback* completion_callback, 48 net::CompletionCallback* completion_callback,
31 bool truncate); 49 bool truncate);
32 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 50 virtual int ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
33 net::CompletionCallback* completion_callback); 51 net::CompletionCallback* completion_callback);
34 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len, 52 virtual int WriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len,
35 net::CompletionCallback* completion_callback); 53 net::CompletionCallback* completion_callback);
36 virtual int GetAvailableRange(int64 offset, int len, int64* start); 54 virtual int GetAvailableRange(int64 offset, int len, int64* start);
37 55
38 // Performs the initialization of a EntryImpl that will be added to the 56 // Performs the initialization of a EntryImpl that will be added to the
39 // cache. 57 // cache.
40 bool CreateEntry(const std::string& key); 58 bool CreateEntry(const std::string& key);
41 59
42 // Permamently destroys this entry 60 // Performs the initialization of a MemEntryImpl as a child entry.
61 // TODO(hclam): this method should be private. Leave this as public because
62 // this is the only way to create a child entry. Move this method to private
63 // once child entries are created by parent entry.
64 bool CreateChildEntry(MemEntryImpl* parent);
65
66 // Permanently destroys this entry.
43 void InternalDoom(); 67 void InternalDoom();
44 68
69 void Open();
70 bool InUse();
71
45 MemEntryImpl* next() const { 72 MemEntryImpl* next() const {
46 return next_; 73 return next_;
47 } 74 }
48 75
49 MemEntryImpl* prev() const { 76 MemEntryImpl* prev() const {
50 return prev_; 77 return prev_;
51 } 78 }
52 79
53 void set_next(MemEntryImpl* next) { 80 void set_next(MemEntryImpl* next) {
54 next_ = next; 81 next_ = next;
55 } 82 }
56 83
57 void set_prev(MemEntryImpl* prev) { 84 void set_prev(MemEntryImpl* prev) {
58 prev_ = prev; 85 prev_ = prev;
59 } 86 }
60 87
61 void Open(); 88 EntryType type() const {
62 bool InUse(); 89 return type_;
90 }
63 91
64 private: 92 private:
65 enum { 93 enum {
66 NUM_STREAMS = 3 94 NUM_STREAMS = 3
67 }; 95 };
68 96
69 ~MemEntryImpl(); 97 ~MemEntryImpl();
70 98
71 // Grows and cleans up the data buffer. 99 // Grows and cleans up the data buffer.
72 void PrepareTarget(int index, int offset, int buf_len); 100 void PrepareTarget(int index, int offset, int buf_len);
73 101
74 // Updates ranking information. 102 // Updates ranking information.
75 void UpdateRank(bool modified); 103 void UpdateRank(bool modified);
76 104
77 std::string key_; 105 std::string key_;
78 std::vector<char> data_[NUM_STREAMS]; // User data. 106 std::vector<char> data_[NUM_STREAMS]; // User data.
79 int32 data_size_[NUM_STREAMS]; 107 int32 data_size_[NUM_STREAMS];
80 int ref_count_; 108 int ref_count_;
81 109
82 MemEntryImpl* next_; // Pointers for the LRU list. 110 MemEntryImpl* next_; // Pointers for the LRU list.
83 MemEntryImpl* prev_; 111 MemEntryImpl* prev_;
84 base::Time last_modified_; // LRU information. 112 MemEntryImpl* parent_; // Pointer to the parent entry.
113 base::Time last_modified_; // LRU information.
85 base::Time last_used_; 114 base::Time last_used_;
86 MemBackendImpl* backend_; // Back pointer to the cache. 115 MemBackendImpl* backend_; // Back pointer to the cache.
87 bool doomed_; // True if this entry was removed from the cache. 116 bool doomed_; // True if this entry was removed from the cache.
117 EntryType type_; // The type of this entry.
88 118
89 DISALLOW_EVIL_CONSTRUCTORS(MemEntryImpl); 119 DISALLOW_EVIL_CONSTRUCTORS(MemEntryImpl);
90 }; 120 };
91 121
92 } // namespace disk_cache 122 } // namespace disk_cache
93 123
94 #endif // NET_DISK_CACHE_MEM_ENTRY_IMPL_H__ 124 #endif // NET_DISK_CACHE_MEM_ENTRY_IMPL_H_
OLDNEW
« no previous file with comments | « net/disk_cache/mem_backend_impl.cc ('k') | net/disk_cache/mem_entry_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698