summaryrefslogtreecommitdiffstats
path: root/sync/api/attachments
diff options
context:
space:
mode:
authorpavely@chromium.org <pavely@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 20:20:32 +0000
committerpavely@chromium.org <pavely@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-23 20:20:32 +0000
commit1ee3768fded14dff8fe5fbb8938c1601cb57d9b7 (patch)
treed59df1d0d818c0269641e38f6d65937f0045ba64 /sync/api/attachments
parentc3dd3384f1a159eabd913ada94f3a1627735015d (diff)
downloadchromium_src-1ee3768fded14dff8fe5fbb8938c1601cb57d9b7.zip
chromium_src-1ee3768fded14dff8fe5fbb8938c1601cb57d9b7.tar.gz
chromium_src-1ee3768fded14dff8fe5fbb8938c1601cb57d9b7.tar.bz2
Add AttachmentDownloader interface, change signature of AttachmentStore::Read
- AttachmentDownloader interface is similar to AttachmentUploader interface. No implementation yet. - AttachmentStore::Read guarantee should be stronger. It should attempt to read all attachments and return list of attachment ids that can't be loaded locally. Those need to be downloaded from server. R=maniscalco@chromium.org BUG=376073 Review URL: https://codereview.chromium.org/293143002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272585 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/api/attachments')
-rw-r--r--sync/api/attachments/attachment_downloader.cc12
-rw-r--r--sync/api/attachments/attachment_downloader.h41
-rw-r--r--sync/api/attachments/attachment_service_impl.cc8
-rw-r--r--sync/api/attachments/attachment_service_impl.h3
-rw-r--r--sync/api/attachments/attachment_store.h16
-rw-r--r--sync/api/attachments/attachment_uploader.h3
6 files changed, 71 insertions, 12 deletions
diff --git a/sync/api/attachments/attachment_downloader.cc b/sync/api/attachments/attachment_downloader.cc
new file mode 100644
index 0000000..a0108f7
--- /dev/null
+++ b/sync/api/attachments/attachment_downloader.cc
@@ -0,0 +1,12 @@
+// 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/api/attachments/attachment_downloader.h"
+
+namespace syncer {
+
+AttachmentDownloader::~AttachmentDownloader() {
+}
+
+} // namespace syncer
diff --git a/sync/api/attachments/attachment_downloader.h b/sync/api/attachments/attachment_downloader.h
new file mode 100644
index 0000000..0473899
--- /dev/null
+++ b/sync/api/attachments/attachment_downloader.h
@@ -0,0 +1,41 @@
+// 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.
+
+#ifndef SYNC_API_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_
+#define SYNC_API_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "sync/api/attachments/attachment.h"
+#include "sync/base/sync_export.h"
+
+namespace syncer {
+
+// AttachmentDownloader is responsible for downloading attachments from server.
+class SYNC_EXPORT AttachmentDownloader {
+ public:
+ // The result of a DownloadAttachment operation.
+ enum DownloadResult {
+ DOWNLOAD_SUCCESS, // No error, attachment was downloaded
+ // successfully.
+ DOWNLOAD_UNSPECIFIED_ERROR, // An unspecified error occurred.
+ };
+
+ typedef base::Callback<void(const DownloadResult&, scoped_ptr<Attachment>)>
+ DownloadCallback;
+
+ virtual ~AttachmentDownloader();
+
+ // Download attachment referred by |attachment_id| and invoke |callback| when
+ // done.
+ //
+ // |callback| will receive a DownloadResult code and an Attachment object. If
+ // DownloadResult is not DOWNLOAD_SUCCESS then attachment pointer is NULL.
+ virtual void DownloadAttachment(const AttachmentId& attachment_id,
+ const DownloadCallback& callback) = 0;
+};
+
+} // namespace syncer
+
+#endif // SYNC_API_ATTACHMENTS_ATTACHMENT_DOWNLOADER_H_
diff --git a/sync/api/attachments/attachment_service_impl.cc b/sync/api/attachments/attachment_service_impl.cc
index a77d052..af2dea7 100644
--- a/sync/api/attachments/attachment_service_impl.cc
+++ b/sync/api/attachments/attachment_service_impl.cc
@@ -95,9 +95,11 @@ void AttachmentServiceImpl::OnSyncDataUpdate(
// attachments from local storage (bug 356351).
}
-void AttachmentServiceImpl::ReadDone(const GetOrDownloadCallback& callback,
- const AttachmentStore::Result& result,
- scoped_ptr<AttachmentMap> attachments) {
+void AttachmentServiceImpl::ReadDone(
+ const GetOrDownloadCallback& callback,
+ const AttachmentStore::Result& result,
+ scoped_ptr<AttachmentMap> attachments,
+ scoped_ptr<AttachmentIdList> unavailable_attachment_ids) {
AttachmentService::GetOrDownloadResult get_result =
AttachmentService::GET_UNSPECIFIED_ERROR;
if (result == AttachmentStore::SUCCESS) {
diff --git a/sync/api/attachments/attachment_service_impl.h b/sync/api/attachments/attachment_service_impl.h
index aa99110..dbb1b53 100644
--- a/sync/api/attachments/attachment_service_impl.h
+++ b/sync/api/attachments/attachment_service_impl.h
@@ -45,7 +45,8 @@ class SYNC_EXPORT AttachmentServiceImpl : public AttachmentService,
private:
void ReadDone(const GetOrDownloadCallback& callback,
const AttachmentStore::Result& result,
- scoped_ptr<AttachmentMap> attachments);
+ scoped_ptr<AttachmentMap> attachments,
+ scoped_ptr<AttachmentIdList> unavailable_attachment_ids);
void DropDone(const DropCallback& callback,
const AttachmentStore::Result& result);
void WriteDone(const StoreCallback& callback,
diff --git a/sync/api/attachments/attachment_store.h b/sync/api/attachments/attachment_store.h
index d86cd1b..b8834e0 100644
--- a/sync/api/attachments/attachment_store.h
+++ b/sync/api/attachments/attachment_store.h
@@ -38,17 +38,21 @@ class SYNC_EXPORT AttachmentStore {
UNSPECIFIED_ERROR, // An unspecified error occurred for one or more items.
};
- typedef base::Callback<void(const Result&, scoped_ptr<AttachmentMap>)>
- ReadCallback;
+ typedef base::Callback<void(const Result&,
+ scoped_ptr<AttachmentMap>,
+ scoped_ptr<AttachmentIdList>)> ReadCallback;
typedef base::Callback<void(const Result&)> WriteCallback;
typedef base::Callback<void(const Result&)> DropCallback;
// Asynchronously reads the attachments identified by |ids|.
//
- // |callback| will be invoked when finished. If any of the attachments do not
- // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR
- // and |callback| may receive a partial result. That is, AttachmentMap may be
- // empty or may contain the attachments that were read successfully.
+ // |callback| will be invoked when finished. AttachmentStore will attempt to
+ // read all attachments specified in ids. If any of the attachments do not
+ // exist or could not be read, |callback|'s Result will be UNSPECIFIED_ERROR.
+ // Callback's AttachmentMap will contain all attachments that were
+ // successfully read, AttachmentIdList will contain attachment ids of
+ // attachments that are unavailable in attachment store, these need to be
+ // downloaded from server.
//
// Reads on individual attachments are treated atomically; |callback| will not
// read only part of an attachment.
diff --git a/sync/api/attachments/attachment_uploader.h b/sync/api/attachments/attachment_uploader.h
index 325a9e7..12fe1a3 100644
--- a/sync/api/attachments/attachment_uploader.h
+++ b/sync/api/attachments/attachment_uploader.h
@@ -8,7 +8,6 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
#include "sync/api/attachments/attachment.h"
#include "sync/base/sync_export.h"
@@ -36,7 +35,7 @@ class SYNC_EXPORT AttachmentUploader {
// or otherwise).
//
// |callback| will receive an UploadResult code and an updated AttachmentId
- // |containing the server address of the newly uploaded attachment.
+ // containing the server address of the newly uploaded attachment.
virtual void UploadAttachment(const Attachment& attachment,
const UploadCallback& callback) = 0;
};