Index: services/url_response_disk_cache/url_response_disk_cache_db.h |
diff --git a/services/url_response_disk_cache/url_response_disk_cache_db.h b/services/url_response_disk_cache/url_response_disk_cache_db.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..cbbc11e6843059b32628e33002193eb021529a5d |
--- /dev/null |
+++ b/services/url_response_disk_cache/url_response_disk_cache_db.h |
@@ -0,0 +1,85 @@ |
+// Copyright 2015 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 SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
+#define SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |
+ |
+#include "base/files/file_path.h" |
+#include "base/memory/linked_ptr.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "services/url_response_disk_cache/url_response_disk_cache_entry.mojom.h" |
+ |
+namespace leveldb { |
+class Comparator; |
+class DB; |
+}; |
+ |
+namespace mojo { |
+ |
+// Interface describing the read operation on the database. |
+class DBReader { |
+ public: |
+ class Iterator { |
+ public: |
+ virtual ~Iterator() {} |
+ |
+ virtual bool HasNext() = 0; |
+ virtual void GetNext(InternalEntryKeyPtr* key, CacheEntryPtr* entry) = 0; |
+ }; |
+ |
+ DBReader() {} |
+ virtual ~DBReader() {} |
+ |
+ // Returns an iterator over all the entries in the database. For a given |
+ // |request_origin| and |url|, entries will be sorted from newest to oldest. |
+ virtual scoped_ptr<Iterator> Iterate() = 0; |
+ // Returns the newest entry for the given |request_origin| and |url|, or null |
+ // if none exist. |
+ virtual CacheEntryPtr Get(const std::string& request_origin, |
+ const std::string& url) = 0; |
+}; |
+ |
+// Specialized database for the cache content. |
+class URLResponseDiskCacheDB |
+ : public DBReader, |
+ public base::RefCountedThreadSafe<URLResponseDiskCacheDB> { |
+ public: |
+ // Constructs the database. |db_path| is the path to the leveldb database. If |
+ // the path exists, the database will be opened, otherwise it will be created. |
+ URLResponseDiskCacheDB(const base::FilePath& db_path); |
+ |
+ // Implementation of DBReader: |
+ scoped_ptr<Iterator> Iterate() override; |
ppi
2015/09/08 15:46:26
This, as opposed to Iterate() on a snapshot, retur
qsr
2015/09/11 15:47:57
Done.
|
+ CacheEntryPtr Get(const std::string& request_origin, |
+ const std::string& url) override; |
+ |
+ // Set and get the version of the database. |
+ uint64_t GetVersion(); |
+ void SetVersion(uint64_t version); |
+ |
+ // Put an entry for the given |request_origin| and |url|. Older entry for the |
+ // same |request_origin| and |url| will not be removed, but will be shadowed |
+ // by the new one. |
+ void Put(const std::string& request_origin, |
+ const std::string& url, |
+ CacheEntryPtr entry); |
+ // Delete the entry for the given |key|. |
+ void Delete(InternalEntryKeyPtr key); |
+ |
+ // Returns a snapshot of the database in its current state. |
+ scoped_ptr<DBReader> GetSnapshot(); |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>; |
+ ~URLResponseDiskCacheDB() override; |
+ |
+ scoped_ptr<leveldb::Comparator> comparator_; |
+ linked_ptr<leveldb::DB> db_; |
+ scoped_ptr<DBReader> db_reader_; |
+}; |
+ |
+} // namespace |
+ |
+#endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_ |