Add test_runner support for new accessibility event
[chromium-blink-merge.git] / sync / internal_api / public / attachments / on_disk_attachment_store.h
blobbde55c878d4543fe92c78a5eb5fc7d1c70a78b7e
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.
5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/threading/non_thread_safe.h"
11 #include "sync/api/attachments/attachment.h"
12 #include "sync/api/attachments/attachment_id.h"
13 #include "sync/api/attachments/attachment_store.h"
14 #include "sync/api/attachments/attachment_store_backend.h"
15 #include "sync/base/sync_export.h"
17 namespace attachment_store_pb {
18 class RecordMetadata;
19 } // namespace attachment_store_pb
21 namespace base {
22 class SequencedTaskRunner;
23 } // namespace base
25 namespace leveldb {
26 class DB;
27 } // namespace leveldb
29 namespace syncer {
31 // On-disk implementation of AttachmentStore. Stores attachments in leveldb
32 // database in |path| directory.
33 class SYNC_EXPORT OnDiskAttachmentStore : public AttachmentStoreBackend,
34 public base::NonThreadSafe {
35 public:
36 // Constructs attachment store.
37 OnDiskAttachmentStore(
38 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner,
39 const base::FilePath& path);
40 ~OnDiskAttachmentStore() override;
42 // AttachmentStoreBackend implementation.
43 void Init(const AttachmentStore::InitCallback& callback) override;
44 void Read(const AttachmentIdList& ids,
45 const AttachmentStore::ReadCallback& callback) override;
46 void Write(AttachmentStore::Component component,
47 const AttachmentList& attachments,
48 const AttachmentStore::WriteCallback& callback) override;
49 void SetReference(AttachmentStore::Component component,
50 const AttachmentIdList& ids) override;
51 void DropReference(AttachmentStore::Component component,
52 const AttachmentIdList& ids,
53 const AttachmentStore::DropCallback& callback) override;
54 void ReadMetadata(
55 const AttachmentIdList& ids,
56 const AttachmentStore::ReadMetadataCallback& callback) override;
57 void ReadAllMetadata(
58 AttachmentStore::Component component,
59 const AttachmentStore::ReadMetadataCallback& callback) override;
61 private:
62 friend class OnDiskAttachmentStoreSpecificTest;
64 // Opens leveldb database at |path|, creating it if needed. In the future
65 // upgrade code will be invoked from OpenOrCreate as well. If open fails
66 // result is UNSPECIFIED_ERROR.
67 AttachmentStore::Result OpenOrCreate(const base::FilePath& path);
68 // Reads single attachment from store. Returns nullptr in case of errors.
69 scoped_ptr<Attachment> ReadSingleAttachment(
70 const AttachmentId& attachment_id);
71 // Writes single attachment to store. Returns false in case of errors.
72 bool WriteSingleAttachment(const Attachment& attachment);
73 // Reads single store_pb::RecordMetadata from levelDB into the provided
74 // buffer. Returns false in case of an error.
75 bool ReadSingleRecordMetadata(
76 const AttachmentId& attachment_id,
77 attachment_store_pb::RecordMetadata* record_metadata);
79 static std::string MakeDataKeyFromAttachmentId(
80 const AttachmentId& attachment_id);
81 static std::string MakeMetadataKeyFromAttachmentId(
82 const AttachmentId& attachment_id);
83 static AttachmentMetadata MakeAttachmentMetadata(
84 const AttachmentId& attachment_id,
85 const attachment_store_pb::RecordMetadata& record_metadata);
87 const base::FilePath path_;
88 scoped_ptr<leveldb::DB> db_;
90 DISALLOW_COPY_AND_ASSIGN(OnDiskAttachmentStore);
93 } // namespace syncer
95 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_