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

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

Issue 601553004: Refactor FakeAttachmentStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
Index: sync/internal_api/public/attachments/attachment_store_proxy.h
diff --git a/sync/internal_api/public/attachments/attachment_store_proxy.h b/sync/internal_api/public/attachments/attachment_store_proxy.h
new file mode 100644
index 0000000000000000000000000000000000000000..801e8bd0922e2c4a864d92e801ec49ac3d4ff890
--- /dev/null
+++ b/sync/internal_api/public/attachments/attachment_store_proxy.h
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// 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_ATTACHMENT_STORE_PROXY_H_
+#define SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_PROXY_H_
+
+#include <map>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/stl_util.h"
+#include "base/threading/non_thread_safe.h"
+#include "sync/api/attachments/attachment_store.h"
+#include "sync/base/sync_export.h"
+
+namespace base {
+class SequencedTaskRunner;
+} // namespace base
+
+namespace sync_pb {
+class AttachmentId;
+} // namespace sync_pb
+
+namespace syncer {
+
+class Attachment;
+
+// AttachmentStoreproxy is helper to post AttachmentStore calls to backend on
maniscalco 2014/09/29 20:57:52 s/Storeproxy/StoreProxy/
pavely 2014/09/29 23:27:08 Done.
+// different thread. Backend is expected to know on which thread to post
+// callbacks with results.
+// AttachmentStoreProxy takes ownership of backend. Backend is deleted by
maniscalco 2014/09/29 20:57:52 I'd remove the mention of using DeleteSoon as it's
pavely 2014/09/29 23:27:08 Done.
+// posting DeleteSoon on backend thread.
+class SYNC_EXPORT AttachmentStoreProxy : public AttachmentStore,
maniscalco 2014/09/29 20:57:52 Consider adding a unit test for this class. Sure,
pavely 2014/09/29 23:27:08 Done.
+ public base::NonThreadSafe {
+ public:
+ AttachmentStoreProxy(
maniscalco 2014/09/29 20:57:52 As we discussed, AttachmentStoreProxy is similar t
maniscalco 2014/09/29 20:57:52 It's worth documenting that this class promises to
maniscalco 2014/09/29 20:57:52 nit: I think the style guide would have us pass ba
pavely 2014/09/29 23:27:08 Done.
pavely 2014/09/29 23:27:08 No, it is not that strict. http://google-styleguid
pavely 2014/09/29 23:27:08 Done.
+ scoped_ptr<AttachmentStoreBase> backend,
+ const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner);
+
+ // AttachmentStore implementation.
+ virtual void Read(const AttachmentIdList& id,
+ const ReadCallback& callback) OVERRIDE;
+ virtual void Write(const AttachmentList& attachments,
+ const WriteCallback& callback) OVERRIDE;
+ virtual void Drop(const AttachmentIdList& id,
+ const DropCallback& callback) OVERRIDE;
+
+ private:
+ virtual ~AttachmentStoreProxy();
+
+ // AttachmentStoreProxy controls backend's lifetime. It is safe for
+ // AttachmentStoreProxy to bind backend through base::Unretained for posts.
+ // Backend is deleted by posting DeleteSoon on backend_task_runner, after this
+ // backend_ pointer is invalid.
+ scoped_ptr<AttachmentStoreBase> backend_;
+ scoped_refptr<base::SequencedTaskRunner> backend_task_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(AttachmentStoreProxy);
+};
+
+} // namespace syncer
+
+#endif // SYNC_INTERNAL_API_PUBLIC_ATTACHMENTS_ATTACHMENT_STORE_PROXY_H_

Powered by Google App Engine
This is Rietveld 408576698