1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/internal_api/public/attachments/attachment_service_proxy.h"
#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/thread_task_runner_handle.h"
namespace syncer {
namespace {
// These ProxyFooCallback functions are used to invoke a callback in a specific
// thread.
// Invokes |callback| with |result| and |attachments| in the |task_runner|
// thread.
void ProxyGetOrDownloadCallback(
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const AttachmentService::GetOrDownloadCallback& callback,
const AttachmentService::GetOrDownloadResult& result,
scoped_ptr<AttachmentMap> attachments) {
task_runner->PostTask(
FROM_HERE, base::Bind(callback, result, base::Passed(&attachments)));
}
} // namespace
AttachmentServiceProxy::AttachmentServiceProxy() {
}
AttachmentServiceProxy::AttachmentServiceProxy(
const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
const base::WeakPtr<syncer::AttachmentService>& wrapped)
: wrapped_task_runner_(wrapped_task_runner), core_(new Core(wrapped)) {
DCHECK(wrapped_task_runner_.get());
}
AttachmentServiceProxy::AttachmentServiceProxy(
const scoped_refptr<base::SequencedTaskRunner>& wrapped_task_runner,
const scoped_refptr<Core>& core)
: wrapped_task_runner_(wrapped_task_runner), core_(core) {
DCHECK(wrapped_task_runner_.get());
DCHECK(core_.get());
}
AttachmentServiceProxy::~AttachmentServiceProxy() {
}
void AttachmentServiceProxy::GetOrDownloadAttachments(
const AttachmentIdList& attachment_ids,
const GetOrDownloadCallback& callback) {
DCHECK(wrapped_task_runner_.get());
GetOrDownloadCallback proxy_callback =
base::Bind(&ProxyGetOrDownloadCallback,
base::ThreadTaskRunnerHandle::Get(),
callback);
wrapped_task_runner_->PostTask(
FROM_HERE,
base::Bind(&AttachmentService::GetOrDownloadAttachments,
core_,
attachment_ids,
proxy_callback));
}
void AttachmentServiceProxy::UploadAttachments(
const AttachmentIdList& attachment_ids) {
DCHECK(wrapped_task_runner_.get());
wrapped_task_runner_->PostTask(
FROM_HERE,
base::Bind(&AttachmentService::UploadAttachments, core_, attachment_ids));
}
AttachmentServiceProxy::Core::Core(
const base::WeakPtr<syncer::AttachmentService>& wrapped)
: wrapped_(wrapped) {
}
AttachmentServiceProxy::Core::~Core() {
}
void AttachmentServiceProxy::Core::GetOrDownloadAttachments(
const AttachmentIdList& attachment_ids,
const GetOrDownloadCallback& callback) {
if (!wrapped_) {
return;
}
wrapped_->GetOrDownloadAttachments(attachment_ids, callback);
}
void AttachmentServiceProxy::Core::UploadAttachments(
const AttachmentIdList& attachment_ids) {
if (!wrapped_) {
return;
}
wrapped_->UploadAttachments(attachment_ids);
}
} // namespace syncer
|