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

Side by Side Diff: components/sync/core_impl/attachments/attachment_service_proxy.cc

Issue 2399953002: [Sync] Move attachments code out of core/. (Closed)
Patch Set: Address comments. 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/core/attachments/attachment_service_proxy.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/threading/thread_task_runner_handle.h"
10
11 namespace syncer {
12
13 namespace {
14
15 // These ProxyFooCallback functions are used to invoke a callback in a specific
16 // thread.
17
18 // Invokes |callback| with |result| and |attachments| in the |task_runner|
19 // thread.
20 void ProxyGetOrDownloadCallback(
21 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
22 const AttachmentService::GetOrDownloadCallback& callback,
23 const AttachmentService::GetOrDownloadResult& result,
24 std::unique_ptr<AttachmentMap> attachments) {
25 task_runner->PostTask(
26 FROM_HERE, base::Bind(callback, result, base::Passed(&attachments)));
27 }
28
29 } // namespace
30
31 AttachmentServiceProxy::AttachmentServiceProxy() {}
32
33 AttachmentServiceProxy::AttachmentServiceProxy(
34 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
35 const base::WeakPtr<AttachmentService>& wrapped)
36 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) {
37 DCHECK(wrapped_task_runner_.get());
38 }
39
40 AttachmentServiceProxy::AttachmentServiceProxy(
41 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
42 const scoped_refptr<Core>& core)
43 : wrapped_task_runner_(wrapped_task_runner), core_(core) {
44 DCHECK(wrapped_task_runner_.get());
45 DCHECK(core_.get());
46 }
47
48 AttachmentServiceProxy::AttachmentServiceProxy(
49 const AttachmentServiceProxy& other) = default;
50
51 AttachmentServiceProxy::~AttachmentServiceProxy() {}
52
53 void AttachmentServiceProxy::GetOrDownloadAttachments(
54 const AttachmentIdList& attachment_ids,
55 const GetOrDownloadCallback& callback) {
56 DCHECK(wrapped_task_runner_.get());
57 GetOrDownloadCallback proxy_callback =
58 base::Bind(&ProxyGetOrDownloadCallback,
59 base::ThreadTaskRunnerHandle::Get(), callback);
60 wrapped_task_runner_->PostTask(
61 FROM_HERE, base::Bind(&AttachmentService::GetOrDownloadAttachments, core_,
62 attachment_ids, proxy_callback));
63 }
64
65 void AttachmentServiceProxy::UploadAttachments(
66 const AttachmentIdList& attachment_ids) {
67 DCHECK(wrapped_task_runner_.get());
68 wrapped_task_runner_->PostTask(
69 FROM_HERE,
70 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids));
71 }
72
73 AttachmentServiceProxy::Core::Core(
74 const base::WeakPtr<AttachmentService>& wrapped)
75 : wrapped_(wrapped) {}
76
77 AttachmentServiceProxy::Core::~Core() {}
78
79 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
80 const AttachmentIdList& attachment_ids,
81 const GetOrDownloadCallback& callback) {
82 if (!wrapped_) {
83 return;
84 }
85 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
86 }
87
88 void AttachmentServiceProxy::Core::UploadAttachments(
89 const AttachmentIdList& attachment_ids) {
90 if (!wrapped_) {
91 return;
92 }
93 wrapped_->UploadAttachments(attachment_ids);
94 }
95
96 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698