OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
| 6 #define SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
| 7 |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/memory/linked_ptr.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "services/url_response_disk_cache/url_response_disk_cache_entry.mojom.h
" |
| 13 |
| 14 namespace leveldb { |
| 15 class Comparator; |
| 16 class DB; |
| 17 class Iterator; |
| 18 }; |
| 19 |
| 20 namespace mojo { |
| 21 |
| 22 // Specialized database for the cache content. |
| 23 class URLResponseDiskCacheDB |
| 24 : public base::RefCountedThreadSafe<URLResponseDiskCacheDB> { |
| 25 public: |
| 26 class Iterator { |
| 27 public: |
| 28 explicit Iterator(linked_ptr<leveldb::DB> db); |
| 29 ~Iterator(); |
| 30 |
| 31 bool HasNext(); |
| 32 void GetNext(CacheKeyPtr* key, CacheEntryPtr* entry); |
| 33 |
| 34 private: |
| 35 linked_ptr<leveldb::DB> db_; |
| 36 scoped_ptr<leveldb::Iterator> it_; |
| 37 }; |
| 38 |
| 39 // Constructs the database. |db_path| is the path to the leveldb database. If |
| 40 // the path exists, the database will be opened, otherwise it will be created. |
| 41 explicit URLResponseDiskCacheDB(const base::FilePath& db_path); |
| 42 |
| 43 // Set and get the version of the database. |
| 44 uint64_t GetVersion(); |
| 45 void SetVersion(uint64_t version); |
| 46 |
| 47 // Put an entry for the given |request_origin| and |url|. Older entry for the |
| 48 // same |request_origin| and |url| will not be removed, but will be shadowed |
| 49 // by the new one. |
| 50 void PutNew(const std::string& request_origin, |
| 51 const std::string& url, |
| 52 CacheEntryPtr entry); |
| 53 |
| 54 // Returns the newest entry for the given |request_origin| and |url|, or null |
| 55 // if none exist. |
| 56 CacheEntryPtr GetNewest(const std::string& request_origin, |
| 57 const std::string& url); |
| 58 |
| 59 // Delete the entry for the given |key|. |
| 60 void Delete(CacheKeyPtr key); |
| 61 |
| 62 // Returns an iterator over all the entries in the database. For a given |
| 63 // |request_origin| and |url|, entries will be sorted from newest to oldest. |
| 64 // An iterator will not be invalidated nor any of its values will be modified |
| 65 // by further changes to the database. |
| 66 scoped_ptr<Iterator> GetIterator(); |
| 67 |
| 68 private: |
| 69 friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>; |
| 70 ~URLResponseDiskCacheDB(); |
| 71 |
| 72 scoped_ptr<leveldb::Comparator> comparator_; |
| 73 linked_ptr<leveldb::DB> db_; |
| 74 }; |
| 75 |
| 76 } // namespace |
| 77 |
| 78 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
OLD | NEW |