Do not update AttachmentIds after uploading attachments to sync server.

In a previous design iteration we planned to have the sync server assign
an attachments id after receiving an attachment upload. We have since
changed the design so the client is responsible for assigning the
attachment id before upload occurs.

Remove comments related to updating attachment id after upload.

Rename UpdateAttachmentIdWithServerInfo to MarkAttachmentAsOnServer.

Rename UpdateEntriesWithAttachmentId to
UpdateEntriesMarkAttachmentAsOnServer.

BUG=371522

Review URL: https://codereview.chromium.org/394293003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283670 0039d316-1c4b-4281-b951-d872f2087c98
parent 35ea7cbc
...@@ -214,7 +214,7 @@ syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext( ...@@ -214,7 +214,7 @@ syncer::SyncError GenericChangeProcessor::UpdateDataTypeContext(
void GenericChangeProcessor::OnAttachmentUploaded( void GenericChangeProcessor::OnAttachmentUploaded(
const syncer::AttachmentId& attachment_id) { const syncer::AttachmentId& attachment_id) {
syncer::WriteTransaction trans(FROM_HERE, share_handle()); syncer::WriteTransaction trans(FROM_HERE, share_handle());
trans.UpdateEntriesWithAttachmentId(attachment_id); trans.UpdateEntriesMarkAttachmentAsOnServer(attachment_id);
} }
syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError( syncer::SyncError GenericChangeProcessor::GetAllSyncDataReturnError(
......
...@@ -34,8 +34,8 @@ class SYNC_EXPORT AttachmentUploader { ...@@ -34,8 +34,8 @@ class SYNC_EXPORT AttachmentUploader {
// |callback| will be invoked when the operation has completed (successfully // |callback| will be invoked when the operation has completed (successfully
// or otherwise). // or otherwise).
// //
// |callback| will receive an UploadResult code and an updated AttachmentId // |callback| will receive an UploadResult code and the AttachmentId of the
// containing the server address of the newly uploaded attachment. // newly uploaded attachment.
virtual void UploadAttachment(const Attachment& attachment, virtual void UploadAttachment(const Attachment& attachment,
const UploadCallback& callback) = 0; const UploadCallback& callback) = 0;
}; };
......
...@@ -137,8 +137,6 @@ void AttachmentUploaderImpl::UploadState::OnURLFetchComplete( ...@@ -137,8 +137,6 @@ void AttachmentUploaderImpl::UploadState::OnURLFetchComplete(
AttachmentId attachment_id = attachment_.GetId(); AttachmentId attachment_id = attachment_.GetId();
if (source->GetResponseCode() == net::HTTP_OK) { if (source->GetResponseCode() == net::HTTP_OK) {
result = UPLOAD_SUCCESS; result = UPLOAD_SUCCESS;
// TODO(maniscalco): Update the attachment id with server address
// information before passing it to the callback (bug 371522).
} else if (source->GetResponseCode() == net::HTTP_UNAUTHORIZED) { } else if (source->GetResponseCode() == net::HTTP_UNAUTHORIZED) {
// TODO(maniscalco): One possibility is that we received a 401 because our // TODO(maniscalco): One possibility is that we received a 401 because our
// access token has expired. We should probably fetch a new access token // access token has expired. We should probably fetch a new access token
......
...@@ -187,7 +187,7 @@ class AttachmentUploaderImplTest : public testing::Test, ...@@ -187,7 +187,7 @@ class AttachmentUploaderImplTest : public testing::Test,
const AttachmentUploader::UploadCallback& upload_callback() const; const AttachmentUploader::UploadCallback& upload_callback() const;
std::vector<HttpRequest>& http_requests_received(); std::vector<HttpRequest>& http_requests_received();
std::vector<AttachmentUploader::UploadResult>& upload_results(); std::vector<AttachmentUploader::UploadResult>& upload_results();
std::vector<AttachmentId>& updated_attachment_ids(); std::vector<AttachmentId>& attachment_ids();
MockOAuth2TokenService& token_service(); MockOAuth2TokenService& token_service();
base::MessageLoopForIO& message_loop(); base::MessageLoopForIO& message_loop();
RequestHandler& request_handler(); RequestHandler& request_handler();
...@@ -195,7 +195,7 @@ class AttachmentUploaderImplTest : public testing::Test, ...@@ -195,7 +195,7 @@ class AttachmentUploaderImplTest : public testing::Test,
private: private:
// An UploadCallback invoked by AttachmentUploaderImpl. // An UploadCallback invoked by AttachmentUploaderImpl.
void UploadDone(const AttachmentUploader::UploadResult& result, void UploadDone(const AttachmentUploader::UploadResult& result,
const AttachmentId& updated_attachment_id); const AttachmentId& attachment_id);
base::MessageLoopForIO message_loop_; base::MessageLoopForIO message_loop_;
scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_;
...@@ -207,7 +207,7 @@ class AttachmentUploaderImplTest : public testing::Test, ...@@ -207,7 +207,7 @@ class AttachmentUploaderImplTest : public testing::Test,
base::Closure signal_upload_done_; base::Closure signal_upload_done_;
std::vector<HttpRequest> http_requests_received_; std::vector<HttpRequest> http_requests_received_;
std::vector<AttachmentUploader::UploadResult> upload_results_; std::vector<AttachmentUploader::UploadResult> upload_results_;
std::vector<AttachmentId> updated_attachment_ids_; std::vector<AttachmentId> attachment_ids_;
scoped_ptr<MockOAuth2TokenService> token_service_; scoped_ptr<MockOAuth2TokenService> token_service_;
// Must be last data member. // Must be last data member.
...@@ -315,8 +315,8 @@ AttachmentUploaderImplTest::upload_results() { ...@@ -315,8 +315,8 @@ AttachmentUploaderImplTest::upload_results() {
} }
std::vector<AttachmentId>& std::vector<AttachmentId>&
AttachmentUploaderImplTest::updated_attachment_ids() { AttachmentUploaderImplTest::attachment_ids() {
return updated_attachment_ids_; return attachment_ids_;
} }
MockOAuth2TokenService& AttachmentUploaderImplTest::token_service() { MockOAuth2TokenService& AttachmentUploaderImplTest::token_service() {
...@@ -333,10 +333,10 @@ RequestHandler& AttachmentUploaderImplTest::request_handler() { ...@@ -333,10 +333,10 @@ RequestHandler& AttachmentUploaderImplTest::request_handler() {
void AttachmentUploaderImplTest::UploadDone( void AttachmentUploaderImplTest::UploadDone(
const AttachmentUploader::UploadResult& result, const AttachmentUploader::UploadResult& result,
const AttachmentId& updated_attachment_id) { const AttachmentId& attachment_id) {
DCHECK(CalledOnValidThread()); DCHECK(CalledOnValidThread());
upload_results_.push_back(result); upload_results_.push_back(result);
updated_attachment_ids_.push_back(updated_attachment_id); attachment_ids_.push_back(attachment_id);
DCHECK(!signal_upload_done_.is_null()); DCHECK(!signal_upload_done_.is_null());
signal_upload_done_.Run(); signal_upload_done_.Run();
} }
...@@ -432,8 +432,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) { ...@@ -432,8 +432,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) {
// See that the done callback was invoked with the right arguments. // See that the done callback was invoked with the right arguments.
ASSERT_EQ(1U, upload_results().size()); ASSERT_EQ(1U, upload_results().size());
EXPECT_EQ(AttachmentUploader::UPLOAD_SUCCESS, upload_results()[0]); EXPECT_EQ(AttachmentUploader::UPLOAD_SUCCESS, upload_results()[0]);
ASSERT_EQ(1U, updated_attachment_ids().size()); ASSERT_EQ(1U, attachment_ids().size());
EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]); EXPECT_EQ(attachment.GetId(), attachment_ids()[0]);
// See that the HTTP server received one request. // See that the HTTP server received one request.
ASSERT_EQ(1U, http_requests_received().size()); ASSERT_EQ(1U, http_requests_received().size());
...@@ -448,10 +448,6 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) { ...@@ -448,10 +448,6 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_HappyCase) {
const std::string header_value(std::string("Bearer ") + kAccessToken); const std::string header_value(std::string("Bearer ") + kAccessToken);
EXPECT_THAT(http_request.headers, EXPECT_THAT(http_request.headers,
testing::Contains(testing::Pair(header_name, header_value))); testing::Contains(testing::Pair(header_name, header_value)));
// TODO(maniscalco): Once AttachmentUploaderImpl is capable of updating the
// AttachmentId with server address information about the attachment, add some
// checks here to verify it works properly (bug 371522).
} }
// Verify two overlapping calls to upload the same attachment result in only one // Verify two overlapping calls to upload the same attachment result in only one
...@@ -513,8 +509,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_FailToGetToken) { ...@@ -513,8 +509,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_FailToGetToken) {
// See that the done callback was invoked. // See that the done callback was invoked.
ASSERT_EQ(1U, upload_results().size()); ASSERT_EQ(1U, upload_results().size());
EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]); EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
ASSERT_EQ(1U, updated_attachment_ids().size()); ASSERT_EQ(1U, attachment_ids().size());
EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]); EXPECT_EQ(attachment.GetId(), attachment_ids()[0]);
// See that no HTTP request was received. // See that no HTTP request was received.
ASSERT_EQ(0U, http_requests_received().size()); ASSERT_EQ(0U, http_requests_received().size());
...@@ -535,8 +531,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_ServiceUnavilable) { ...@@ -535,8 +531,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_ServiceUnavilable) {
// See that the done callback was invoked. // See that the done callback was invoked.
ASSERT_EQ(1U, upload_results().size()); ASSERT_EQ(1U, upload_results().size());
EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]); EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
ASSERT_EQ(1U, updated_attachment_ids().size()); ASSERT_EQ(1U, attachment_ids().size());
EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]); EXPECT_EQ(attachment.GetId(), attachment_ids()[0]);
// See that the HTTP server received one request. // See that the HTTP server received one request.
ASSERT_EQ(1U, http_requests_received().size()); ASSERT_EQ(1U, http_requests_received().size());
...@@ -573,8 +569,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_BadToken) { ...@@ -573,8 +569,8 @@ TEST_F(AttachmentUploaderImplTest, UploadAttachment_BadToken) {
// See that the done callback was invoked. // See that the done callback was invoked.
ASSERT_EQ(1U, upload_results().size()); ASSERT_EQ(1U, upload_results().size());
EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]); EXPECT_EQ(AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR, upload_results()[0]);
ASSERT_EQ(1U, updated_attachment_ids().size()); ASSERT_EQ(1U, attachment_ids().size());
EXPECT_EQ(attachment.GetId(), updated_attachment_ids()[0]); EXPECT_EQ(attachment.GetId(), attachment_ids()[0]);
// See that the HTTP server received one request. // See that the HTTP server received one request.
ASSERT_EQ(1U, http_requests_received().size()); ASSERT_EQ(1U, http_requests_received().size());
......
...@@ -25,11 +25,9 @@ void FakeAttachmentUploader::UploadAttachment(const Attachment& attachment, ...@@ -25,11 +25,9 @@ void FakeAttachmentUploader::UploadAttachment(const Attachment& attachment,
DCHECK(!attachment.GetId().GetProto().unique_id().empty()); DCHECK(!attachment.GetId().GetProto().unique_id().empty());
UploadResult result = UPLOAD_SUCCESS; UploadResult result = UPLOAD_SUCCESS;
AttachmentId updated_id = attachment.GetId(); AttachmentId id = attachment.GetId();
// TODO(maniscalco): Update the attachment id with server address information base::MessageLoop::current()->PostTask(FROM_HERE,
// before passing it to the callback. base::Bind(callback, result, id));
base::MessageLoop::current()->PostTask(
FROM_HERE, base::Bind(callback, result, updated_id));
} }
} // namespace syncer } // namespace syncer
...@@ -52,9 +52,9 @@ class SYNC_EXPORT WriteTransaction : public BaseTransaction { ...@@ -52,9 +52,9 @@ class SYNC_EXPORT WriteTransaction : public BaseTransaction {
syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status, syncer::SyncChangeProcessor::ContextRefreshStatus refresh_status,
const std::string& context); const std::string& context);
// Attachment id was just updated. Propagate this change to all entries that // Update all entries that refer to |attachment_id| indicating that
// refer this attachment id and set is_on_server for corresponding records. // |attachment_id| has been uploaded to the sync server.
void UpdateEntriesWithAttachmentId(const AttachmentId& attachment_id); void UpdateEntriesMarkAttachmentAsOnServer(const AttachmentId& attachment_id);
protected: protected:
WriteTransaction() {} WriteTransaction() {}
......
...@@ -81,7 +81,7 @@ void WriteTransaction::SetDataTypeContext( ...@@ -81,7 +81,7 @@ void WriteTransaction::SetDataTypeContext(
// See crbug.com/360280 // See crbug.com/360280
} }
void WriteTransaction::UpdateEntriesWithAttachmentId( void WriteTransaction::UpdateEntriesMarkAttachmentAsOnServer(
const AttachmentId& attachment_id) { const AttachmentId& attachment_id) {
syncable::Directory::Metahandles handles; syncable::Directory::Metahandles handles;
GetDirectory()->GetMetahandlesByAttachmentId( GetDirectory()->GetMetahandlesByAttachmentId(
...@@ -90,7 +90,7 @@ void WriteTransaction::UpdateEntriesWithAttachmentId( ...@@ -90,7 +90,7 @@ void WriteTransaction::UpdateEntriesWithAttachmentId(
iter != handles.end(); iter != handles.end();
++iter) { ++iter) {
syncable::MutableEntry entry(transaction_, syncable::GET_BY_HANDLE, *iter); syncable::MutableEntry entry(transaction_, syncable::GET_BY_HANDLE, *iter);
entry.UpdateAttachmentIdWithServerInfo(attachment_id.GetProto()); entry.MarkAttachmentAsOnServer(attachment_id.GetProto());
} }
} }
......
...@@ -1649,8 +1649,7 @@ TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) { ...@@ -1649,8 +1649,7 @@ TEST_F(SyncableDirectoryTest, MutableEntry_UpdateAttachmentId) {
ASSERT_FALSE(entry_metadata.record(1).is_on_server()); ASSERT_FALSE(entry_metadata.record(1).is_on_server());
ASSERT_FALSE(entry.GetIsUnsynced()); ASSERT_FALSE(entry.GetIsUnsynced());
// TODO(pavely): When we add server info to proto, add test for it here. entry.MarkAttachmentAsOnServer(attachment_id_proto);
entry.UpdateAttachmentIdWithServerInfo(attachment_id_proto);
ASSERT_TRUE(entry_metadata.record(0).is_on_server()); ASSERT_TRUE(entry_metadata.record(0).is_on_server());
ASSERT_FALSE(entry_metadata.record(1).is_on_server()); ASSERT_FALSE(entry_metadata.record(1).is_on_server());
......
...@@ -246,19 +246,18 @@ void MutableEntry::PutAttachmentMetadata( ...@@ -246,19 +246,18 @@ void MutableEntry::PutAttachmentMetadata(
} }
} }
void MutableEntry::UpdateAttachmentIdWithServerInfo( void MutableEntry::MarkAttachmentAsOnServer(
const sync_pb::AttachmentIdProto& updated_attachment_id) { const sync_pb::AttachmentIdProto& attachment_id) {
DCHECK(kernel_); DCHECK(kernel_);
DCHECK(!updated_attachment_id.unique_id().empty()); DCHECK(!attachment_id.unique_id().empty());
write_transaction()->TrackChangesTo(kernel_); write_transaction()->TrackChangesTo(kernel_);
sync_pb::AttachmentMetadata& attachment_metadata = sync_pb::AttachmentMetadata& attachment_metadata =
kernel_->mutable_ref(ATTACHMENT_METADATA); kernel_->mutable_ref(ATTACHMENT_METADATA);
for (int i = 0; i < attachment_metadata.record_size(); ++i) { for (int i = 0; i < attachment_metadata.record_size(); ++i) {
sync_pb::AttachmentMetadataRecord* record = sync_pb::AttachmentMetadataRecord* record =
attachment_metadata.mutable_record(i); attachment_metadata.mutable_record(i);
if (record->id().unique_id() != updated_attachment_id.unique_id()) if (record->id().unique_id() != attachment_id.unique_id())
continue; continue;
*record->mutable_id() = updated_attachment_id;
record->set_is_on_server(true); record->set_is_on_server(true);
} }
kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles); kernel_->mark_dirty(&dir()->kernel_->dirty_metahandles);
......
...@@ -62,11 +62,10 @@ class SYNC_EXPORT_PRIVATE MutableEntry : public ModelNeutralMutableEntry { ...@@ -62,11 +62,10 @@ class SYNC_EXPORT_PRIVATE MutableEntry : public ModelNeutralMutableEntry {
void PutAttachmentMetadata( void PutAttachmentMetadata(
const sync_pb::AttachmentMetadata& attachment_metadata); const sync_pb::AttachmentMetadata& attachment_metadata);
// Update attachment metadata, replace all records matching attachment id's // Update attachment metadata for |attachment_id| to indicate that this
// unique id with updated attachment id that contains server info. // attachment has been uploaded to the sync server.
// Set is_in_server for corresponding records. void MarkAttachmentAsOnServer(
void UpdateAttachmentIdWithServerInfo( const sync_pb::AttachmentIdProto& attachment_id);
const sync_pb::AttachmentIdProto& updated_attachment_id);
private: private:
// Kind of redundant. We should reduce the number of pointers // Kind of redundant. We should reduce the number of pointers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment