OLD | NEW |
| (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 CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_ | |
6 #define CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/memory/ref_counted.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "components/leveldb_proto/proto_database.h" | |
13 #include "components/offline_pages/offline_page_metadata_store.h" | |
14 | |
15 namespace base { | |
16 class FilePath; | |
17 } | |
18 | |
19 namespace offline_pages { | |
20 | |
21 class OfflinePageEntry; | |
22 | |
23 // Implements OfflinePageMetadataStore using leveldb_proto::ProtoDatabase | |
24 // component. Stores metadata of offline pages as serialized protobufs in a | |
25 // LevelDB key/value pairs. | |
26 // Underlying implementation guarantees that all of the method calls will be | |
27 // executed sequentially, and started operations will finish even after the | |
28 // store is already destroyed (callbacks will be called). | |
29 class OfflinePageMetadataStoreImpl : public OfflinePageMetadataStore { | |
30 public: | |
31 OfflinePageMetadataStoreImpl( | |
32 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>> database, | |
33 const base::FilePath& database_dir); | |
34 ~OfflinePageMetadataStoreImpl() override; | |
35 | |
36 // OfflinePageMetadataStore implementation: | |
37 void Load(const LoadCallback& callback) override; | |
38 void AddOfflinePage(const OfflinePageItem& offline_page_record, | |
39 const UpdateCallback& callback) override; | |
40 void RemoveOfflinePage(const GURL& page_url, | |
41 const UpdateCallback& callback) override; | |
42 | |
43 private: | |
44 // Callback for when initialization of the |database_| is done. | |
45 void OnInitDone(bool success); | |
46 | |
47 // Implements the update. | |
48 void UpdateEntries( | |
49 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | |
50 entries_to_save, | |
51 scoped_ptr<std::vector<std::string>> keys_to_remove, | |
52 const UpdateCallback& callback); | |
53 | |
54 // Resets the database. This is to be used when one of the operations fails | |
55 // with no good explanation. | |
56 void ResetDB(); | |
57 | |
58 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>> database_; | |
59 | |
60 base::WeakPtrFactory<OfflinePageMetadataStoreImpl> weak_ptr_factory_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreImpl); | |
63 }; | |
64 | |
65 } // namespace offline_pages | |
66 | |
67 #endif // CHROME_BROWSER_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_ | |
OLD | NEW |