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

Side by Side 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: Follow review 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 unified diff | Download patch
OLDNEW
(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 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 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 PutNewest(const std::string& request_origin, const std::string& url,
ppi 2015/09/15 15:21:22 nit: I'd name these methods: - PutNew - GetNewe
qsr 2015/09/16 11:46:38 Done.
51 CacheEntryPtr entry);
52
53 // Returns the newest entry for the given |request_origin| and |url|, or null
54 // if none exist.
55 CacheEntryPtr GetNewest(const std::string& request_origin,
56 const std::string& url);
57
58 // Delete the entry for the given |key|.
59 void Delete(CacheKeyPtr key);
60
61 // Returns an iterator over all the entries in the database. For a given
62 // |request_origin| and |url|, entries will be sorted from newest to oldest.
63 // An iterator will not be invalidated nor any of its values will be modified
64 // by further changes to the database.
65 scoped_ptr<Iterator> Iterate();
ppi 2015/09/15 15:21:22 nit: maybe call this conservatively GetIterator()?
qsr 2015/09/16 11:46:38 Done.
66
67 private:
68 friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>;
69 ~URLResponseDiskCacheDB();
70
71 scoped_ptr<leveldb::Comparator> comparator_;
72 linked_ptr<leveldb::DB> db_;
73 };
74
75 } // namespace
76
77 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698