Chromium Code Reviews| Index: content/browser/cache_storage/cache_storage_index.h |
| diff --git a/content/browser/cache_storage/cache_storage_index.h b/content/browser/cache_storage/cache_storage_index.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..93b3d6c57d6bc5428def78bacfb27471475b9f99 |
| --- /dev/null |
| +++ b/content/browser/cache_storage/cache_storage_index.h |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ |
| +#define CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ |
| + |
| +#include <list> |
| +#include <string> |
| +#include <unordered_map> |
| +#include "content/browser/cache_storage/cache_storage.h" |
| + |
| +namespace content { |
| + |
| +class CacheMetadata; |
| + |
|
jkarlin
2016/11/23 16:02:18
Class needs a comment.
cmumford
2016/11/29 18:10:21
Done. I also added some documentation to README.md
|
| +class CONTENT_EXPORT CacheStorageIndex { |
| + public: |
| + struct CacheMetadata { |
| + CacheMetadata(const std::string& name, int64_t size) |
| + : name(name), size(size) {} |
| + std::string name; |
| + // The size (in bytes) of the cache. Set to CacheStorage::kSizeUnknown if |
| + // size not known. |
| + int64_t size; |
| + }; |
| + |
| + CacheStorageIndex(const CacheStorageIndex& other); |
| + CacheStorageIndex(); |
| + ~CacheStorageIndex(); |
| + |
| + CacheStorageIndex& operator=(CacheStorageIndex&& rhs); |
| + CacheStorageIndex& operator=(const CacheStorageIndex& rhs); |
| + |
| + void Insert(const CacheMetadata& cache_metadata); |
| + void Delete(const std::string& cache_name); |
| + |
| + // Sets the cache size. Returns true if the new size is different than the |
| + // current size else false. |
| + bool SetCacheSize(const std::string& cache_name, int64_t size); |
| + |
| + // The cache was modified, increasing/decreasing cache size by |size_delta|. |
| + void SetCacheSizeModified(const std::string& cache_name, int64_t size_delta); |
| + |
| + int64_t GetCacheSize(const std::string& cache_name) const; |
| + |
| + const std::list<CacheMetadata>& ordered_cache_metadata() const { |
| + return ordered_cache_metadata_; |
| + } |
| + |
| + size_t num_entries() const { return ordered_cache_metadata_.size(); } |
| + |
| + int64_t GetStorageSize(); |
| + |
| + private: |
| + void UpdateStorageSize(); |
| + |
| + // Use a list to keep saved iterators valid during insert/erase. |
| + // Note: ordered by cache creation. |
| + std::list<CacheMetadata> ordered_cache_metadata_; |
| + std::unordered_map<std::string, std::list<CacheMetadata>::iterator> |
| + cache_metadata_map_; |
| + |
| + // The total size of all caches in this store. |
| + int64_t storage_size_ = CacheStorage::kSizeUnknown; |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_CACHE_STORAGE_CACHE_STORAGE_INDEX_H_ |