OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sync_driver/generic_change_processor.h" | 5 #include "components/sync_driver/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 "components/sync_driver/sync_api_component_factory.h" | 10 #include "components/sync_driver/sync_api_component_factory.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 attachment_service_proxy); | 85 attachment_service_proxy); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 GenericChangeProcessor::GenericChangeProcessor( | 90 GenericChangeProcessor::GenericChangeProcessor( |
91 DataTypeErrorHandler* error_handler, | 91 DataTypeErrorHandler* error_handler, |
92 const base::WeakPtr<syncer::SyncableService>& local_service, | 92 const base::WeakPtr<syncer::SyncableService>& local_service, |
93 const base::WeakPtr<syncer::SyncMergeResult>& merge_result, | 93 const base::WeakPtr<syncer::SyncMergeResult>& merge_result, |
94 syncer::UserShare* user_share, | 94 syncer::UserShare* user_share, |
95 SyncApiComponentFactory* sync_factory) | 95 SyncApiComponentFactory* sync_factory, |
96 const scoped_refptr<syncer::AttachmentStore>& attachment_store) | |
96 : ChangeProcessor(error_handler), | 97 : ChangeProcessor(error_handler), |
97 local_service_(local_service), | 98 local_service_(local_service), |
98 merge_result_(merge_result), | 99 merge_result_(merge_result), |
99 share_handle_(user_share), | 100 share_handle_(user_share) { |
100 attachment_service_( | |
101 sync_factory->CreateAttachmentService(*user_share, this)), | |
102 attachment_service_weak_ptr_factory_(attachment_service_.get()), | |
103 attachment_service_proxy_( | |
104 base::MessageLoopProxy::current(), | |
105 attachment_service_weak_ptr_factory_.GetWeakPtr()) { | |
106 DCHECK(CalledOnValidThread()); | 101 DCHECK(CalledOnValidThread()); |
107 DCHECK(attachment_service_); | 102 if (attachment_store) { |
maniscalco
2014/09/08 21:56:35
I thought scoped_refptr no longer automatically co
pavely
2014/09/09 23:52:30
Done.
| |
103 attachment_service_ = sync_factory->CreateAttachmentService( | |
104 attachment_store, *user_share, this); | |
105 attachment_service_weak_ptr_factory_.reset( | |
106 new base::WeakPtrFactory<syncer::AttachmentService>( | |
107 attachment_service_.get())); | |
108 attachment_service_proxy_.reset(new syncer::AttachmentServiceProxy( | |
109 base::MessageLoopProxy::current(), | |
110 attachment_service_weak_ptr_factory_->GetWeakPtr())); | |
111 } else { | |
112 attachment_service_proxy_.reset(new syncer::AttachmentServiceProxy( | |
113 base::MessageLoopProxy::current(), | |
114 base::WeakPtr<syncer::AttachmentService>())); | |
115 } | |
108 } | 116 } |
109 | 117 |
110 GenericChangeProcessor::~GenericChangeProcessor() { | 118 GenericChangeProcessor::~GenericChangeProcessor() { |
111 DCHECK(CalledOnValidThread()); | 119 DCHECK(CalledOnValidThread()); |
112 } | 120 } |
113 | 121 |
114 void GenericChangeProcessor::ApplyChangesFromSyncModel( | 122 void GenericChangeProcessor::ApplyChangesFromSyncModel( |
115 const syncer::BaseTransaction* trans, | 123 const syncer::BaseTransaction* trans, |
116 int64 model_version, | 124 int64 model_version, |
117 const syncer::ImmutableChangeRecordList& changes) { | 125 const syncer::ImmutableChangeRecordList& changes) { |
(...skipping 11 matching lines...) Expand all Loading... | |
129 } | 137 } |
130 const syncer::AttachmentIdList empty_list_of_attachment_ids; | 138 const syncer::AttachmentIdList empty_list_of_attachment_ids; |
131 syncer_changes_.push_back( | 139 syncer_changes_.push_back( |
132 syncer::SyncChange(FROM_HERE, | 140 syncer::SyncChange(FROM_HERE, |
133 syncer::SyncChange::ACTION_DELETE, | 141 syncer::SyncChange::ACTION_DELETE, |
134 syncer::SyncData::CreateRemoteData( | 142 syncer::SyncData::CreateRemoteData( |
135 it->id, | 143 it->id, |
136 specifics ? *specifics : it->specifics, | 144 specifics ? *specifics : it->specifics, |
137 base::Time(), | 145 base::Time(), |
138 empty_list_of_attachment_ids, | 146 empty_list_of_attachment_ids, |
139 attachment_service_proxy_))); | 147 *attachment_service_proxy_))); |
140 } else { | 148 } else { |
141 syncer::SyncChange::SyncChangeType action = | 149 syncer::SyncChange::SyncChangeType action = |
142 (it->action == syncer::ChangeRecord::ACTION_ADD) ? | 150 (it->action == syncer::ChangeRecord::ACTION_ADD) ? |
143 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE; | 151 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE; |
144 // Need to load specifics from node. | 152 // Need to load specifics from node. |
145 syncer::ReadNode read_node(trans); | 153 syncer::ReadNode read_node(trans); |
146 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { | 154 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { |
147 syncer::SyncError error( | 155 syncer::SyncError error( |
148 FROM_HERE, | 156 FROM_HERE, |
149 syncer::SyncError::DATATYPE_ERROR, | 157 syncer::SyncError::DATATYPE_ERROR, |
150 "Failed to look up data for received change with id " + | 158 "Failed to look up data for received change with id " + |
151 base::Int64ToString(it->id), | 159 base::Int64ToString(it->id), |
152 syncer::GetModelTypeFromSpecifics(it->specifics)); | 160 syncer::GetModelTypeFromSpecifics(it->specifics)); |
153 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 161 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
154 return; | 162 return; |
155 } | 163 } |
156 syncer_changes_.push_back(syncer::SyncChange( | 164 syncer_changes_.push_back(syncer::SyncChange( |
157 FROM_HERE, | 165 FROM_HERE, |
158 action, | 166 action, |
159 BuildRemoteSyncData(it->id, read_node, attachment_service_proxy_))); | 167 BuildRemoteSyncData(it->id, read_node, *attachment_service_proxy_))); |
160 } | 168 } |
161 } | 169 } |
162 } | 170 } |
163 | 171 |
164 void GenericChangeProcessor::CommitChangesFromSyncModel() { | 172 void GenericChangeProcessor::CommitChangesFromSyncModel() { |
165 DCHECK(CalledOnValidThread()); | 173 DCHECK(CalledOnValidThread()); |
166 if (syncer_changes_.empty()) | 174 if (syncer_changes_.empty()) |
167 return; | 175 return; |
168 if (!local_service_.get()) { | 176 if (!local_service_.get()) { |
169 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType(); | 177 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 if (sync_child_node.InitByIdLookup(*it) != | 254 if (sync_child_node.InitByIdLookup(*it) != |
247 syncer::BaseNode::INIT_OK) { | 255 syncer::BaseNode::INIT_OK) { |
248 syncer::SyncError error(FROM_HERE, | 256 syncer::SyncError error(FROM_HERE, |
249 syncer::SyncError::DATATYPE_ERROR, | 257 syncer::SyncError::DATATYPE_ERROR, |
250 "Failed to fetch child node for type " + | 258 "Failed to fetch child node for type " + |
251 type_name + ".", | 259 type_name + ".", |
252 type); | 260 type); |
253 return error; | 261 return error; |
254 } | 262 } |
255 current_sync_data->push_back(BuildRemoteSyncData( | 263 current_sync_data->push_back(BuildRemoteSyncData( |
256 sync_child_node.GetId(), sync_child_node, attachment_service_proxy_)); | 264 sync_child_node.GetId(), sync_child_node, *attachment_service_proxy_)); |
257 } | 265 } |
258 return syncer::SyncError(); | 266 return syncer::SyncError(); |
259 } | 267 } |
260 | 268 |
261 bool GenericChangeProcessor::GetDataTypeContext(syncer::ModelType type, | 269 bool GenericChangeProcessor::GetDataTypeContext(syncer::ModelType type, |
262 std::string* context) const { | 270 std::string* context) const { |
263 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 271 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
264 sync_pb::DataTypeContext context_proto; | 272 sync_pb::DataTypeContext context_proto; |
265 trans.GetDataTypeContext(type, &context_proto); | 273 trans.GetDataTypeContext(type, &context_proto); |
266 if (!context_proto.has_context()) | 274 if (!context_proto.has_context()) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
458 change.location().ToString(), | 466 change.location().ToString(), |
459 type); | 467 type); |
460 error_handler()->OnSingleDataTypeUnrecoverableError(error); | 468 error_handler()->OnSingleDataTypeUnrecoverableError(error); |
461 NOTREACHED(); | 469 NOTREACHED(); |
462 LOG(ERROR) << "Unset sync change."; | 470 LOG(ERROR) << "Unset sync change."; |
463 return error; | 471 return error; |
464 } | 472 } |
465 } | 473 } |
466 | 474 |
467 if (!new_attachments.empty()) { | 475 if (!new_attachments.empty()) { |
468 StoreAttachments(attachment_service_.get(), new_attachments); | 476 StoreAttachments(attachment_service_.get(), new_attachments); |
maniscalco
2014/09/08 21:56:35
If we get to this point and attachment_service_ is
pavely
2014/09/09 23:52:30
Done.
| |
469 } | 477 } |
470 | 478 |
471 return syncer::SyncError(); | 479 return syncer::SyncError(); |
472 } | 480 } |
473 | 481 |
474 // WARNING: this code is sensitive to compiler optimizations. Be careful | 482 // WARNING: this code is sensitive to compiler optimizations. Be careful |
475 // modifying any code around an OnSingleDataTypeUnrecoverableError call, else | 483 // modifying any code around an OnSingleDataTypeUnrecoverableError call, else |
476 // the compiler attempts to merge it with other calls, losing useful information | 484 // the compiler attempts to merge it with other calls, losing useful information |
477 // in breakpad uploads. | 485 // in breakpad uploads. |
478 syncer::SyncError GenericChangeProcessor::HandleActionAdd( | 486 syncer::SyncError GenericChangeProcessor::HandleActionAdd( |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 | 713 |
706 void GenericChangeProcessor::StartImpl() { | 714 void GenericChangeProcessor::StartImpl() { |
707 } | 715 } |
708 | 716 |
709 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 717 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
710 DCHECK(CalledOnValidThread()); | 718 DCHECK(CalledOnValidThread()); |
711 return share_handle_; | 719 return share_handle_; |
712 } | 720 } |
713 | 721 |
714 } // namespace sync_driver | 722 } // namespace sync_driver |
OLD | NEW |