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

Side by Side Diff: sync/internal_api/attachments/attachment_service_proxy.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/internal_api/public/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
34 AttachmentServiceProxy::AttachmentServiceProxy(
35 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
36 const base::WeakPtr<syncer::AttachmentService>& wrapped)
37 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) {
38 DCHECK(wrapped_task_runner_.get());
39 }
40
41 AttachmentServiceProxy::AttachmentServiceProxy(
42 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
43 const scoped_refptr<Core>& core)
44 : wrapped_task_runner_(wrapped_task_runner), core_(core) {
45 DCHECK(wrapped_task_runner_.get());
46 DCHECK(core_.get());
47 }
48
49 AttachmentServiceProxy::AttachmentServiceProxy(
50 const AttachmentServiceProxy& other) = default;
51
52 AttachmentServiceProxy::~AttachmentServiceProxy() {
53 }
54
55 void AttachmentServiceProxy::GetOrDownloadAttachments(
56 const AttachmentIdList& attachment_ids,
57 const GetOrDownloadCallback& callback) {
58 DCHECK(wrapped_task_runner_.get());
59 GetOrDownloadCallback proxy_callback =
60 base::Bind(&ProxyGetOrDownloadCallback,
61 base::ThreadTaskRunnerHandle::Get(),
62 callback);
63 wrapped_task_runner_->PostTask(
64 FROM_HERE,
65 base::Bind(&AttachmentService::GetOrDownloadAttachments,
66 core_,
67 attachment_ids,
68 proxy_callback));
69 }
70
71 void AttachmentServiceProxy::UploadAttachments(
72 const AttachmentIdList& attachment_ids) {
73 DCHECK(wrapped_task_runner_.get());
74 wrapped_task_runner_->PostTask(
75 FROM_HERE,
76 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids));
77 }
78
79 AttachmentServiceProxy::Core::Core(
80 const base::WeakPtr<syncer::AttachmentService>& wrapped)
81 : wrapped_(wrapped) {
82 }
83
84 AttachmentServiceProxy::Core::~Core() {
85 }
86
87 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
88 const AttachmentIdList& attachment_ids,
89 const GetOrDownloadCallback& callback) {
90 if (!wrapped_) {
91 return;
92 }
93 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
94 }
95
96 void AttachmentServiceProxy::Core::UploadAttachments(
97 const AttachmentIdList& attachment_ids) {
98 if (!wrapped_) {
99 return;
100 }
101 wrapped_->UploadAttachments(attachment_ids);
102 }
103
104 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698