OLD | NEW |
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/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 const syncer::ImmutableChangeRecordList& changes) { | 46 const syncer::ImmutableChangeRecordList& changes) { |
47 DCHECK(CalledOnValidThread()); | 47 DCHECK(CalledOnValidThread()); |
48 DCHECK(syncer_changes_.empty()); | 48 DCHECK(syncer_changes_.empty()); |
49 for (syncer::ChangeRecordList::const_iterator it = | 49 for (syncer::ChangeRecordList::const_iterator it = |
50 changes.Get().begin(); it != changes.Get().end(); ++it) { | 50 changes.Get().begin(); it != changes.Get().end(); ++it) { |
51 if (it->action == syncer::ChangeRecord::ACTION_DELETE) { | 51 if (it->action == syncer::ChangeRecord::ACTION_DELETE) { |
52 syncer_changes_.push_back( | 52 syncer_changes_.push_back( |
53 syncer::SyncChange( | 53 syncer::SyncChange( |
54 FROM_HERE, | 54 FROM_HERE, |
55 syncer::SyncChange::ACTION_DELETE, | 55 syncer::SyncChange::ACTION_DELETE, |
56 syncer::SyncData::CreateRemoteData(it->id, it->specifics))); | 56 syncer::SyncData::CreateRemoteData(it->id, it->specifics, |
| 57 false))); |
57 } else { | 58 } else { |
58 syncer::SyncChange::SyncChangeType action = | 59 syncer::SyncChange::SyncChangeType action = |
59 (it->action == syncer::ChangeRecord::ACTION_ADD) ? | 60 (it->action == syncer::ChangeRecord::ACTION_ADD) ? |
60 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE; | 61 syncer::SyncChange::ACTION_ADD : syncer::SyncChange::ACTION_UPDATE; |
61 // Need to load specifics from node. | 62 // Need to load specifics from node. |
62 syncer::ReadNode read_node(trans); | 63 syncer::ReadNode read_node(trans); |
63 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { | 64 if (read_node.InitByIdLookup(it->id) != syncer::BaseNode::INIT_OK) { |
64 error_handler()->OnSingleDatatypeUnrecoverableError( | 65 error_handler()->OnSingleDatatypeUnrecoverableError( |
65 FROM_HERE, | 66 FROM_HERE, |
66 "Failed to look up data for received change with id " + | 67 "Failed to look up data for received change with id " + |
67 base::Int64ToString(it->id)); | 68 base::Int64ToString(it->id)); |
68 return; | 69 return; |
69 } | 70 } |
70 syncer_changes_.push_back( | 71 syncer_changes_.push_back( |
71 syncer::SyncChange( | 72 syncer::SyncChange( |
72 FROM_HERE, | 73 FROM_HERE, |
73 action, | 74 action, |
74 syncer::SyncData::CreateRemoteData( | 75 syncer::SyncData::CreateRemoteData( |
75 it->id, read_node.GetEntitySpecifics()))); | 76 it->id, read_node.GetEntitySpecifics(), |
| 77 read_node.GetIsFolder()))); |
76 } | 78 } |
77 } | 79 } |
78 } | 80 } |
79 | 81 |
80 void GenericChangeProcessor::CommitChangesFromSyncModel() { | 82 void GenericChangeProcessor::CommitChangesFromSyncModel() { |
81 DCHECK(CalledOnValidThread()); | 83 DCHECK(CalledOnValidThread()); |
82 if (syncer_changes_.empty()) | 84 if (syncer_changes_.empty()) |
83 return; | 85 return; |
84 if (!local_service_) { | 86 if (!local_service_) { |
85 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType(); | 87 syncer::ModelType type = syncer_changes_[0].sync_data().GetDataType(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 while (sync_child_id != syncer::kInvalidId) { | 122 while (sync_child_id != syncer::kInvalidId) { |
121 syncer::ReadNode sync_child_node(&trans); | 123 syncer::ReadNode sync_child_node(&trans); |
122 if (sync_child_node.InitByIdLookup(sync_child_id) != | 124 if (sync_child_node.InitByIdLookup(sync_child_id) != |
123 syncer::BaseNode::INIT_OK) { | 125 syncer::BaseNode::INIT_OK) { |
124 syncer::SyncError error(FROM_HERE, | 126 syncer::SyncError error(FROM_HERE, |
125 "Failed to fetch child node for type " + type_name + ".", | 127 "Failed to fetch child node for type " + type_name + ".", |
126 type); | 128 type); |
127 return error; | 129 return error; |
128 } | 130 } |
129 current_sync_data->push_back(syncer::SyncData::CreateRemoteData( | 131 current_sync_data->push_back(syncer::SyncData::CreateRemoteData( |
130 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics())); | 132 sync_child_node.GetId(), sync_child_node.GetEntitySpecifics(), |
| 133 sync_child_node.GetIsFolder())); |
131 sync_child_id = sync_child_node.GetSuccessorId(); | 134 sync_child_id = sync_child_node.GetSuccessorId(); |
132 } | 135 } |
133 return syncer::SyncError(); | 136 return syncer::SyncError(); |
134 } | 137 } |
135 | 138 |
136 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { | 139 int GenericChangeProcessor::GetSyncCountForType(syncer::ModelType type) { |
137 syncer::ReadTransaction trans(FROM_HERE, share_handle()); | 140 syncer::ReadTransaction trans(FROM_HERE, share_handle()); |
138 syncer::ReadNode root(&trans); | 141 syncer::ReadNode root(&trans); |
139 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != | 142 if (root.InitByTagLookup(syncer::ModelTypeToRootTag(type)) != |
140 syncer::BaseNode::INIT_OK) | 143 syncer::BaseNode::INIT_OK) |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 void GenericChangeProcessor::StartImpl(Profile* profile) { | 509 void GenericChangeProcessor::StartImpl(Profile* profile) { |
507 DCHECK(CalledOnValidThread()); | 510 DCHECK(CalledOnValidThread()); |
508 } | 511 } |
509 | 512 |
510 syncer::UserShare* GenericChangeProcessor::share_handle() const { | 513 syncer::UserShare* GenericChangeProcessor::share_handle() const { |
511 DCHECK(CalledOnValidThread()); | 514 DCHECK(CalledOnValidThread()); |
512 return share_handle_; | 515 return share_handle_; |
513 } | 516 } |
514 | 517 |
515 } // namespace browser_sync | 518 } // namespace browser_sync |
OLD | NEW |