diff options
Diffstat (limited to 'sync/api/attachments')
-rw-r--r-- | sync/api/attachments/attachment_metadata.cc | 24 | ||||
-rw-r--r-- | sync/api/attachments/attachment_metadata.h | 41 | ||||
-rw-r--r-- | sync/api/attachments/attachment_metadata_unittest.cc | 21 | ||||
-rw-r--r-- | sync/api/attachments/attachment_store.h | 19 |
4 files changed, 105 insertions, 0 deletions
diff --git a/sync/api/attachments/attachment_metadata.cc b/sync/api/attachments/attachment_metadata.cc new file mode 100644 index 0000000..202de23 --- /dev/null +++ b/sync/api/attachments/attachment_metadata.cc @@ -0,0 +1,24 @@ +// 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_metadata.h" + +namespace syncer { + +AttachmentMetadata::AttachmentMetadata(const AttachmentId& id, size_t size) + : id_(id), size_(size) { +} + +AttachmentMetadata::~AttachmentMetadata() { +} + +const AttachmentId& AttachmentMetadata::GetId() const { + return id_; +} + +size_t AttachmentMetadata::GetSize() const { + return size_; +} + +} // namespace syncer diff --git a/sync/api/attachments/attachment_metadata.h b/sync/api/attachments/attachment_metadata.h new file mode 100644 index 0000000..10761f8 --- /dev/null +++ b/sync/api/attachments/attachment_metadata.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_METADATA_H_ +#define SYNC_API_ATTACHMENTS_ATTACHMENT_METADATA_H_ + +#include <vector> + +#include "base/basictypes.h" +#include "sync/api/attachments/attachment_id.h" +#include "sync/base/sync_export.h" + +namespace syncer { + +// This class represents immutable Attachment metadata. +// +// It is OK to copy and return AttachmentMetadata by value. +class SYNC_EXPORT AttachmentMetadata { + public: + AttachmentMetadata(const AttachmentId& id, size_t size); + ~AttachmentMetadata(); + + // Default copy and assignment are welcome. + + // Returns this attachment's id. + const AttachmentId& GetId() const; + + // Returns this attachment's size in bytes. + size_t GetSize() const; + + private: + AttachmentId id_; + size_t size_; +}; + +typedef std::vector<syncer::AttachmentMetadata> AttachmentMetadataList; + +} // namespace syncer + +#endif // SYNC_API_ATTACHMENTS_ATTACHMENT_METADATA_H_ diff --git a/sync/api/attachments/attachment_metadata_unittest.cc b/sync/api/attachments/attachment_metadata_unittest.cc new file mode 100644 index 0000000..06477d0 --- /dev/null +++ b/sync/api/attachments/attachment_metadata_unittest.cc @@ -0,0 +1,21 @@ +// 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_metadata.h" + +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { + +class AttachmentMetadataTest : public testing::Test {}; + +TEST_F(AttachmentMetadataTest, Create) { + AttachmentId id = AttachmentId::Create(); + size_t size = 42; + AttachmentMetadata metadata(id, size); + EXPECT_EQ(metadata.GetId(), id); + EXPECT_EQ(metadata.GetSize(), size); +} + +} // namespace syncer diff --git a/sync/api/attachments/attachment_store.h b/sync/api/attachments/attachment_store.h index 3c41a27..6c7791a 100644 --- a/sync/api/attachments/attachment_store.h +++ b/sync/api/attachments/attachment_store.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "sync/api/attachments/attachment.h" #include "sync/api/attachments/attachment_id.h" +#include "sync/api/attachments/attachment_metadata.h" #include "sync/base/sync_export.h" namespace base { @@ -42,6 +43,9 @@ class SYNC_EXPORT AttachmentStoreBase { scoped_ptr<AttachmentIdList>)> ReadCallback; typedef base::Callback<void(const Result&)> WriteCallback; typedef base::Callback<void(const Result&)> DropCallback; + typedef base::Callback<void(const Result&, + scoped_ptr<AttachmentMetadataList>)> + ReadMetadataCallback; AttachmentStoreBase(); virtual ~AttachmentStoreBase(); @@ -84,6 +88,21 @@ class SYNC_EXPORT AttachmentStoreBase { // successfully. virtual void Drop(const AttachmentIdList& ids, const DropCallback& callback) = 0; + + // Asynchronously reads metadata for the attachments identified by |ids|. + // + // |callback| will be invoked when finished. AttachmentStore will attempt to + // read metadata for all attachments specified in ids. If any of the + // metadata entries do not exist or could not be read, |callback|'s Result + // will be UNSPECIFIED_ERROR. + virtual void ReadMetadata(const AttachmentIdList& ids, + const ReadMetadataCallback& callback) = 0; + + // Asynchronously reads metadata for all attachments in the store. + // + // |callback| will be invoked when finished. If any of the metadata entries + // could not be read, |callback|'s Result will be UNSPECIFIED_ERROR. + virtual void ReadAllMetadata(const ReadMetadataCallback& callback) = 0; }; // AttachmentStore is an interface exposed to data type and AttachmentService |