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

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

Issue 7497014: Revert 94128 - [Sync] Refactor sync datatype error handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/tracked.h" 7 #include "base/tracked.h"
8 #include "chrome/browser/sync/api/syncable_service.h" 8 #include "chrome/browser/sync/api/syncable_service.h"
9 #include "chrome/browser/sync/api/sync_change.h" 9 #include "chrome/browser/sync/api/sync_change.h"
10 #include "chrome/browser/sync/api/sync_error.h"
11 #include "chrome/browser/sync/engine/syncapi.h" 10 #include "chrome/browser/sync/engine/syncapi.h"
12 #include "chrome/browser/sync/syncable/nigori_util.h" 11 #include "chrome/browser/sync/syncable/nigori_util.h"
13 12
14 namespace browser_sync { 13 namespace browser_sync {
15 14
16 GenericChangeProcessor::GenericChangeProcessor( 15 GenericChangeProcessor::GenericChangeProcessor(
17 SyncableService* local_service, 16 SyncableService* local_service,
18 UnrecoverableErrorHandler* error_handler, 17 UnrecoverableErrorHandler* error_handler,
19 sync_api::UserShare* user_share) 18 sync_api::UserShare* user_share)
20 : ChangeProcessor(error_handler), 19 : ChangeProcessor(error_handler),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 SyncChange(action, SyncData::CreateRemoteData(*specifics))); 62 SyncChange(action, SyncData::CreateRemoteData(*specifics)));
64 } 63 }
65 } 64 }
66 } 65 }
67 66
68 void GenericChangeProcessor::CommitChangesFromSyncModel() { 67 void GenericChangeProcessor::CommitChangesFromSyncModel() {
69 if (!running()) 68 if (!running())
70 return; 69 return;
71 if (syncer_changes_.empty()) 70 if (syncer_changes_.empty())
72 return; 71 return;
73 SyncError error = local_service_->ProcessSyncChanges(FROM_HERE, 72 local_service_->ProcessSyncChanges(FROM_HERE, syncer_changes_);
74 syncer_changes_);
75 syncer_changes_.clear(); 73 syncer_changes_.clear();
76 if (error.IsSet()) {
77 error_handler()->OnUnrecoverableError(error.location(), error.message());
78 }
79 } 74 }
80 75
81 SyncError GenericChangeProcessor::GetSyncDataForType( 76 bool GenericChangeProcessor::GetSyncDataForType(
82 syncable::ModelType type, 77 syncable::ModelType type,
83 SyncDataList* current_sync_data) { 78 SyncDataList* current_sync_data) {
84 std::string type_name = syncable::ModelTypeToString(type); 79 std::string type_name = syncable::ModelTypeToString(type);
85 sync_api::ReadTransaction trans(FROM_HERE, share_handle()); 80 sync_api::ReadTransaction trans(FROM_HERE, share_handle());
86 sync_api::ReadNode root(&trans); 81 sync_api::ReadNode root(&trans);
87 if (!root.InitByTagLookup(syncable::ModelTypeToRootTag(type))) { 82 if (!root.InitByTagLookup(syncable::ModelTypeToRootTag(type))) {
88 SyncError error(FROM_HERE, 83 LOG(ERROR) << "Server did not create the top-level " + type_name + " node."
89 "Server did not create the top-level " + type_name + 84 << " We might be running against an out-of-date server.";
90 " node. We might be running against an out-of-date server.", 85 return false;
91 type);
92 return error;
93 } 86 }
94 87
95 int64 sync_child_id = root.GetFirstChildId(); 88 int64 sync_child_id = root.GetFirstChildId();
96 while (sync_child_id != sync_api::kInvalidId) { 89 while (sync_child_id != sync_api::kInvalidId) {
97 sync_api::ReadNode sync_child_node(&trans); 90 sync_api::ReadNode sync_child_node(&trans);
98 if (!sync_child_node.InitByIdLookup(sync_child_id)) { 91 if (!sync_child_node.InitByIdLookup(sync_child_id)) {
99 SyncError error(FROM_HERE, 92 LOG(ERROR) << "Failed to fetch child node for type " + type_name + ".";
100 "Failed to fetch child node for type " + type_name + ".", 93 return false;
101 type);
102 return error;
103 } 94 }
104 current_sync_data->push_back(SyncData::CreateRemoteData( 95 current_sync_data->push_back(SyncData::CreateRemoteData(
105 sync_child_node.GetEntitySpecifics())); 96 sync_child_node.GetEntitySpecifics()));
106 sync_child_id = sync_child_node.GetSuccessorId(); 97 sync_child_id = sync_child_node.GetSuccessorId();
107 } 98 }
108 return SyncError(); 99 return true;
109 } 100 }
110 101
111 SyncError GenericChangeProcessor::ProcessSyncChanges( 102 void GenericChangeProcessor::ProcessSyncChanges(
112 const tracked_objects::Location& from_here, 103 const tracked_objects::Location& from_here,
113 const SyncChangeList& list_of_changes) { 104 const SyncChangeList& list_of_changes) {
114 sync_api::WriteTransaction trans(from_here, share_handle()); 105 sync_api::WriteTransaction trans(from_here, share_handle());
115 106
116 for (SyncChangeList::const_iterator iter = list_of_changes.begin(); 107 for (SyncChangeList::const_iterator iter = list_of_changes.begin();
117 iter != list_of_changes.end(); 108 iter != list_of_changes.end();
118 ++iter) { 109 ++iter) {
119 const SyncChange& change = *iter; 110 const SyncChange& change = *iter;
120 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED); 111 DCHECK_NE(change.sync_data().GetDataType(), syncable::UNSPECIFIED);
121 syncable::ModelType type = change.sync_data().GetDataType(); 112 std::string type_str = syncable::ModelTypeToString(
122 std::string type_str = syncable::ModelTypeToString(type); 113 change.sync_data().GetDataType());
123 sync_api::WriteNode sync_node(&trans); 114 sync_api::WriteNode sync_node(&trans);
124 if (change.change_type() == SyncChange::ACTION_DELETE) { 115 if (change.change_type() == SyncChange::ACTION_DELETE) {
125 if (change.sync_data().GetTag() == "" || 116 if (change.sync_data().GetTag() == "" ||
126 !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), 117 !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(),
127 change.sync_data().GetTag())) { 118 change.sync_data().GetTag())) {
128 NOTREACHED(); 119 NOTREACHED();
129 SyncError error(FROM_HERE, 120 error_handler()->OnUnrecoverableError(FROM_HERE,
130 "Failed to delete " + type_str + " node.", 121 "Failed to delete " + type_str + " node.");
131 type); 122 return;
132 error_handler()->OnUnrecoverableError(error.location(),
133 error.message());
134 return error;
135 } 123 }
136 sync_node.Remove(); 124 sync_node.Remove();
137 } else if (change.change_type() == SyncChange::ACTION_ADD) { 125 } else if (change.change_type() == SyncChange::ACTION_ADD) {
138 // TODO(sync): Handle other types of creation (custom parents, folders, 126 // TODO(sync): Handle other types of creation (custom parents, folders,
139 // etc.). 127 // etc.).
140 sync_api::ReadNode root_node(&trans); 128 sync_api::ReadNode root_node(&trans);
141 if (!root_node.InitByTagLookup( 129 if (!root_node.InitByTagLookup(
142 syncable::ModelTypeToRootTag(change.sync_data().GetDataType()))) { 130 syncable::ModelTypeToRootTag(change.sync_data().GetDataType()))) {
143 NOTREACHED(); 131 NOTREACHED();
144 SyncError error(FROM_HERE, 132 error_handler()->OnUnrecoverableError(FROM_HERE,
145 "Failed to look up root node for type " + type_str, 133 "Failed to look up root node for type " + type_str);
146 type); 134 return;
147 error_handler()->OnUnrecoverableError(error.location(),
148 error.message());
149 return error;
150 } 135 }
151 if (!sync_node.InitUniqueByCreation(change.sync_data().GetDataType(), 136 if (!sync_node.InitUniqueByCreation(change.sync_data().GetDataType(),
152 root_node, 137 root_node,
153 change.sync_data().GetTag())) { 138 change.sync_data().GetTag())) {
154 NOTREACHED(); 139 error_handler()->OnUnrecoverableError(FROM_HERE,
155 SyncError error(FROM_HERE, 140 "Failed to create " + type_str + " node.");
156 "Failed to create " + type_str + " node.", 141 return;
157 type);
158 error_handler()->OnUnrecoverableError(error.location(),
159 error.message());
160 return error;
161 } 142 }
162 sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle())); 143 sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle()));
163 sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics()); 144 sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics());
164 } else if (change.change_type() == SyncChange::ACTION_UPDATE) { 145 } else if (change.change_type() == SyncChange::ACTION_UPDATE) {
165 if (change.sync_data().GetTag() == "" || 146 if (change.sync_data().GetTag() == "" ||
166 !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(), 147 !sync_node.InitByClientTagLookup(change.sync_data().GetDataType(),
167 change.sync_data().GetTag())) { 148 change.sync_data().GetTag())) {
168 NOTREACHED(); 149 NOTREACHED();
169 SyncError error(FROM_HERE, 150 error_handler()->OnUnrecoverableError(FROM_HERE,
170 "Failed to update " + type_str + " node.", 151 "Failed to update " + type_str + " node");
171 type); 152 return;
172 error_handler()->OnUnrecoverableError(error.location(),
173 error.message());
174 return error;
175 } 153 }
176 sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle())); 154 sync_node.SetTitle(UTF8ToWide(change.sync_data().GetTitle()));
177 sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics()); 155 sync_node.SetEntitySpecifics(change.sync_data().GetSpecifics());
178 // TODO(sync): Support updating other parts of the sync node (title, 156 // TODO(sync): Support updating other parts of the sync node (title,
179 // successor, parent, etc.). 157 // successor, parent, etc.).
180 } else { 158 } else {
181 NOTREACHED(); 159 NOTREACHED();
182 SyncError error(FROM_HERE, 160 error_handler()->OnUnrecoverableError(FROM_HERE,
183 "Received unset SyncChange in the change processor.", 161 "Received unset SyncChange in the change processor.");
184 type); 162 return;
185 error_handler()->OnUnrecoverableError(error.location(),
186 error.message());
187 return error;
188 } 163 }
189 } 164 }
190 return SyncError();
191 } 165 }
192 166
193 bool GenericChangeProcessor::SyncModelHasUserCreatedNodes( 167 bool GenericChangeProcessor::SyncModelHasUserCreatedNodes(
194 syncable::ModelType type, 168 syncable::ModelType type,
195 bool* has_nodes) { 169 bool* has_nodes) {
196 DCHECK(has_nodes); 170 DCHECK(has_nodes);
197 DCHECK_NE(type, syncable::UNSPECIFIED); 171 DCHECK_NE(type, syncable::UNSPECIFIED);
198 std::string type_name = syncable::ModelTypeToString(type); 172 std::string type_name = syncable::ModelTypeToString(type);
199 std::string err_str = "Server did not create the top-level " + type_name + 173 std::string err_str = "Server did not create the top-level " + type_name +
200 " node. We might be running against an out-of-date server."; 174 " node. We might be running against an out-of-date server.";
(...skipping 23 matching lines...) Expand all
224 198
225 void GenericChangeProcessor::StartImpl(Profile* profile) {} 199 void GenericChangeProcessor::StartImpl(Profile* profile) {}
226 200
227 void GenericChangeProcessor::StopImpl() {} 201 void GenericChangeProcessor::StopImpl() {}
228 202
229 sync_api::UserShare* GenericChangeProcessor::share_handle() { 203 sync_api::UserShare* GenericChangeProcessor::share_handle() {
230 return user_share_; 204 return user_share_;
231 } 205 }
232 206
233 } // namespace browser_sync 207 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/generic_change_processor.h ('k') | chrome/browser/sync/glue/model_associator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698