Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / sync / internal_api / attachments / attachment_service_proxy.cc
blob91a627db3f793ee9fc7b6c7456690e76373f4690
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 } // namespace
31 AttachmentServiceProxy::AttachmentServiceProxy() {
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());
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());
49 AttachmentServiceProxy::~AttachmentServiceProxy() {
52 void AttachmentServiceProxy::GetOrDownloadAttachments(
53 const AttachmentIdList& attachment_ids,
54 const GetOrDownloadCallback& callback) {
55 DCHECK(wrapped_task_runner_.get());
56 GetOrDownloadCallback proxy_callback =
57 base::Bind(&ProxyGetOrDownloadCallback,
58 base::ThreadTaskRunnerHandle::Get(),
59 callback);
60 wrapped_task_runner_->PostTask(
61 FROM_HERE,
62 base::Bind(&AttachmentService::GetOrDownloadAttachments,
63 core_,
64 attachment_ids,
65 proxy_callback));
68 void AttachmentServiceProxy::UploadAttachments(
69 const AttachmentIdList& attachment_ids) {
70 DCHECK(wrapped_task_runner_.get());
71 wrapped_task_runner_->PostTask(
72 FROM_HERE,
73 base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids));
76 AttachmentServiceProxy::Core::Core(
77 const base::WeakPtr<syncer::AttachmentService>& wrapped)
78 : wrapped_(wrapped) {
81 AttachmentServiceProxy::Core::~Core() {
84 void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
85 const AttachmentIdList& attachment_ids,
86 const GetOrDownloadCallback& callback) {
87 if (!wrapped_) {
88 return;
90 wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
93 void AttachmentServiceProxy::Core::UploadAttachments(
94 const AttachmentIdList& attachment_ids) {
95 if (!wrapped_) {
96 return;
98 wrapped_->UploadAttachments(attachment_ids);
101 } // namespace syncer