Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/browser/sync/glue/generic_change_processor.cc

Issue 187303006: Update sync API to support attachments. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@attachmentapi
Patch Set: Fix enum related compile errors on mac. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/glue/generic_change_processor.h" 5 #include "chrome/browser/sync/glue/generic_change_processor.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 21 matching lines...) Expand all
32 syncer::PASSWORDS) { 32 syncer::PASSWORDS) {
33 write_node->SetPasswordSpecifics( 33 write_node->SetPasswordSpecifics(
34 entity_specifics.password().client_only_encrypted_data()); 34 entity_specifics.password().client_only_encrypted_data());
35 } else { 35 } else {
36 write_node->SetEntitySpecifics(entity_specifics); 36 write_node->SetEntitySpecifics(entity_specifics);
37 } 37 }
38 } 38 }
39 39
40 syncer::SyncData BuildRemoteSyncData( 40 syncer::SyncData BuildRemoteSyncData(
41 int64 sync_id, 41 int64 sync_id,
42 const syncer::BaseNode& read_node) { 42 const syncer::BaseNode& read_node,
43 const scoped_refptr<syncer::AttachmentServiceProxy>&
44 attachment_service_proxy) {
45 const syncer::AttachmentIdList& attachment_ids = read_node.GetAttachmentIds();
43 // Use the specifics of non-password datatypes directly (encryption has 46 // Use the specifics of non-password datatypes directly (encryption has
44 // already been handled). 47 // already been handled).
45 if (read_node.GetModelType() != syncer::PASSWORDS) { 48 if (read_node.GetModelType() != syncer::PASSWORDS) {
46 return syncer::SyncData::CreateRemoteData(sync_id, 49 return syncer::SyncData::CreateRemoteData(sync_id,
47 read_node.GetEntitySpecifics(), 50 read_node.GetEntitySpecifics(),
48 read_node.GetModificationTime()); 51 read_node.GetModificationTime(),
52 attachment_ids,
53 attachment_service_proxy);
49 } 54 }
50 55
51 // Passwords must be accessed differently, to account for their encryption, 56 // Passwords must be accessed differently, to account for their encryption,
52 // and stored into a temporary EntitySpecifics. 57 // and stored into a temporary EntitySpecifics.
53 sync_pb::EntitySpecifics password_holder; 58 sync_pb::EntitySpecifics password_holder;
54 password_holder.mutable_password()->mutable_client_only_encrypted_data()-> 59 password_holder.mutable_password()->mutable_client_only_encrypted_data()->
55 CopyFrom(read_node.GetPasswordSpecifics()); 60 CopyFrom(read_node.GetPasswordSpecifics());
56 return syncer::SyncData::CreateRemoteData(sync_id, 61 return syncer::SyncData::CreateRemoteData(sync_id,
57 password_holder, 62 password_holder,
58 read_node.GetModificationTime()); 63 read_node.GetModificationTime(),
64 attachment_ids,
65 attachment_service_proxy);
59 } 66 }
60 67
61 } // namespace 68 } // namespace
62 69
63 GenericChangeProcessor::GenericChangeProcessor( 70 GenericChangeProcessor::GenericChangeProcessor(
64 DataTypeErrorHandler* error_handler, 71 DataTypeErrorHandler* error_handler,
65 const base::WeakPtr<syncer::SyncableService>& local_service, 72 const base::WeakPtr<syncer::SyncableService>& local_service,
66 const base::WeakPtr<syncer::SyncMergeResult>& merge_result, 73 const base::WeakPtr<syncer::SyncMergeResult>& merge_result,
67 syncer::UserShare* user_share) 74 syncer::UserShare* user_share,
75 scoped_ptr<syncer::AttachmentService> attachment_service)
68 : ChangeProcessor(error_handler), 76 : ChangeProcessor(error_handler),
69 local_service_(local_service), 77 local_service_(local_service),
70 merge_result_(merge_result), 78 merge_result_(merge_result),
71 share_handle_(user_share) { 79 share_handle_(user_share),
80 attachment_service_(attachment_service.Pass()),
81 attachment_service_proxy_(new syncer::AttachmentServiceProxy(
82 base::MessageLoopProxy::current(),
83 attachment_service_->AsWeakPtr())) {
72 DCHECK(CalledOnValidThread()); 84 DCHECK(CalledOnValidThread());
85 DCHECK(attachment_service_);
86 DCHECK(attachment_service_proxy_);
73 } 87 }
74 88
75 GenericChangeProcessor::~GenericChangeProcessor() { 89 GenericChangeProcessor::~GenericChangeProcessor() {
76 DCHECK(CalledOnValidThread()); 90 DCHECK(CalledOnValidThread());
77 } 91 }
78 92
79 void GenericChangeProcessor::ApplyChangesFromSyncModel( 93 void GenericChangeProcessor::ApplyChangesFromSyncModel(
80 const syncer::BaseTransaction* trans, 94 const syncer::BaseTransaction* trans,
81 int64 model_version, 95 int64 model_version,
82 const syncer::ImmutableChangeRecordList& changes) { 96 const syncer::ImmutableChangeRecordList& changes) {
83 DCHECK(CalledOnValidThread()); 97 DCHECK(CalledOnValidThread());
84 DCHECK(syncer_changes_.empty()); 98 DCHECK(syncer_changes_.empty());
85 for (syncer::ChangeRecordList::const_iterator it = 99 for (syncer::ChangeRecordList::const_iterator it =
86 changes.Get().begin(); it != changes.Get().end(); ++it) { 100 changes.Get().begin(); it != changes.Get().end(); ++it) {
87 if (it->action == syncer::ChangeRecord::ACTION_DELETE) { 101 if (it->action == syncer::ChangeRecord::ACTION_DELETE) {
88 scoped_ptr<sync_pb::EntitySpecifics> specifics; 102 scoped_ptr<sync_pb::EntitySpecifics> specifics;
89 if (it->specifics.has_password()) { 103 if (it->specifics.has_password()) {
90 DCHECK(it->extra.get()); 104 DCHECK(it->extra.get());
91 specifics.reset(new sync_pb::EntitySpecifics(it->specifics)); 105 specifics.reset(new sync_pb::EntitySpecifics(it->specifics));
92 specifics->mutable_password()->mutable_client_only_encrypted_data()-> 106 specifics->mutable_password()->mutable_client_only_encrypted_data()->
93 CopyFrom(it->extra->unencrypted()); 107 CopyFrom(it->extra->unencrypted());
94 } 108 }
95 syncer_changes_.push_back(syncer::SyncChange( 109 const syncer::AttachmentIdList empty_list_of_attachment_ids;
96 FROM_HERE, 110 syncer_changes_.push_back(
97 syncer::SyncChange::ACTION_DELETE, 111 syncer::SyncChange(FROM_HERE,
98 syncer::SyncData::CreateRemoteData( 112 syncer::SyncChange::ACTION_DELETE,
99 it->id, specifics ? *specifics : it->specifics, base::Time()))); 113 syncer::SyncData::CreateRemoteData(
114 it->id,
115 specifics ? *specifics : it->specifics,
116 base::Time(),
117 empty_list_of_attachment_ids,
118 attachment_service_proxy_)));
100 } else { 119 } else {
101 syncer::SyncChange::SyncChangeType action = 120 syncer::SyncChange::SyncChangeType action =
102 (it->action == syncer::ChangeRecord::ACTION_ADD) ? 121 (it->action == syncer::ChangeRecord::ACTION_ADD) ?
103 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE; 122 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE;
104 // Need to load specifics from node. 123 // Need to load specifics from node.
105 syncer::ReadNode read_node(trans); 124 syncer::ReadNode read_node(trans);
106 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { 125 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) {
107 error_handler()->OnSingleDatatypeUnrecoverableError( 126 error_handler()->OnSingleDatatypeUnrecoverableError(
108 FROM_HERE, 127 FROM_HERE,
109 "Failed to look up data for received change with id " + 128 "Failed to look up data for received change with id " +
110 base::Int64ToString(it->id)); 129 base::Int64ToString(it->id));
111 return; 130 return;
112 } 131 }
113 syncer_changes_.push_back( 132 syncer_changes_.push_back(syncer::SyncChange(
114 syncer::SyncChange( 133 FROM_HERE,
115 FROM_HERE, 134 action,
116 action, 135 BuildRemoteSyncData(it->id, read_node, attachment_service_proxy_)));
117 BuildRemoteSyncData(it->id, read_node)));
118 } 136 }
119 } 137 }
120 } 138 }
121 139
122 void GenericChangeProcessor::CommitChangesFromSyncModel() { 140 void GenericChangeProcessor::CommitChangesFromSyncModel() {
123 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
124 if (syncer_changes_.empty()) 142 if (syncer_changes_.empty())
125 return; 143 return;
126 if (!local_service_.get()) { 144 if (!local_service_.get()) {
127 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType(); 145 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 syncer::ReadNode sync_child_node(&trans); 197 syncer::ReadNode sync_child_node(&trans);
180 if (sync_child_node.InitByIdLookup(*it) != 198 if (sync_child_node.InitByIdLookup(*it) !=
181 syncer::BaseNode::INIT_OK) { 199 syncer::BaseNode::INIT_OK) {
182 syncer::SyncError error(FROM_HERE, 200 syncer::SyncError error(FROM_HERE,
183 syncer::SyncError::DATATYPE_ERROR, 201 syncer::SyncError::DATATYPE_ERROR,
184 "Failed to fetch child node for type " + 202 "Failed to fetch child node for type " +
185 type_name + ".", 203 type_name + ".",
186 type); 204 type);
187 return error; 205 return error;
188 } 206 }
189 current_sync_data->push_back(BuildRemoteSyncData(sync_child_node.GetId(), 207 current_sync_data->push_back(BuildRemoteSyncData(
190 sync_child_node)); 208 sync_child_node.GetId(), sync_child_node, attachment_service_proxy_));
191 } 209 }
192 return syncer::SyncError(); 210 return syncer::SyncError();
193 } 211 }
194 212
195 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { 213 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) {
196 syncer::ReadTransaction trans(FROM_HERE, share_handle()); 214 syncer::ReadTransaction trans(FROM_HERE, share_handle());
197 syncer::ReadNode root(&trans); 215 syncer::ReadNode root(&trans);
198 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != 216 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) !=
199 syncer::BaseNode::INIT_OK) 217 syncer::BaseNode::INIT_OK)
200 return 0; 218 return 0;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 syncer::ModelType type = change.sync_data().GetDataType(); 349 syncer::ModelType type = change.sync_data().GetDataType();
332 std::string type_str = syncer::ModelTypeToString(type); 350 std::string type_str = syncer::ModelTypeToString(type);
333 syncer::WriteNode sync_node(&trans); 351 syncer::WriteNode sync_node(&trans);
334 if (change.change_type() == syncer::SyncChange::ACTION_DELETE) { 352 if (change.change_type() == syncer::SyncChange::ACTION_DELETE) {
335 syncer::SyncError error = 353 syncer::SyncError error =
336 AttemptDelete(change, type, type_str, &sync_node, error_handler()); 354 AttemptDelete(change, type, type_str, &sync_node, error_handler());
337 if (error.IsSet()) { 355 if (error.IsSet()) {
338 NOTREACHED(); 356 NOTREACHED();
339 return error; 357 return error;
340 } 358 }
359 attachment_service_->OnSyncDataDelete(change.sync_data());
341 if (merge_result_.get()) { 360 if (merge_result_.get()) {
342 merge_result_->set_num_items_deleted( 361 merge_result_->set_num_items_deleted(
343 merge_result_->num_items_deleted() + 1); 362 merge_result_->num_items_deleted() + 1);
344 } 363 }
345 } else if (change.change_type() == syncer::SyncChange::ACTION_ADD) { 364 } else if (change.change_type() == syncer::SyncChange::ACTION_ADD) {
346 syncer::SyncError error = 365 syncer::SyncError error =
347 HandleActionAdd(change, type_str, type, trans, &sync_node); 366 HandleActionAdd(change, type_str, type, trans, &sync_node);
348 if (error.IsSet()) { 367 if (error.IsSet()) {
349 return error; 368 return error;
350 } 369 }
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 error.Reset(FROM_HERE, error_prefix + "unknown error", type); 461 error.Reset(FROM_HERE, error_prefix + "unknown error", type);
443 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 462 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
444 error.message()); 463 error.message());
445 LOG(ERROR) << "Create: Unknown error."; 464 LOG(ERROR) << "Create: Unknown error.";
446 return error; 465 return error;
447 } 466 }
448 } 467 }
449 } 468 }
450 sync_node->SetTitle(base::UTF8ToWide(change.sync_data().GetTitle())); 469 sync_node->SetTitle(base::UTF8ToWide(change.sync_data().GetTitle()));
451 SetNodeSpecifics(change.sync_data().GetSpecifics(), sync_node); 470 SetNodeSpecifics(change.sync_data().GetSpecifics(), sync_node);
471 attachment_service_->OnSyncDataAdd(change.sync_data());
452 if (merge_result_.get()) { 472 if (merge_result_.get()) {
453 merge_result_->set_num_items_added(merge_result_->num_items_added() + 1); 473 merge_result_->set_num_items_added(merge_result_->num_items_added() + 1);
454 } 474 }
455 return syncer::SyncError(); 475 return syncer::SyncError();
456 } 476 }
457 // WARNING: this code is sensitive to compiler optimizations. Be careful 477 // WARNING: this code is sensitive to compiler optimizations. Be careful
458 // modifying any code around an OnSingleDatatypeUnrecoverableError call, else 478 // modifying any code around an OnSingleDatatypeUnrecoverableError call, else
459 // the compiler attempts to merge it with other calls, losing useful information 479 // the compiler attempts to merge it with other calls, losing useful information
460 // in breakpad uploads. 480 // in breakpad uploads.
461 syncer::SyncError GenericChangeProcessor::HandleActionUpdate( 481 syncer::SyncError GenericChangeProcessor::HandleActionUpdate(
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE, 563 error_handler()->OnSingleDatatypeUnrecoverableError(FROM_HERE,
544 error.message()); 564 error.message());
545 LOG(ERROR) << "Update: encr case 4."; 565 LOG(ERROR) << "Update: encr case 4.";
546 return error; 566 return error;
547 } 567 }
548 } 568 }
549 } 569 }
550 570
551 sync_node->SetTitle(base::UTF8ToWide(change.sync_data().GetTitle())); 571 sync_node->SetTitle(base::UTF8ToWide(change.sync_data().GetTitle()));
552 SetNodeSpecifics(change.sync_data().GetSpecifics(), sync_node); 572 SetNodeSpecifics(change.sync_data().GetSpecifics(), sync_node);
573 attachment_service_->OnSyncDataUpdate(sync_node->GetAttachmentIds(),
574 change.sync_data());
553 if (merge_result_.get()) { 575 if (merge_result_.get()) {
554 merge_result_->set_num_items_modified(merge_result_->num_items_modified() + 576 merge_result_->set_num_items_modified(merge_result_->num_items_modified() +
555 1); 577 1);
556 } 578 }
557 // TODO(sync): Support updating other parts of the sync node (title, 579 // TODO(sync): Support updating other parts of the sync node (title,
558 // successor, parent, etc.). 580 // successor, parent, etc.).
559 return syncer::SyncError(); 581 return syncer::SyncError();
560 } 582 }
561 583
562 bool GenericChangeProcessor::SyncModelHasUserCreatedNodes( 584 bool GenericChangeProcessor::SyncModelHasUserCreatedNodes(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 void GenericChangeProcessor::StartImpl(Profile* profile) { 618 void GenericChangeProcessor::StartImpl(Profile* profile) {
597 DCHECK(CalledOnValidThread()); 619 DCHECK(CalledOnValidThread());
598 } 620 }
599 621
600 syncer::UserShare* GenericChangeProcessor::share_handle() const { 622 syncer::UserShare* GenericChangeProcessor::share_handle() const {
601 DCHECK(CalledOnValidThread()); 623 DCHECK(CalledOnValidThread());
602 return share_handle_; 624 return share_handle_;
603 } 625 }
604 626
605 } // namespace browser_sync 627 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698