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

Side by Side Diff: sync/internal_api/public/attachments/on_disk_attachment_store.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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 2014 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 SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/threading/non_thread_safe.h"
14 #include "sync/api/attachments/attachment.h"
15 #include "sync/api/attachments/attachment_id.h"
16 #include "sync/api/attachments/attachment_store.h"
17 #include "sync/api/attachments/attachment_store_backend.h"
18 #include "sync/base/sync_export.h"
19
20 namespace attachment_store_pb {
21 class RecordMetadata;
22 } // namespace attachment_store_pb
23
24 namespace base {
25 class SequencedTaskRunner;
26 } // namespace base
27
28 namespace leveldb {
29 class DB;
30 } // namespace leveldb
31
32 namespace syncer {
33
34 // On-disk implementation of AttachmentStore. Stores attachments in leveldb
35 // database in |path| directory.
36 class SYNC_EXPORT OnDiskAttachmentStore : public AttachmentStoreBackend,
37 public base::NonThreadSafe {
38 public:
39 // Constructs attachment store.
40 OnDiskAttachmentStore(
41 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner,
42 const base::FilePath& path);
43 ~OnDiskAttachmentStore() override;
44
45 // AttachmentStoreBackend implementation.
46 void Init(const AttachmentStore::InitCallback& callback) override;
47 void Read(AttachmentStore::Component component,
48 const AttachmentIdList& ids,
49 const AttachmentStore::ReadCallback& callback) override;
50 void Write(AttachmentStore::Component component,
51 const AttachmentList& attachments,
52 const AttachmentStore::WriteCallback& callback) override;
53 void SetReference(AttachmentStore::Component component,
54 const AttachmentIdList& ids) override;
55 void DropReference(AttachmentStore::Component component,
56 const AttachmentIdList& ids,
57 const AttachmentStore::DropCallback& callback) override;
58 void ReadMetadataById(
59 AttachmentStore::Component component,
60 const AttachmentIdList& ids,
61 const AttachmentStore::ReadMetadataCallback& callback) override;
62 void ReadMetadata(
63 AttachmentStore::Component component,
64 const AttachmentStore::ReadMetadataCallback& callback) override;
65
66 private:
67 friend class OnDiskAttachmentStoreSpecificTest;
68
69 // Opens leveldb database at |path|, creating it if needed. In the future
70 // upgrade code will be invoked from OpenOrCreate as well. If open fails
71 // result is UNSPECIFIED_ERROR.
72 AttachmentStore::Result OpenOrCreate(const base::FilePath& path);
73 // Reads single attachment from store. Returns nullptr in case of errors.
74 std::unique_ptr<Attachment> ReadSingleAttachment(
75 const AttachmentId& attachment_id,
76 AttachmentStore::Component component);
77 // Writes single attachment to store. Returns false in case of errors.
78 bool WriteSingleAttachment(const Attachment& attachment,
79 AttachmentStore::Component component);
80 // Reads single attachment_store_pb::RecordMetadata from levelDB into the
81 // provided buffer. Returns false in case of an error.
82 bool ReadSingleRecordMetadata(
83 const AttachmentId& attachment_id,
84 attachment_store_pb::RecordMetadata* record_metadata);
85 // Writes single attachment_store_pb::RecordMetadata to levelDB. Returns false
86 // in case of an error.
87 bool WriteSingleRecordMetadata(
88 const AttachmentId& attachment_id,
89 const attachment_store_pb::RecordMetadata& record_metadata);
90
91 static std::string MakeDataKeyFromAttachmentId(
92 const AttachmentId& attachment_id);
93 static std::string MakeMetadataKeyFromAttachmentId(
94 const AttachmentId& attachment_id);
95 static AttachmentMetadata MakeAttachmentMetadata(
96 const AttachmentId& attachment_id,
97 const attachment_store_pb::RecordMetadata& record_metadata);
98
99 const base::FilePath path_;
100 std::unique_ptr<leveldb::DB> db_;
101
102 DISALLOW_COPY_AND_ASSIGN(OnDiskAttachmentStore);
103 };
104
105 } // namespace syncer
106
107 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/attachments/in_memory_attachment_store.h ('k') | sync/internal_api/public/attachments/task_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698