• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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.
ProxyGetOrDownloadCallback(const scoped_refptr<base::SequencedTaskRunner> & task_runner,const AttachmentService::GetOrDownloadCallback & callback,const AttachmentService::GetOrDownloadResult & result,scoped_ptr<AttachmentMap> attachments)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)));
27 }
28 
29 // Invokes |callback| with |result| and |attachments| in the |task_runner|
30 // thread.
ProxyDropCallback(const scoped_refptr<base::SequencedTaskRunner> & task_runner,const AttachmentService::DropCallback & callback,const AttachmentService::DropResult & result)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));
36 }
37 
38 }  // namespace
39 
AttachmentServiceProxy()40 AttachmentServiceProxy::AttachmentServiceProxy() {
41 }
42 
AttachmentServiceProxy(const scoped_refptr<base::SequencedTaskRunner> & wrapped_task_runner,const base::WeakPtr<syncer::AttachmentService> & wrapped)43 AttachmentServiceProxy::AttachmentServiceProxy(
44     const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
45     const base::WeakPtr<syncer::AttachmentService>& wrapped)
46     : wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) {
47   DCHECK(wrapped_task_runner_.get());
48 }
49 
AttachmentServiceProxy(const scoped_refptr<base::SequencedTaskRunner> & wrapped_task_runner,const scoped_refptr<Core> & core)50 AttachmentServiceProxy::AttachmentServiceProxy(
51     const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
52     const scoped_refptr<Core>& core)
53     : wrapped_task_runner_(wrapped_task_runner), core_(core) {
54   DCHECK(wrapped_task_runner_.get());
55   DCHECK(core_.get());
56 }
57 
~AttachmentServiceProxy()58 AttachmentServiceProxy::~AttachmentServiceProxy() {
59 }
60 
GetStore()61 AttachmentStore* AttachmentServiceProxy::GetStore() {
62   return NULL;
63 }
64 
GetOrDownloadAttachments(const AttachmentIdList & attachment_ids,const GetOrDownloadCallback & callback)65 void AttachmentServiceProxy::GetOrDownloadAttachments(
66     const AttachmentIdList& attachment_ids,
67     const GetOrDownloadCallback& callback) {
68   DCHECK(wrapped_task_runner_.get());
69   GetOrDownloadCallback proxy_callback =
70       base::Bind(&ProxyGetOrDownloadCallback,
71                  base::ThreadTaskRunnerHandle::Get(),
72                  callback);
73   wrapped_task_runner_->PostTask(
74       FROM_HERE,
75       base::Bind(&AttachmentService::GetOrDownloadAttachments,
76                  core_,
77                  attachment_ids,
78                  proxy_callback));
79 }
80 
DropAttachments(const AttachmentIdList & attachment_ids,const DropCallback & callback)81 void AttachmentServiceProxy::DropAttachments(
82     const AttachmentIdList& attachment_ids,
83     const DropCallback& callback) {
84   DCHECK(wrapped_task_runner_.get());
85   DropCallback proxy_callback = base::Bind(
86       &ProxyDropCallback, base::ThreadTaskRunnerHandle::Get(), callback);
87   wrapped_task_runner_->PostTask(FROM_HERE,
88                                  base::Bind(&AttachmentService::DropAttachments,
89                                             core_,
90                                             attachment_ids,
91                                             proxy_callback));
92 }
93 
UploadAttachments(const AttachmentIdSet & attachment_ids)94 void AttachmentServiceProxy::UploadAttachments(
95     const AttachmentIdSet& attachment_ids) {
96   DCHECK(wrapped_task_runner_.get());
97   wrapped_task_runner_->PostTask(
98       FROM_HERE,
99       base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids));
100 }
101 
Core(const base::WeakPtr<syncer::AttachmentService> & wrapped)102 AttachmentServiceProxy::Core::Core(
103     const base::WeakPtr<syncer::AttachmentService>& wrapped)
104     : wrapped_(wrapped) {
105 }
106 
~Core()107 AttachmentServiceProxy::Core::~Core() {
108 }
109 
GetStore()110 AttachmentStore* AttachmentServiceProxy::Core::GetStore() {
111   return NULL;
112 }
113 
GetOrDownloadAttachments(const AttachmentIdList & attachment_ids,const GetOrDownloadCallback & callback)114 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
115     const AttachmentIdList& attachment_ids,
116     const GetOrDownloadCallback& callback) {
117   if (!wrapped_) {
118     return;
119   }
120   wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
121 }
122 
DropAttachments(const AttachmentIdList & attachment_ids,const DropCallback & callback)123 void AttachmentServiceProxy::Core::DropAttachments(
124     const AttachmentIdList& attachment_ids,
125     const DropCallback& callback) {
126   if (!wrapped_) {
127     return;
128   }
129   wrapped_->DropAttachments(attachment_ids, callback);
130 }
131 
UploadAttachments(const AttachmentIdSet & attachment_ids)132 void AttachmentServiceProxy::Core::UploadAttachments(
133     const AttachmentIdSet& attachment_ids) {
134   if (!wrapped_) {
135     return;
136   }
137   wrapped_->UploadAttachments(attachment_ids);
138 }
139 
140 }  // namespace syncer
141