Adding Test Fixture for initial test cases for the App Remoting Test Driver. Also...
[chromium-blink-merge.git] / sync / internal_api / public / attachments / on_disk_attachment_store.h
blob62cec5bc935e28cd3bd9802fcbf7e3af13ba6311
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::AttachmentReferrer referrer,
47 const AttachmentList& attachments,
48 const AttachmentStore::WriteCallback& callback) override;
49 void Drop(AttachmentStore::AttachmentReferrer referrer,
50 const AttachmentIdList& ids,
51 const AttachmentStore::DropCallback& callback) override;
52 void ReadMetadata(
53 const AttachmentIdList& ids,
54 const AttachmentStore::ReadMetadataCallback& callback) override;
55 void ReadAllMetadata(
56 AttachmentStore::AttachmentReferrer referrer,
57 const AttachmentStore::ReadMetadataCallback& callback) override;
59 private:
60 friend class OnDiskAttachmentStoreSpecificTest;
62 // Opens leveldb database at |path|, creating it if needed. In the future
63 // upgrade code will be invoked from OpenOrCreate as well. If open fails
64 // result is UNSPECIFIED_ERROR.
65 AttachmentStore::Result OpenOrCreate(const base::FilePath& path);
66 // Reads single attachment from store. Returns nullptr in case of errors.
67 scoped_ptr<Attachment> ReadSingleAttachment(
68 const AttachmentId& attachment_id);
69 // Writes single attachment to store. Returns false in case of errors.
70 bool WriteSingleAttachment(const Attachment& attachment);
71 // Reads single store_pb::RecordMetadata from levelDB into the provided
72 // buffer. Returns false in case of an error.
73 bool ReadSingleRecordMetadata(
74 const AttachmentId& attachment_id,
75 attachment_store_pb::RecordMetadata* record_metadata);
77 static std::string MakeDataKeyFromAttachmentId(
78 const AttachmentId& attachment_id);
79 static std::string MakeMetadataKeyFromAttachmentId(
80 const AttachmentId& attachment_id);
81 static AttachmentMetadata MakeAttachmentMetadata(
82 const AttachmentId& attachment_id,
83 const attachment_store_pb::RecordMetadata& record_metadata);
85 const base::FilePath path_;
86 scoped_ptr<leveldb::DB> db_;
88 DISALLOW_COPY_AND_ASSIGN(OnDiskAttachmentStore);
91 } // namespace syncer
93 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_