Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2010 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| 11 #include "net/base/net_log.h" | |
| 11 #include "net/disk_cache/disk_cache.h" | 12 #include "net/disk_cache/disk_cache.h" |
| 12 #include "testing/gtest/include/gtest/gtest_prod.h" | 13 #include "testing/gtest/include/gtest/gtest_prod.h" |
| 13 | 14 |
| 14 namespace disk_cache { | 15 namespace disk_cache { |
| 15 | 16 |
| 16 class MemBackendImpl; | 17 class MemBackendImpl; |
| 17 | 18 |
| 18 // This class implements the Entry interface for the memory-only cache. An | 19 // This class implements the Entry interface for the memory-only cache. An |
| 19 // object of this class represents a single entry on the cache. We use two | 20 // object of this class represents a single entry on the cache. We use two |
| 20 // types of entries, parent and child to support sparse caching. | 21 // types of entries, parent and child to support sparse caching. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 47 public: | 48 public: |
| 48 enum EntryType { | 49 enum EntryType { |
| 49 kParentEntry, | 50 kParentEntry, |
| 50 kChildEntry, | 51 kChildEntry, |
| 51 }; | 52 }; |
| 52 | 53 |
| 53 explicit MemEntryImpl(MemBackendImpl* backend); | 54 explicit MemEntryImpl(MemBackendImpl* backend); |
| 54 | 55 |
| 55 // 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 |
| 56 // cache. | 57 // cache. |
| 57 bool CreateEntry(const std::string& key); | 58 bool CreateEntry(const std::string& key, net::NetLog* net_log); |
| 58 | 59 |
| 59 // Permanently destroys this entry. | 60 // Permanently destroys this entry. |
| 60 void InternalDoom(); | 61 void InternalDoom(); |
| 61 | 62 |
| 62 void Open(); | 63 void Open(); |
| 63 bool InUse(); | 64 bool InUse(); |
| 64 | 65 |
| 65 MemEntryImpl* next() const { | 66 MemEntryImpl* next() const { |
| 66 return next_; | 67 return next_; |
| 67 } | 68 } |
| 68 | 69 |
| 69 MemEntryImpl* prev() const { | 70 MemEntryImpl* prev() const { |
| 70 return prev_; | 71 return prev_; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void set_next(MemEntryImpl* next) { | 74 void set_next(MemEntryImpl* next) { |
| 74 next_ = next; | 75 next_ = next; |
| 75 } | 76 } |
| 76 | 77 |
| 77 void set_prev(MemEntryImpl* prev) { | 78 void set_prev(MemEntryImpl* prev) { |
| 78 prev_ = prev; | 79 prev_ = prev; |
| 79 } | 80 } |
| 80 | 81 |
| 81 EntryType type() const { | 82 EntryType type() const { |
| 82 return parent_ ? kChildEntry : kParentEntry; | 83 return parent_ ? kChildEntry : kParentEntry; |
| 83 } | 84 } |
| 84 | 85 |
| 86 net::BoundNetLog& net_log() { | |
| 87 return net_log_; | |
| 88 } | |
| 89 | |
| 85 // Entry interface. | 90 // Entry interface. |
| 86 virtual void Doom(); | 91 virtual void Doom(); |
| 87 virtual void Close(); | 92 virtual void Close(); |
| 88 virtual std::string GetKey() const; | 93 virtual std::string GetKey() const; |
| 89 virtual base::Time GetLastUsed() const; | 94 virtual base::Time GetLastUsed() const; |
| 90 virtual base::Time GetLastModified() const; | 95 virtual base::Time GetLastModified() const; |
| 91 virtual int32 GetDataSize(int index) const; | 96 virtual int32 GetDataSize(int index) const; |
| 92 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, | 97 virtual int ReadData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| 93 net::CompletionCallback* completion_callback); | 98 net::CompletionCallback* completion_callback); |
| 94 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | 99 virtual int WriteData(int index, int offset, net::IOBuffer* buf, int buf_len, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 106 | 111 |
| 107 private: | 112 private: |
| 108 typedef base::hash_map<int, MemEntryImpl*> EntryMap; | 113 typedef base::hash_map<int, MemEntryImpl*> EntryMap; |
| 109 | 114 |
| 110 enum { | 115 enum { |
| 111 NUM_STREAMS = 3 | 116 NUM_STREAMS = 3 |
| 112 }; | 117 }; |
| 113 | 118 |
| 114 ~MemEntryImpl(); | 119 ~MemEntryImpl(); |
| 115 | 120 |
| 121 int InternalReadData(int index, int offset, net::IOBuffer* buf, int buf_len); | |
|
rvargas (doing something else)
2011/03/04 21:39:16
nit: Add a comment for this block of methods.
mmenke
2011/03/07 17:46:41
Done.
| |
| 122 int InternalWriteData(int index, int offset, net::IOBuffer* buf, int buf_len, | |
| 123 bool truncate); | |
| 124 int InternalReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len); | |
| 125 int InternalWriteSparseData(int64 offset, net::IOBuffer* buf, int buf_len); | |
| 126 | |
| 116 // Old Entry interface. | 127 // Old Entry interface. |
| 117 int GetAvailableRange(int64 offset, int len, int64* start); | 128 int GetAvailableRange(int64 offset, int len, int64* start); |
| 118 | 129 |
| 119 // Grows and cleans up the data buffer. | 130 // Grows and cleans up the data buffer. |
| 120 void PrepareTarget(int index, int offset, int buf_len); | 131 void PrepareTarget(int index, int offset, int buf_len); |
| 121 | 132 |
| 122 // Updates ranking information. | 133 // Updates ranking information. |
| 123 void UpdateRank(bool modified); | 134 void UpdateRank(bool modified); |
| 124 | 135 |
| 125 // Initializes the children map and sparse info. This method is only called | 136 // Initializes the children map and sparse info. This method is only called |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 156 MemEntryImpl* next_; // Pointers for the LRU list. | 167 MemEntryImpl* next_; // Pointers for the LRU list. |
| 157 MemEntryImpl* prev_; | 168 MemEntryImpl* prev_; |
| 158 MemEntryImpl* parent_; // Pointer to the parent entry. | 169 MemEntryImpl* parent_; // Pointer to the parent entry. |
| 159 scoped_ptr<EntryMap> children_; | 170 scoped_ptr<EntryMap> children_; |
| 160 | 171 |
| 161 base::Time last_modified_; // LRU information. | 172 base::Time last_modified_; // LRU information. |
| 162 base::Time last_used_; | 173 base::Time last_used_; |
| 163 MemBackendImpl* backend_; // Back pointer to the cache. | 174 MemBackendImpl* backend_; // Back pointer to the cache. |
| 164 bool doomed_; // True if this entry was removed from the cache. | 175 bool doomed_; // True if this entry was removed from the cache. |
| 165 | 176 |
| 177 net::BoundNetLog net_log_; | |
| 178 | |
| 166 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); | 179 DISALLOW_COPY_AND_ASSIGN(MemEntryImpl); |
| 167 }; | 180 }; |
| 168 | 181 |
| 169 } // namespace disk_cache | 182 } // namespace disk_cache |
| 170 | 183 |
| 171 #endif // NET_DISK_CACHE_MEM_ENTRY_IMPL_H_ | 184 #endif // NET_DISK_CACHE_MEM_ENTRY_IMPL_H_ |
| OLD | NEW |