Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(483)

Unified Diff: services/url_response_disk_cache/url_response_disk_cache_db.h

Issue 1276073004: Offline By Default (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Add missing explicits. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c8aee1b58012320e3d9841bc54c2b55a078846e2
--- /dev/null
+++ b/services/url_response_disk_cache/url_response_disk_cache_db.h
@@ -0,0 +1,78 @@
+// 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;
+class Iterator;
+};
+
+namespace mojo {
+
+// Specialized database for the cache content.
+class URLResponseDiskCacheDB
+ : public base::RefCountedThreadSafe<URLResponseDiskCacheDB> {
+ public:
+ class Iterator {
+ public:
+ explicit Iterator(linked_ptr<leveldb::DB> db);
+ ~Iterator();
+
+ bool HasNext();
+ void GetNext(CacheKeyPtr* key, CacheEntryPtr* entry);
+
+ private:
+ linked_ptr<leveldb::DB> db_;
+ scoped_ptr<leveldb::Iterator> it_;
+ };
+
+ // 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.
+ explicit URLResponseDiskCacheDB(const base::FilePath& db_path);
+
+ // 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 PutNew(const std::string& request_origin,
+ const std::string& url,
+ CacheEntryPtr entry);
+
+ // Returns the newest entry for the given |request_origin| and |url|, or null
+ // if none exist.
+ CacheEntryPtr GetNewest(const std::string& request_origin,
+ const std::string& url);
+
+ // Delete the entry for the given |key|.
+ void Delete(CacheKeyPtr key);
+
+ // 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.
+ // An iterator will not be invalidated nor any of its values will be modified
+ // by further changes to the database.
+ scoped_ptr<Iterator> GetIterator();
+
+ private:
+ friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>;
+ ~URLResponseDiskCacheDB();
+
+ scoped_ptr<leveldb::Comparator> comparator_;
+ linked_ptr<leveldb::DB> db_;
+};
+
+} // namespace
+
+#endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_

Powered by Google App Engine
This is Rietveld 408576698