OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ | 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_ | 6 #define SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 }; | 37 }; |
38 | 38 |
39 // Constructs the database. |db_path| is the path to the leveldb database. If | 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. | 40 // the path exists, the database will be opened, otherwise it will be created. |
41 explicit URLResponseDiskCacheDB(const base::FilePath& db_path); | 41 explicit URLResponseDiskCacheDB(const base::FilePath& db_path); |
42 | 42 |
43 // Set and get the version of the database. | 43 // Set and get the version of the database. |
44 uint64_t GetVersion(); | 44 uint64_t GetVersion(); |
45 void SetVersion(uint64_t version); | 45 void SetVersion(uint64_t version); |
46 | 46 |
| 47 // Set and get an entry for a given key. |
| 48 void Put(CacheKeyPtr key, CacheEntryPtr entry); |
| 49 CacheEntryPtr Get(CacheKeyPtr key); |
| 50 |
47 // Put an entry for the given |request_origin| and |url|. Older entry for the | 51 // 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 | 52 // same |request_origin| and |url| will not be removed, but will be shadowed |
49 // by the new one. | 53 // by the new one. |
50 void PutNew(const std::string& request_origin, | 54 void PutNew(const std::string& request_origin, |
51 const std::string& url, | 55 const std::string& url, |
52 CacheEntryPtr entry); | 56 CacheEntryPtr entry); |
53 | 57 |
54 // Returns the newest entry for the given |request_origin| and |url|, or null | 58 // Returns the newest entry for the given |request_origin| and |url|, or null |
55 // if none exist. | 59 // if none exist. If |key| is not null and GetNewest returns an entry, |*key| |
| 60 // will contain the actual key of the entry. |
56 CacheEntryPtr GetNewest(const std::string& request_origin, | 61 CacheEntryPtr GetNewest(const std::string& request_origin, |
57 const std::string& url); | 62 const std::string& url, |
| 63 CacheKeyPtr* key); |
58 | 64 |
59 // Delete the entry for the given |key|. | 65 // Delete the entry for the given |key|. |
60 void Delete(CacheKeyPtr key); | 66 void Delete(CacheKeyPtr key); |
61 | 67 |
62 // Returns an iterator over all the entries in the database. For a given | 68 // 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. | 69 // |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 | 70 // An iterator will not be invalidated nor any of its values will be modified |
65 // by further changes to the database. | 71 // by further changes to the database. |
66 scoped_ptr<Iterator> GetIterator(); | 72 scoped_ptr<Iterator> GetIterator(); |
67 | 73 |
68 private: | 74 private: |
69 friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>; | 75 friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>; |
70 ~URLResponseDiskCacheDB(); | 76 ~URLResponseDiskCacheDB(); |
71 | 77 |
72 scoped_ptr<leveldb::Comparator> comparator_; | 78 scoped_ptr<leveldb::Comparator> comparator_; |
73 linked_ptr<leveldb::DB> db_; | 79 linked_ptr<leveldb::DB> db_; |
74 }; | 80 }; |
75 | 81 |
76 } // namespace | 82 } // namespace |
77 | 83 |
78 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ | 84 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
OLD | NEW |