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

Side by Side Diff: components/sync/api/attachments/attachment_store.cc

Issue 2401223002: [Sync] Renaming sync/api* to sync/model*. (Closed)
Patch Set: Missed a comment in a DEPS file, and rebasing. Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "components/sync/api/attachments/attachment_store.h"
6
7 #include <utility>
8
9 #include "base/bind.h"
10 #include "base/location.h"
11 #include "base/message_loop/message_loop.h"
12 #include "base/sequenced_task_runner.h"
13 #include "base/threading/thread_task_runner_handle.h"
14 #include "components/sync/engine/attachments/attachment_store_frontend.h"
15 #include "components/sync/engine/attachments/in_memory_attachment_store.h"
16 #include "components/sync/engine/attachments/on_disk_attachment_store.h"
17
18 namespace syncer {
19
20 namespace {
21
22 void NoOpDropCallback(const AttachmentStore::Result& result) {}
23 }
24
25 AttachmentStore::AttachmentStore(
26 const scoped_refptr<AttachmentStoreFrontend>& frontend,
27 Component component)
28 : frontend_(frontend), component_(component) {}
29
30 AttachmentStore::~AttachmentStore() {}
31
32 void AttachmentStore::Read(const AttachmentIdList& ids,
33 const ReadCallback& callback) {
34 frontend_->Read(component_, ids, callback);
35 }
36
37 void AttachmentStore::Write(const AttachmentList& attachments,
38 const WriteCallback& callback) {
39 frontend_->Write(component_, attachments, callback);
40 }
41
42 void AttachmentStore::Drop(const AttachmentIdList& ids,
43 const DropCallback& callback) {
44 frontend_->DropReference(component_, ids, callback);
45 }
46
47 void AttachmentStore::ReadMetadataById(const AttachmentIdList& ids,
48 const ReadMetadataCallback& callback) {
49 frontend_->ReadMetadataById(component_, ids, callback);
50 }
51
52 void AttachmentStore::ReadMetadata(const ReadMetadataCallback& callback) {
53 frontend_->ReadMetadata(component_, callback);
54 }
55
56 std::unique_ptr<AttachmentStoreForSync>
57 AttachmentStore::CreateAttachmentStoreForSync() const {
58 std::unique_ptr<AttachmentStoreForSync> attachment_store_for_sync(
59 new AttachmentStoreForSync(frontend_, component_, SYNC));
60 return attachment_store_for_sync;
61 }
62
63 std::unique_ptr<AttachmentStore> AttachmentStore::CreateInMemoryStore() {
64 // Both frontend and backend of attachment store will live on current thread.
65 scoped_refptr<base::SingleThreadTaskRunner> runner;
66 if (base::ThreadTaskRunnerHandle::IsSet()) {
67 runner = base::ThreadTaskRunnerHandle::Get();
68 } else {
69 // Dummy runner for tests that don't have MessageLoop.
70 base::MessageLoop loop;
71 // This works because |runner| takes a ref to the proxy.
72 runner = base::ThreadTaskRunnerHandle::Get();
73 }
74 std::unique_ptr<AttachmentStoreBackend> backend(
75 new InMemoryAttachmentStore(runner));
76 scoped_refptr<AttachmentStoreFrontend> frontend(
77 new AttachmentStoreFrontend(std::move(backend), runner));
78 std::unique_ptr<AttachmentStore> attachment_store(
79 new AttachmentStore(frontend, MODEL_TYPE));
80 return attachment_store;
81 }
82
83 std::unique_ptr<AttachmentStore> AttachmentStore::CreateOnDiskStore(
84 const base::FilePath& path,
85 const scoped_refptr<base::SequencedTaskRunner>& backend_task_runner,
86 const InitCallback& callback) {
87 std::unique_ptr<OnDiskAttachmentStore> backend(
88 new OnDiskAttachmentStore(base::ThreadTaskRunnerHandle::Get(), path));
89
90 scoped_refptr<AttachmentStoreFrontend> frontend =
91 new AttachmentStoreFrontend(std::move(backend), backend_task_runner);
92 std::unique_ptr<AttachmentStore> attachment_store(
93 new AttachmentStore(frontend, MODEL_TYPE));
94 frontend->Init(callback);
95
96 return attachment_store;
97 }
98
99 std::unique_ptr<AttachmentStore> AttachmentStore::CreateMockStoreForTest(
100 std::unique_ptr<AttachmentStoreBackend> backend) {
101 scoped_refptr<base::SingleThreadTaskRunner> runner =
102 base::ThreadTaskRunnerHandle::Get();
103 scoped_refptr<AttachmentStoreFrontend> attachment_store_frontend(
104 new AttachmentStoreFrontend(std::move(backend), runner));
105 std::unique_ptr<AttachmentStore> attachment_store(
106 new AttachmentStore(attachment_store_frontend, MODEL_TYPE));
107 return attachment_store;
108 }
109
110 AttachmentStoreForSync::AttachmentStoreForSync(
111 const scoped_refptr<AttachmentStoreFrontend>& frontend,
112 Component consumer_component,
113 Component sync_component)
114 : AttachmentStore(frontend, consumer_component),
115 sync_component_(sync_component) {}
116
117 AttachmentStoreForSync::~AttachmentStoreForSync() {}
118
119 void AttachmentStoreForSync::SetSyncReference(const AttachmentIdList& ids) {
120 frontend()->SetReference(sync_component_, ids);
121 }
122
123 void AttachmentStoreForSync::SetModelTypeReference(
124 const AttachmentIdList& ids) {
125 frontend()->SetReference(component(), ids);
126 }
127
128 void AttachmentStoreForSync::DropSyncReference(const AttachmentIdList& ids) {
129 frontend()->DropReference(sync_component_, ids,
130 base::Bind(&NoOpDropCallback));
131 }
132
133 void AttachmentStoreForSync::ReadMetadataForSync(
134 const ReadMetadataCallback& callback) {
135 frontend()->ReadMetadata(sync_component_, callback);
136 }
137
138 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/api/attachments/attachment_store.h ('k') | components/sync/api/attachments/attachment_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698