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.
5 #ifndef COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_
6 #define COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_
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"
19 namespace offline_pages
{
21 class OfflinePageEntry
;
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
{
31 OfflinePageMetadataStoreImpl(
32 scoped_ptr
<leveldb_proto::ProtoDatabase
<OfflinePageEntry
>> database
,
33 const base::FilePath
& database_dir
);
34 ~OfflinePageMetadataStoreImpl() override
;
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 RemoveOfflinePages(const std::vector
<int64
>& bookmark_ids
,
41 const UpdateCallback
& callback
) override
;
44 // Callback for when initialization of the |database_| is done.
45 void OnInitDone(bool success
);
47 // Implements the update.
49 scoped_ptr
<leveldb_proto::ProtoDatabase
<OfflinePageEntry
>::KeyEntryVector
>
51 scoped_ptr
<std::vector
<std::string
>> keys_to_remove
,
52 const UpdateCallback
& callback
);
54 // Resets the database. This is to be used when one of the operations fails
55 // with no good explanation.
58 scoped_ptr
<leveldb_proto::ProtoDatabase
<OfflinePageEntry
>> database_
;
60 base::WeakPtrFactory
<OfflinePageMetadataStoreImpl
> weak_ptr_factory_
;
62 DISALLOW_COPY_AND_ASSIGN(OfflinePageMetadataStoreImpl
);
65 } // namespace offline_pages
67 #endif // COMPONENTS_OFFLINE_PAGES_OFFLINE_PAGE_METADATA_STORE_IMPL_H_