summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaniscalco@chromium.org <maniscalco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-02 22:42:14 +0000
committermaniscalco@chromium.org <maniscalco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-02 22:42:14 +0000
commitd0fcac09a5259cf728931e91f87c26806ae99548 (patch)
treeb1868f9b4f41c78d9150a66e7466d0cafeef0f59
parent7ffa8815e1e13ede3313951fc001eba0fe9d9ef8 (diff)
downloadchromium_src-d0fcac09a5259cf728931e91f87c26806ae99548.zip
chromium_src-d0fcac09a5259cf728931e91f87c26806ae99548.tar.gz
chromium_src-d0fcac09a5259cf728931e91f87c26806ae99548.tar.bz2
Checkpointing some Sync Attachment work. Added SyncAttachment and SyncAttachmentId. The interfaces are still in flux and will likely change.
Review URL: https://codereview.chromium.org/102193004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242818 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--sync/api/sync_attachment.cc45
-rw-r--r--sync/api/sync_attachment.h58
-rw-r--r--sync/api/sync_attachment_unittest.cc54
-rw-r--r--sync/protocol/attachments.proto24
-rw-r--r--sync/protocol/proto_value_conversions.cc7
-rw-r--r--sync/protocol/proto_value_conversions.h4
-rw-r--r--sync/protocol/proto_value_conversions_unittest.cc4
-rw-r--r--sync/protocol/sync.proto1
-rw-r--r--sync/sync_api.gypi14
-rw-r--r--sync/sync_proto.gypi1
-rw-r--r--sync/sync_tests.gypi1
11 files changed, 207 insertions, 6 deletions
diff --git a/sync/api/sync_attachment.cc b/sync/api/sync_attachment.cc
new file mode 100644
index 0000000..a214307
--- /dev/null
+++ b/sync/api/sync_attachment.cc
@@ -0,0 +1,45 @@
+// 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/sync_attachment.h"
+
+#include "base/logging.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/rand_util.h"
+
+namespace syncer {
+
+SyncAttachment::~SyncAttachment() {}
+
+// Static.
+scoped_ptr<SyncAttachment> SyncAttachment::Create(
+ const scoped_refptr<base::RefCountedMemory>& bytes) {
+ sync_pb::SyncAttachmentId id;
+ // Only requirement here is that this id must be globally unique.
+ id.set_unique_id(base::RandBytesAsString(16));
+ return CreateWithId(id, bytes);
+}
+
+// Static.
+scoped_ptr<SyncAttachment> SyncAttachment::CreateWithId(
+ const sync_pb::SyncAttachmentId& id,
+ const scoped_refptr<base::RefCountedMemory>& bytes) {
+ return scoped_ptr<SyncAttachment>(new SyncAttachment(id, bytes)).Pass();
+}
+
+const sync_pb::SyncAttachmentId& SyncAttachment::GetId() const { return id_; }
+
+const scoped_refptr<base::RefCountedMemory>& SyncAttachment::GetBytes() const {
+ return bytes_;
+}
+
+SyncAttachment::SyncAttachment(
+ const sync_pb::SyncAttachmentId& id,
+ const scoped_refptr<base::RefCountedMemory>& bytes)
+ : id_(id), bytes_(bytes) {
+ DCHECK(!id.unique_id().empty());
+ DCHECK(bytes);
+}
+
+} // namespace syncer
diff --git a/sync/api/sync_attachment.h b/sync/api/sync_attachment.h
new file mode 100644
index 0000000..26836b9
--- /dev/null
+++ b/sync/api/sync_attachment.h
@@ -0,0 +1,58 @@
+// 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_SYNC_ATTACHMENT_H_
+#define SYNC_API_SYNC_ATTACHMENT_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "sync/base/sync_export.h"
+#include "sync/protocol/sync.pb.h"
+
+namespace base {
+class RefCountedMemory;
+} // namespace base
+
+namespace syncer {
+
+// An immutable blob of in-memory data attached to a sync item.
+class SYNC_EXPORT SyncAttachment {
+ public:
+ ~SyncAttachment();
+
+ // Creates an attachment with a unique id and the supplied bytes.
+ //
+ // Used when creating a brand new attachment.
+ static scoped_ptr<SyncAttachment> Create(
+ const scoped_refptr<base::RefCountedMemory>& bytes);
+
+ // Creates an attachment with the supplied id and bytes.
+ //
+ // Used when you want to recreate a specific attachment. E.g. creating a local
+ // copy of an attachment that already exists on the sync server.
+ static scoped_ptr<SyncAttachment> CreateWithId(
+ const sync_pb::SyncAttachmentId& id,
+ const scoped_refptr<base::RefCountedMemory>& bytes);
+
+ // Returns this attachment's id.
+ const sync_pb::SyncAttachmentId& GetId() const;
+
+ // Returns this attachment's bytes.
+ const scoped_refptr<base::RefCountedMemory>& GetBytes() const;
+
+ private:
+ const sync_pb::SyncAttachmentId id_;
+ const scoped_refptr<base::RefCountedMemory> bytes_;
+
+ SyncAttachment(const sync_pb::SyncAttachmentId& id,
+ const scoped_refptr<base::RefCountedMemory>& bytes);
+
+ // Default copy ctor welcome.
+ DISALLOW_ASSIGN(SyncAttachment);
+};
+
+} // namespace syncer
+
+#endif // SYNC_API_SYNC_ATTACHMENT_H_
diff --git a/sync/api/sync_attachment_unittest.cc b/sync/api/sync_attachment_unittest.cc
new file mode 100644
index 0000000..6c4c93e
--- /dev/null
+++ b/sync/api/sync_attachment_unittest.cc
@@ -0,0 +1,54 @@
+// 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/sync_attachment.h"
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/memory/scoped_ptr.h"
+#include "sync/protocol/sync.pb.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using sync_pb::SyncAttachmentId;
+
+namespace syncer {
+
+namespace {
+
+const char kAttachmentData[] = "some data";
+
+typedef testing::Test SyncAttachmentTest;
+
+TEST_F(SyncAttachmentTest, Create_UniqueIdIsUnique) {
+ SyncAttachmentId id;
+ scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
+ bytes->data() = kAttachmentData;
+ scoped_ptr<SyncAttachment> a1 = SyncAttachment::Create(bytes);
+ scoped_ptr<SyncAttachment> a2 = SyncAttachment::Create(bytes);
+ EXPECT_NE(a1->GetId().unique_id(), a2->GetId().unique_id());
+ EXPECT_EQ(a1->GetBytes(), a2->GetBytes());
+}
+
+TEST_F(SyncAttachmentTest, Create_WithEmptyBytes) {
+ SyncAttachmentId id;
+ scoped_refptr<base::RefCountedString> emptyBytes(new base::RefCountedString);
+ scoped_ptr<SyncAttachment> a = SyncAttachment::Create(emptyBytes);
+ EXPECT_EQ(emptyBytes, a->GetBytes());
+}
+
+TEST_F(SyncAttachmentTest, CreateWithId_HappyCase) {
+ SyncAttachmentId id;
+ id.set_unique_id("3290482049832");
+ scoped_refptr<base::RefCountedString> bytes(new base::RefCountedString);
+ bytes->data() = kAttachmentData;
+ scoped_ptr<SyncAttachment> a = SyncAttachment::CreateWithId(id, bytes);
+ EXPECT_EQ(id.unique_id(), a->GetId().unique_id());
+ EXPECT_EQ(bytes, a->GetBytes());
+}
+
+} // namespace
+
+} // namespace syncer
diff --git a/sync/protocol/attachments.proto b/sync/protocol/attachments.proto
new file mode 100644
index 0000000..4dd85fd
--- /dev/null
+++ b/sync/protocol/attachments.proto
@@ -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.
+//
+// Sync protocol for attachments.
+
+// Update proto_{value,enum}_conversions{.h,.cc,_unittest.cc} if you change any
+// fields in this file.
+
+syntax = "proto2";
+
+option optimize_for = LITE_RUNTIME;
+option retain_unknown_fields = true;
+
+package sync_pb;
+
+// Identifies an attachment.
+//
+// Note, message's definition is in flux and may change. Don't rely on it.
+message SyncAttachmentId {
+ // Uniquely identifies the attachment. Two attachments with the same unique_id
+ // are considered equivalent.
+ optional string unique_id = 1;
+}
diff --git a/sync/protocol/proto_value_conversions.cc b/sync/protocol/proto_value_conversions.cc
index a7ccdf2..4b7e495 100644
--- a/sync/protocol/proto_value_conversions.cc
+++ b/sync/protocol/proto_value_conversions.cc
@@ -1024,6 +1024,13 @@ base::DictionaryValue* ClientConfigParamsToValue(
return value;
}
+base::DictionaryValue* SyncAttachmentIdToValue(
+ const sync_pb::SyncAttachmentId& proto) {
+ base::DictionaryValue* value = new base::DictionaryValue();
+ SET_STR(unique_id);
+ return value;
+}
+
#undef SET
#undef SET_REP
diff --git a/sync/protocol/proto_value_conversions.h b/sync/protocol/proto_value_conversions.h
index 9357031..3c8f3d9 100644
--- a/sync/protocol/proto_value_conversions.h
+++ b/sync/protocol/proto_value_conversions.h
@@ -60,6 +60,7 @@ class SessionSpecifics;
class SessionTab;
class SessionWindow;
class SimpleCollapsedLayout;
+class SyncAttachmentId;
class SyncCycleCompletedEventInfo;
class SyncedNotification;
class SyncedNotificationAction;
@@ -289,6 +290,9 @@ base::DictionaryValue* SyncCycleCompletedEventInfoToValue(
base::DictionaryValue* ClientConfigParamsToValue(
const sync_pb::ClientConfigParams& proto);
+SYNC_EXPORT_PRIVATE base::DictionaryValue* SyncAttachmentIdToValue(
+ const sync_pb::SyncAttachmentId& proto);
+
} // namespace syncer
#endif // SYNC_PROTOCOL_PROTO_VALUE_CONVERSIONS_H_
diff --git a/sync/protocol/proto_value_conversions_unittest.cc b/sync/protocol/proto_value_conversions_unittest.cc
index 986c7a9..11c9674 100644
--- a/sync/protocol/proto_value_conversions_unittest.cc
+++ b/sync/protocol/proto_value_conversions_unittest.cc
@@ -363,5 +363,9 @@ TEST_F(ProtoValueConversionsTest, ClientToServerResponseToValue) {
"get_updates.entries"));
}
+TEST_F(ProtoValueConversionsTest, SyncAttachmentIdToValue) {
+ TestSpecificsToValue(SyncAttachmentIdToValue);
+}
+
} // namespace
} // namespace syncer
diff --git a/sync/protocol/sync.proto b/sync/protocol/sync.proto
index 449c836..ee051cd 100644
--- a/sync/protocol/sync.proto
+++ b/sync/protocol/sync.proto
@@ -19,6 +19,7 @@ import "app_notification_specifics.proto";
import "app_setting_specifics.proto";
import "app_specifics.proto";
import "article_specifics.proto";
+import "attachments.proto";
import "autofill_specifics.proto";
import "bookmark_specifics.proto";
import "client_commands.proto";
diff --git a/sync/sync_api.gypi b/sync/sync_api.gypi
index 188fc32..4a2b21d 100644
--- a/sync/sync_api.gypi
+++ b/sync/sync_api.gypi
@@ -16,18 +16,20 @@
'api/string_ordinal.h',
'api/syncable_service.cc',
'api/syncable_service.h',
- 'api/sync_data.h',
+ 'api/sync_attachment.cc',
+ 'api/sync_attachment.h',
'api/sync_data.cc',
- 'api/sync_change.h',
+ 'api/sync_data.h',
'api/sync_change.cc',
- 'api/sync_change_processor.h',
+ 'api/sync_change.h',
'api/sync_change_processor.cc',
- 'api/sync_error.h',
+ 'api/sync_change_processor.h',
'api/sync_error.cc',
- 'api/sync_error_factory.h',
+ 'api/sync_error.h',
'api/sync_error_factory.cc',
- 'api/sync_merge_result.h',
+ 'api/sync_error_factory.h',
'api/sync_merge_result.cc',
+ 'api/sync_merge_result.h',
'api/time.h',
],
}
diff --git a/sync/sync_proto.gypi b/sync/sync_proto.gypi
index 29b80d0..5a34c7a 100644
--- a/sync/sync_proto.gypi
+++ b/sync/sync_proto.gypi
@@ -15,6 +15,7 @@
'protocol/app_specifics.proto',
'protocol/app_list_specifics.proto',
'protocol/article_specifics.proto',
+ 'protocol/attachments.proto',
'protocol/autofill_specifics.proto',
'protocol/bookmark_specifics.proto',
'protocol/client_commands.proto',
diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi
index eaa01aa..761cb29 100644
--- a/sync/sync_tests.gypi
+++ b/sync/sync_tests.gypi
@@ -417,6 +417,7 @@
'..',
],
'sources': [
+ 'api/sync_attachment_unittest.cc',
'api/sync_change_unittest.cc',
'api/sync_error_unittest.cc',
'api/sync_merge_result_unittest.cc',