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

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: Rename MoveIntoDir 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 };
18
19 namespace mojo {
20
21 // Interface describing the read operation on the database.
22 class DBReader {
23 public:
24 class Iterator {
25 public:
26 virtual ~Iterator() {}
27
28 virtual bool HasNext() = 0;
29 virtual void GetNext(InternalEntryKeyPtr* key, CacheEntryPtr* entry) = 0;
30 };
31
32 DBReader() {}
33 virtual ~DBReader() {}
34
35 // Returns an iterator over all the entries in the database. For a given
36 // |request_origin| and |url|, entries will be sorted from newest to oldest.
37 virtual scoped_ptr<Iterator> Iterate() = 0;
38 // Returns the newest entry for the given |request_origin| and |url|, or null
39 // if none exist.
40 virtual CacheEntryPtr Get(const std::string& request_origin,
41 const std::string& url) = 0;
42 };
43
44 // Specialized database for the cache content.
45 class URLResponseDiskCacheDB
46 : public DBReader,
47 public base::RefCountedThreadSafe<URLResponseDiskCacheDB> {
48 public:
49 // Constructs the database. |db_path| is the path to the leveldb database. If
50 // the path exists, the database will be opened, otherwise it will be created.
51 URLResponseDiskCacheDB(const base::FilePath& db_path);
52
53 // Implementation of DBReader:
54 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.
55 CacheEntryPtr Get(const std::string& request_origin,
56 const std::string& url) override;
57
58 // Set and get the version of the database.
59 uint64_t GetVersion();
60 void SetVersion(uint64_t version);
61
62 // Put an entry for the given |request_origin| and |url|. Older entry for the
63 // same |request_origin| and |url| will not be removed, but will be shadowed
64 // by the new one.
65 void Put(const std::string& request_origin,
66 const std::string& url,
67 CacheEntryPtr entry);
68 // Delete the entry for the given |key|.
69 void Delete(InternalEntryKeyPtr key);
70
71 // Returns a snapshot of the database in its current state.
72 scoped_ptr<DBReader> GetSnapshot();
73
74 private:
75 friend class base::RefCountedThreadSafe<URLResponseDiskCacheDB>;
76 ~URLResponseDiskCacheDB() override;
77
78 scoped_ptr<leveldb::Comparator> comparator_;
79 linked_ptr<leveldb::DB> db_;
80 scoped_ptr<DBReader> db_reader_;
81 };
82
83 } // namespace
84
85 #endif // SERVICES_URL_RESPONSE_DISK_CACHE_URL_RESPONSE_DISK_CACHE_DB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698