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

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 23441042: Refactor common invalidation framework types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move DEPS rule Created 7 years, 2 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) 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 "sync/internal_api/sync_manager_impl.h" 5 #include "sync/internal_api/sync_manager_impl.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 js_message_handlers_[name] = 998 js_message_handlers_[name] =
999 base::Bind(unbound_message_handler, base::Unretained(this)); 999 base::Bind(unbound_message_handler, base::Unretained(this));
1000 } 1000 }
1001 1001
1002 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue( 1002 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue(
1003 const NotificationInfoMap& notification_info) { 1003 const NotificationInfoMap& notification_info) {
1004 base::DictionaryValue* value = new base::DictionaryValue(); 1004 base::DictionaryValue* value = new base::DictionaryValue();
1005 1005
1006 for (NotificationInfoMap::const_iterator it = notification_info.begin(); 1006 for (NotificationInfoMap::const_iterator it = notification_info.begin();
1007 it != notification_info.end(); ++it) { 1007 it != notification_info.end(); ++it) {
1008 const std::string& model_type_str = ModelTypeToString(it->first); 1008 const std::string model_type_str = ModelTypeToString(it->first);
1009 value->Set(model_type_str, it->second.ToValue()); 1009 value->Set(model_type_str, it->second.ToValue());
1010 } 1010 }
1011 1011
1012 return value; 1012 return value;
1013 } 1013 }
1014 1014
1015 std::string SyncManagerImpl::NotificationInfoToString( 1015 std::string SyncManagerImpl::NotificationInfoToString(
1016 const NotificationInfoMap& notification_info) { 1016 const NotificationInfoMap& notification_info) {
1017 scoped_ptr<base::DictionaryValue> value( 1017 scoped_ptr<base::DictionaryValue> value(
1018 NotificationInfoToValue(notification_info)); 1018 NotificationInfoToValue(notification_info));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 for (syncable::Directory::Metahandles::const_iterator it = 1141 for (syncable::Directory::Metahandles::const_iterator it =
1142 child_handles.begin(); it != child_handles.end(); ++it) { 1142 child_handles.begin(); it != child_handles.end(); ++it) {
1143 child_ids->Append(new base::StringValue(base::Int64ToString(*it))); 1143 child_ids->Append(new base::StringValue(base::Int64ToString(*it)));
1144 } 1144 }
1145 } 1145 }
1146 return JsArgList(&return_args); 1146 return JsArgList(&return_args);
1147 } 1147 }
1148 1148
1149 void SyncManagerImpl::UpdateNotificationInfo( 1149 void SyncManagerImpl::UpdateNotificationInfo(
1150 const ObjectIdInvalidationMap& invalidation_map) { 1150 const ObjectIdInvalidationMap& invalidation_map) {
1151 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); 1151 ObjectIdSet ids = invalidation_map.GetObjectIds();
1152 it != invalidation_map.end(); ++it) { 1152 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
1153 ModelType type = UNSPECIFIED; 1153 ModelType type = UNSPECIFIED;
1154 if (ObjectIdToRealModelType(it->first, &type)) { 1154 if (!ObjectIdToRealModelType(*it, &type)) {
1155 continue;
1156 }
1157 const SingleObjectInvalidationSet& type_invalidations =
1158 invalidation_map.ForObject(*it);
1159 for (SingleObjectInvalidationSet::const_iterator inv_it =
1160 type_invalidations.begin(); inv_it != type_invalidations.end();
1161 ++inv_it) {
1155 NotificationInfo* info = &notification_info_map_[type]; 1162 NotificationInfo* info = &notification_info_map_[type];
1156 info->total_count++; 1163 info->total_count++;
1157 info->payload = it->second.payload; 1164 std::string payload =
1165 inv_it->is_unknown_version() ? "UNKNOWN" : inv_it->payload();
1166 info->payload = payload;
1158 } 1167 }
1159 } 1168 }
1160 } 1169 }
1161 1170
1162 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { 1171 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) {
1163 DCHECK(thread_checker_.CalledOnValidThread()); 1172 DCHECK(thread_checker_.CalledOnValidThread());
1164 1173
1165 const std::string& state_str = InvalidatorStateToString(state); 1174 const std::string& state_str = InvalidatorStateToString(state);
1166 invalidator_state_ = state; 1175 invalidator_state_ = state;
1167 DVLOG(1) << "Invalidator state changed to: " << state_str; 1176 DVLOG(1) << "Invalidator state changed to: " << state_str;
(...skipping 10 matching lines...) Expand all
1178 "onNotificationStateChange", 1187 "onNotificationStateChange",
1179 JsEventDetails(&details)); 1188 JsEventDetails(&details));
1180 } 1189 }
1181 } 1190 }
1182 1191
1183 void SyncManagerImpl::OnIncomingInvalidation( 1192 void SyncManagerImpl::OnIncomingInvalidation(
1184 const ObjectIdInvalidationMap& invalidation_map) { 1193 const ObjectIdInvalidationMap& invalidation_map) {
1185 DCHECK(thread_checker_.CalledOnValidThread()); 1194 DCHECK(thread_checker_.CalledOnValidThread());
1186 1195
1187 // We should never receive IDs from non-sync objects. 1196 // We should never receive IDs from non-sync objects.
1188 ObjectIdSet ids = ObjectIdInvalidationMapToSet(invalidation_map); 1197 ObjectIdSet ids = invalidation_map.GetObjectIds();
1189 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { 1198 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
1190 ModelType type; 1199 ModelType type;
1191 if (!ObjectIdToRealModelType(*it, &type)) { 1200 if (!ObjectIdToRealModelType(*it, &type)) {
1192 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it); 1201 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it);
1193 } 1202 }
1194 } 1203 }
1195 1204
1196 if (invalidation_map.empty()) { 1205 if (invalidation_map.Empty()) {
1197 LOG(WARNING) << "Sync received invalidation without any type information."; 1206 LOG(WARNING) << "Sync received invalidation without any type information.";
1198 } else { 1207 } else {
1199 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); 1208 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION);
1200 scheduler_->ScheduleInvalidationNudge( 1209 scheduler_->ScheduleInvalidationNudge(
1201 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 1210 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
1202 invalidation_map, FROM_HERE); 1211 invalidation_map, FROM_HERE);
1203 allstatus_.IncrementNotificationsReceived(); 1212 allstatus_.IncrementNotificationsReceived();
1204 UpdateNotificationInfo(invalidation_map); 1213 UpdateNotificationInfo(invalidation_map);
1205 debug_info_event_listener_.OnIncomingNotification(invalidation_map); 1214 debug_info_event_listener_.OnIncomingNotification(invalidation_map);
1206 } 1215 }
1207 1216
1208 if (js_event_handler_.IsInitialized()) { 1217 if (js_event_handler_.IsInitialized()) {
1209 base::DictionaryValue details; 1218 base::DictionaryValue details;
1210 base::ListValue* changed_types = new base::ListValue(); 1219 base::ListValue* changed_types = new base::ListValue();
1211 details.Set("changedTypes", changed_types); 1220 details.Set("changedTypes", changed_types);
1212 ObjectIdSet id_set = ObjectIdInvalidationMapToSet(invalidation_map); 1221
1222 ObjectIdSet id_set = invalidation_map.GetObjectIds();
1213 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set); 1223 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set);
1214 DCHECK(!nudged_types.Empty()); 1224 DCHECK(!nudged_types.Empty());
1215 for (ModelTypeSet::Iterator it = nudged_types.First(); 1225 for (ModelTypeSet::Iterator it = nudged_types.First();
1216 it.Good(); it.Inc()) { 1226 it.Good(); it.Inc()) {
1217 const std::string model_type_str = ModelTypeToString(it.Get()); 1227 const std::string model_type_str = ModelTypeToString(it.Get());
1218 changed_types->Append(new base::StringValue(model_type_str)); 1228 changed_types->Append(new base::StringValue(model_type_str));
1219 } 1229 }
1220 details.SetString("source", "REMOTE_INVALIDATION"); 1230 details.SetString("source", "REMOTE_INVALIDATION");
1221 js_event_handler_.Call(FROM_HERE, 1231 js_event_handler_.Call(FROM_HERE,
1222 &JsEventHandler::HandleJsEvent, 1232 &JsEventHandler::HandleJsEvent,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1327 int SyncManagerImpl::GetDefaultNudgeDelay() { 1337 int SyncManagerImpl::GetDefaultNudgeDelay() {
1328 return kDefaultNudgeDelayMilliseconds; 1338 return kDefaultNudgeDelayMilliseconds;
1329 } 1339 }
1330 1340
1331 // static. 1341 // static.
1332 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1342 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1333 return kPreferencesNudgeDelayMilliseconds; 1343 return kPreferencesNudgeDelayMilliseconds;
1334 } 1344 }
1335 1345
1336 } // namespace syncer 1346 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/object_id_invalidation_map_test_util.cc ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698