Provide GUID in ONC for all networks in ManagedNetworkConfigurationHandler
[chromium-blink-merge.git] / sync / internal_api / attachments / attachment_service_proxy.cc
blob6b1040bafdf3a0aa6cbe5b367384b958a3d76057
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 } // namespace
40 AttachmentServiceProxy::AttachmentServiceProxy() {
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());
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());
58 AttachmentServiceProxy::~AttachmentServiceProxy() {
61 AttachmentStore* AttachmentServiceProxy::GetStore() {
62 return NULL;
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));
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));
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));
102 AttachmentServiceProxy::Core::Core(
103 const base::WeakPtr<syncer::AttachmentService>& wrapped)
104 : wrapped_(wrapped) {
107 AttachmentServiceProxy::Core::~Core() {
110 AttachmentStore* AttachmentServiceProxy::Core::GetStore() {
111 return NULL;
114 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
115 const AttachmentIdList& attachment_ids,
116 const GetOrDownloadCallback& callback) {
117 if (!wrapped_) {
118 return;
120 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
123 void AttachmentServiceProxy::Core::DropAttachments(
124 const AttachmentIdList& attachment_ids,
125 const DropCallback& callback) {
126 if (!wrapped_) {
127 return;
129 wrapped_->DropAttachments(attachment_ids, callback);
132 void AttachmentServiceProxy::Core::UploadAttachments(
133 const AttachmentIdSet& attachment_ids) {
134 if (!wrapped_) {
135 return;
137 wrapped_->UploadAttachments(attachment_ids);
140 } // namespace syncer