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

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

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

Powered by Google App Engine
This is Rietveld 408576698