Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / sync / internal_api / attachments / attachment_service_proxy.cc
blob1d418788e11ffdf71c1115484a2f0d7e8b1ae24f
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.
5 #include "sync/internal_api/public/attachments/attachment_service_proxy.h"
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/thread_task_runner_handle.h"
11 namespace syncer {
13 namespace {
15 // These ProxyFooCallback functions are used to invoke a callback in a specific
16 // thread.
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 scoped_ptr<AttachmentMap> attachments) {
25 task_runner->PostTask(
26 FROM_HERE, base::Bind(callback, result, base::Passed(&attachments)));
29 // Invokes |callback| with |result| and |attachments| in the |task_runner|
30 // thread.
31 void ProxyDropCallback(
32 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
33 const AttachmentService::DropCallback& callback,
34 const AttachmentService::DropResult& result) {
35 task_runner->PostTask(FROM_HERE, base::Bind(callback, result));
38 // Invokes |callback| with |result| and |attachments| in the |task_runner|
39 // thread.
40 void ProxyStoreCallback(
41 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
42 const AttachmentService::StoreCallback& callback,
43 const AttachmentService::StoreResult& result) {
44 task_runner->PostTask(FROM_HERE, base::Bind(callback, result));
47 } // namespace
49 AttachmentServiceProxy::AttachmentServiceProxy() {
52 AttachmentServiceProxy::AttachmentServiceProxy(
53 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
54 const base::WeakPtr<syncer::AttachmentService>& wrapped)
55 : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) {
56 DCHECK(wrapped_task_runner_.get());
59 AttachmentServiceProxy::AttachmentServiceProxy(
60 const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
61 const scoped_refptr<Core>& core)
62 : wrapped_task_runner_(wrapped_task_runner), core_(core) {
63 DCHECK(wrapped_task_runner_.get());
64 DCHECK(core_.get());
67 AttachmentServiceProxy::~AttachmentServiceProxy() {
70 void AttachmentServiceProxy::GetOrDownloadAttachments(
71 const AttachmentIdList& attachment_ids,
72 const GetOrDownloadCallback& callback) {
73 DCHECK(wrapped_task_runner_.get());
74 GetOrDownloadCallback proxy_callback =
75 base::Bind(&ProxyGetOrDownloadCallback,
76 base::ThreadTaskRunnerHandle::Get(),
77 callback);
78 wrapped_task_runner_->PostTask(
79 FROM_HERE,
80 base::Bind(&AttachmentService::GetOrDownloadAttachments,
81 core_,
82 attachment_ids,
83 proxy_callback));
86 void AttachmentServiceProxy::DropAttachments(
87 const AttachmentIdList& attachment_ids,
88 const DropCallback& callback) {
89 DCHECK(wrapped_task_runner_.get());
90 DropCallback proxy_callback = base::Bind(
91 &ProxyDropCallback, base::ThreadTaskRunnerHandle::Get(), callback);
92 wrapped_task_runner_->PostTask(FROM_HERE,
93 base::Bind(&AttachmentService::DropAttachments,
94 core_,
95 attachment_ids,
96 proxy_callback));
99 void AttachmentServiceProxy::StoreAttachments(const AttachmentList& attachments,
100 const StoreCallback& callback) {
101 DCHECK(wrapped_task_runner_.get());
102 StoreCallback proxy_callback = base::Bind(
103 &ProxyStoreCallback, base::ThreadTaskRunnerHandle::Get(), callback);
104 wrapped_task_runner_->PostTask(
105 FROM_HERE,
106 base::Bind(&AttachmentService::StoreAttachments,
107 core_,
108 attachments,
109 proxy_callback));
112 AttachmentServiceProxy::Core::Core(
113 const base::WeakPtr<syncer::AttachmentService>& wrapped)
114 : wrapped_(wrapped) {
117 AttachmentServiceProxy::Core::~Core() {
120 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
121 const AttachmentIdList& attachment_ids,
122 const GetOrDownloadCallback& callback) {
123 if (!wrapped_) {
124 return;
126 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
129 void AttachmentServiceProxy::Core::DropAttachments(
130 const AttachmentIdList& attachment_ids,
131 const DropCallback& callback) {
132 if (!wrapped_) {
133 return;
135 wrapped_->DropAttachments(attachment_ids, callback);
138 void AttachmentServiceProxy::Core::StoreAttachments(
139 const AttachmentList& attachments,
140 const StoreCallback& callback) {
141 if (!wrapped_) {
142 return;
144 wrapped_->StoreAttachments(attachments, callback);
147 } // namespace syncer