| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See net/disk_cache/disk_cache.h for the public interface. | 5 // See net/disk_cache/disk_cache.h for the public interface. |
| 6 | 6 |
| 7 #ifndef NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ | 7 #ifndef NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| 8 #define NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ | 8 #define NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "net/disk_cache/blockfile/addr.h" | 14 #include "net/disk_cache/blockfile/addr.h" |
| 15 #include "net/disk_cache/blockfile/mapped_file.h" | 15 #include "net/disk_cache/blockfile/mapped_file.h" |
| 16 #include "net/disk_cache/blockfile/storage_block.h" | 16 #include "net/disk_cache/blockfile/storage_block.h" |
| 17 | 17 |
| 18 namespace disk_cache { | 18 namespace disk_cache { |
| 19 | 19 |
| 20 class BackendImpl; | 20 class BackendImpl; |
| 21 struct LruData; | 21 struct LruData; |
| 22 struct RankingsNode; | 22 struct RankingsNode; |
| 23 typedef StorageBlock<RankingsNode> CacheRankingsBlock; | 23 typedef StorageBlock<RankingsNode> CacheRankingsBlock; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 LOW_USE, // List of entries with low reuse. | 59 LOW_USE, // List of entries with low reuse. |
| 60 HIGH_USE, // List of entries with high reuse. | 60 HIGH_USE, // List of entries with high reuse. |
| 61 RESERVED, // Reserved for future use. | 61 RESERVED, // Reserved for future use. |
| 62 DELETED, // List of recently deleted or doomed entries. | 62 DELETED, // List of recently deleted or doomed entries. |
| 63 LAST_ELEMENT | 63 LAST_ELEMENT |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // This class provides a specialized version of scoped_ptr, that calls | 66 // This class provides a specialized version of scoped_ptr, that calls |
| 67 // Rankings whenever a CacheRankingsBlock is deleted, to keep track of cache | 67 // Rankings whenever a CacheRankingsBlock is deleted, to keep track of cache |
| 68 // iterators that may go stale. | 68 // iterators that may go stale. |
| 69 class ScopedRankingsBlock : public scoped_ptr<CacheRankingsBlock> { | 69 class ScopedRankingsBlock : public std::unique_ptr<CacheRankingsBlock> { |
| 70 public: | 70 public: |
| 71 ScopedRankingsBlock(); | 71 ScopedRankingsBlock(); |
| 72 explicit ScopedRankingsBlock(Rankings* rankings); | 72 explicit ScopedRankingsBlock(Rankings* rankings); |
| 73 ScopedRankingsBlock(Rankings* rankings, CacheRankingsBlock* node); | 73 ScopedRankingsBlock(Rankings* rankings, CacheRankingsBlock* node); |
| 74 | 74 |
| 75 ~ScopedRankingsBlock() { | 75 ~ScopedRankingsBlock() { |
| 76 rankings_->FreeRankingsBlock(get()); | 76 rankings_->FreeRankingsBlock(get()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void set_rankings(Rankings* rankings) { | 79 void set_rankings(Rankings* rankings) { |
| 80 rankings_ = rankings; | 80 rankings_ = rankings; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // scoped_ptr::reset will delete the object. | 83 // scoped_ptr::reset will delete the object. |
| 84 void reset(CacheRankingsBlock* p = NULL) { | 84 void reset(CacheRankingsBlock* p = NULL) { |
| 85 if (p != get()) | 85 if (p != get()) |
| 86 rankings_->FreeRankingsBlock(get()); | 86 rankings_->FreeRankingsBlock(get()); |
| 87 scoped_ptr<CacheRankingsBlock>::reset(p); | 87 std::unique_ptr<CacheRankingsBlock>::reset(p); |
| 88 } | 88 } |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 Rankings* rankings_; | 91 Rankings* rankings_; |
| 92 DISALLOW_COPY_AND_ASSIGN(ScopedRankingsBlock); | 92 DISALLOW_COPY_AND_ASSIGN(ScopedRankingsBlock); |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 // If we have multiple lists, we have to iterate through all at the same time. | 95 // If we have multiple lists, we have to iterate through all at the same time. |
| 96 // This structure keeps track of where we are on the iteration. | 96 // This structure keeps track of where we are on the iteration. |
| 97 struct Iterator { | 97 struct Iterator { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 BackendImpl* backend_; | 206 BackendImpl* backend_; |
| 207 LruData* control_data_; // Data related to the LRU lists. | 207 LruData* control_data_; // Data related to the LRU lists. |
| 208 IteratorList iterators_; | 208 IteratorList iterators_; |
| 209 | 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(Rankings); | 210 DISALLOW_COPY_AND_ASSIGN(Rankings); |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 } // namespace disk_cache | 213 } // namespace disk_cache |
| 214 | 214 |
| 215 #endif // NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ | 215 #endif // NET_DISK_CACHE_BLOCKFILE_RANKINGS_H_ |
| OLD | NEW |