| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_ |
| 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_ |
| 7 | 7 |
| 8 #include "base/files/file_path.h" |
| 8 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "base/threading/non_thread_safe.h" | 10 #include "base/threading/non_thread_safe.h" |
| 11 #include "sync/api/attachments/attachment.h" | 11 #include "sync/api/attachments/attachment.h" |
| 12 #include "sync/api/attachments/attachment_id.h" | 12 #include "sync/api/attachments/attachment_id.h" |
| 13 #include "sync/api/attachments/attachment_store.h" | 13 #include "sync/api/attachments/attachment_store.h" |
| 14 #include "sync/base/sync_export.h" | 14 #include "sync/base/sync_export.h" |
| 15 | 15 |
| 16 namespace base { |
| 17 class SequencedTaskRunner; |
| 18 } // namespace base |
| 19 |
| 20 namespace leveldb { |
| 21 class DB; |
| 22 } // namespace leveldb |
| 23 |
| 16 namespace syncer { | 24 namespace syncer { |
| 17 | 25 |
| 18 // An in-memory implementation of AttachmentStore used for testing. | 26 // On-disk implementation of AttachmentStore. Stores attachments in leveldb |
| 19 // InMemoryAttachmentStore is not threadsafe, it lives on backend thread and | 27 // database in |path| directory. |
| 20 // posts callbacks with results on |callback_task_runner|. | 28 class SYNC_EXPORT OnDiskAttachmentStore : public AttachmentStoreBase, |
| 21 class SYNC_EXPORT InMemoryAttachmentStore : public AttachmentStoreBase, | 29 public base::NonThreadSafe { |
| 22 public base::NonThreadSafe { | |
| 23 public: | 30 public: |
| 24 InMemoryAttachmentStore( | 31 // Constructs attachment store. |
| 25 const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner); | 32 OnDiskAttachmentStore( |
| 26 virtual ~InMemoryAttachmentStore(); | 33 const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner); |
| 34 virtual ~OnDiskAttachmentStore(); |
| 27 | 35 |
| 28 // AttachmentStoreBase implementation. | 36 // AttachmentStoreBase implementation. |
| 37 // Load opens database, creating it if needed. In the future upgrade code will |
| 38 // be invoked from Load as well. If loading fails it posts |callback| with |
| 39 // UNSPECIFIED_ERROR. |
| 29 virtual void Read(const AttachmentIdList& ids, | 40 virtual void Read(const AttachmentIdList& ids, |
| 30 const ReadCallback& callback) override; | 41 const ReadCallback& callback) override; |
| 31 virtual void Write(const AttachmentList& attachments, | 42 virtual void Write(const AttachmentList& attachments, |
| 32 const WriteCallback& callback) override; | 43 const WriteCallback& callback) override; |
| 33 virtual void Drop(const AttachmentIdList& ids, | 44 virtual void Drop(const AttachmentIdList& ids, |
| 34 const DropCallback& callback) override; | 45 const DropCallback& callback) override; |
| 35 | 46 |
| 47 // Opens leveldb database at |path|. It will create directory and database if |
| 48 // it doesn't exist. |
| 49 Result OpenOrCreate(const base::FilePath& path); |
| 50 |
| 36 private: | 51 private: |
| 37 scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_; | 52 std::string CreateDataKeyFromAttachmentId(const AttachmentId& attachment_id); |
| 38 AttachmentMap attachments_; | 53 |
| 54 scoped_refptr<base::SequencedTaskRunner> callback_task_runner_; |
| 55 scoped_ptr<leveldb::DB> db_; |
| 39 }; | 56 }; |
| 40 | 57 |
| 41 } // namespace syncer | 58 } // namespace syncer |
| 42 | 59 |
| 43 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_ | 60 #endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_ |
| OLD | NEW |