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

Unified Diff: sync/internal_api/public/attachments/on_disk_attachment_store.h

Issue 652723003: Implementation of OnDiskAttachmentStore. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More updates Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sync/internal_api/attachments/on_disk_attachment_store_unittest.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/internal_api/public/attachments/on_disk_attachment_store.h
diff --git a/sync/internal_api/public/attachments/in_memory_attachment_store.h b/sync/internal_api/public/attachments/on_disk_attachment_store.h
similarity index 39%
copy from sync/internal_api/public/attachments/in_memory_attachment_store.h
copy to sync/internal_api/public/attachments/on_disk_attachment_store.h
index adf4035a9173b7c0d9fcd8dc2509d4d8b367e351..d74b60bf60895fe66b56a1d1df9052fc83c685db 100644
--- a/sync/internal_api/public/attachments/in_memory_attachment_store.h
+++ b/sync/internal_api/public/attachments/on_disk_attachment_store.h
@@ -2,30 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_
-#define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_
+#ifndef SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
+#define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
+#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
-#include "base/single_thread_task_runner.h"
#include "base/threading/non_thread_safe.h"
#include "sync/api/attachments/attachment.h"
#include "sync/api/attachments/attachment_id.h"
#include "sync/api/attachments/attachment_store.h"
#include "sync/base/sync_export.h"
+namespace base {
+class SequencedTaskRunner;
+} // namespace base
+
+namespace leveldb {
+class DB;
+} // namespace leveldb
+
namespace syncer {
-// An in-memory implementation of AttachmentStore used for testing.
-// InMemoryAttachmentStore is not threadsafe, it lives on backend thread and
-// posts callbacks with results on |callback_task_runner|.
-class SYNC_EXPORT InMemoryAttachmentStore : public AttachmentStoreBase,
- public base::NonThreadSafe {
+// On-disk implementation of AttachmentStore. Stores attachments in leveldb
+// database in |path| directory.
+class SYNC_EXPORT OnDiskAttachmentStore : public AttachmentStoreBase,
+ public base::NonThreadSafe {
public:
- InMemoryAttachmentStore(
- const scoped_refptr<base::SingleThreadTaskRunner>& callback_task_runner);
- virtual ~InMemoryAttachmentStore();
+ // Constructs attachment store.
+ OnDiskAttachmentStore(
+ const scoped_refptr<base::SequencedTaskRunner>& callback_task_runner);
+ virtual ~OnDiskAttachmentStore();
// AttachmentStoreBase implementation.
+ // Load opens database, creating it if needed. In the future upgrade code will
+ // be invoked from Load as well. If loading fails it posts |callback| with
+ // UNSPECIFIED_ERROR.
virtual void Read(const AttachmentIdList& ids,
const ReadCallback& callback) override;
virtual void Write(const AttachmentList& attachments,
@@ -33,11 +44,17 @@ class SYNC_EXPORT InMemoryAttachmentStore : public AttachmentStoreBase,
virtual void Drop(const AttachmentIdList& ids,
const DropCallback& callback) override;
+ // Opens leveldb database at |path|. It will create directory and database if
+ // it doesn't exist.
+ Result OpenOrCreate(const base::FilePath& path);
+
private:
- scoped_refptr<base::SingleThreadTaskRunner> callback_task_runner_;
- AttachmentMap attachments_;
+ std::string CreateDataKeyFromAttachmentId(const AttachmentId& attachment_id);
+
+ scoped_refptr<base::SequencedTaskRunner> callback_task_runner_;
+ scoped_ptr<leveldb::DB> db_;
};
} // namespace syncer
-#endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_IN_MEMORY_ATTACHMENT_STORE_H_
+#endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ON_DISK_ATTACHMENT_STORE_H_
« no previous file with comments | « sync/internal_api/attachments/on_disk_attachment_store_unittest.cc ('k') | sync/sync.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698