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 "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 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 js_message_handlers_[name] = | 1002 js_message_handlers_[name] = |
1003 base::Bind(unbound_message_handler, base::Unretained(this)); | 1003 base::Bind(unbound_message_handler, base::Unretained(this)); |
1004 } | 1004 } |
1005 | 1005 |
1006 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue( | 1006 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue( |
1007 const NotificationInfoMap& notification_info) { | 1007 const NotificationInfoMap& notification_info) { |
1008 base::DictionaryValue* value = new base::DictionaryValue(); | 1008 base::DictionaryValue* value = new base::DictionaryValue(); |
1009 | 1009 |
1010 for (NotificationInfoMap::const_iterator it = notification_info.begin(); | 1010 for (NotificationInfoMap::const_iterator it = notification_info.begin(); |
1011 it != notification_info.end(); ++it) { | 1011 it != notification_info.end(); ++it) { |
1012 const std::string& model_type_str = ModelTypeToString(it->first); | 1012 const std::string model_type_str = ModelTypeToString(it->first); |
1013 value->Set(model_type_str, it->second.ToValue()); | 1013 value->Set(model_type_str, it->second.ToValue()); |
1014 } | 1014 } |
1015 | 1015 |
1016 return value; | 1016 return value; |
1017 } | 1017 } |
1018 | 1018 |
1019 std::string SyncManagerImpl::NotificationInfoToString( | 1019 std::string SyncManagerImpl::NotificationInfoToString( |
1020 const NotificationInfoMap& notification_info) { | 1020 const NotificationInfoMap& notification_info) { |
1021 scoped_ptr<base::DictionaryValue> value( | 1021 scoped_ptr<base::DictionaryValue> value( |
1022 NotificationInfoToValue(notification_info)); | 1022 NotificationInfoToValue(notification_info)); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 for (syncable::Directory::Metahandles::const_iterator it = | 1145 for (syncable::Directory::Metahandles::const_iterator it = |
1146 child_handles.begin(); it != child_handles.end(); ++it) { | 1146 child_handles.begin(); it != child_handles.end(); ++it) { |
1147 child_ids->Append(new base::StringValue(base::Int64ToString(*it))); | 1147 child_ids->Append(new base::StringValue(base::Int64ToString(*it))); |
1148 } | 1148 } |
1149 } | 1149 } |
1150 return JsArgList(&return_args); | 1150 return JsArgList(&return_args); |
1151 } | 1151 } |
1152 | 1152 |
1153 void SyncManagerImpl::UpdateNotificationInfo( | 1153 void SyncManagerImpl::UpdateNotificationInfo( |
1154 const ObjectIdInvalidationMap& invalidation_map) { | 1154 const ObjectIdInvalidationMap& invalidation_map) { |
1155 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); | 1155 ObjectIdSet ids = invalidation_map.GetObjectIds(); |
1156 it != invalidation_map.end(); ++it) { | 1156 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
1157 ModelType type = UNSPECIFIED; | 1157 ModelType type = UNSPECIFIED; |
1158 if (ObjectIdToRealModelType(it->first, &type)) { | 1158 if (!ObjectIdToRealModelType(*it, &type)) { |
| 1159 continue; |
| 1160 } |
| 1161 const OrderedInvalidationList& type_invalidations = |
| 1162 invalidation_map.ForObject(*it); |
| 1163 for (OrderedInvalidationList::const_iterator inv_it = |
| 1164 type_invalidations.begin(); inv_it != type_invalidations.end(); |
| 1165 ++inv_it) { |
1159 NotificationInfo* info = ¬ification_info_map_[type]; | 1166 NotificationInfo* info = ¬ification_info_map_[type]; |
1160 info->total_count++; | 1167 info->total_count++; |
1161 info->payload = it->second.payload; | 1168 std::string payload = |
| 1169 inv_it->IsUnknownVersion() ? "UNKNOWN" : inv_it->GetPayload(); |
| 1170 info->payload = payload; |
1162 } | 1171 } |
1163 } | 1172 } |
1164 } | 1173 } |
1165 | 1174 |
1166 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { | 1175 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { |
1167 DCHECK(thread_checker_.CalledOnValidThread()); | 1176 DCHECK(thread_checker_.CalledOnValidThread()); |
1168 | 1177 |
1169 const std::string& state_str = InvalidatorStateToString(state); | 1178 const std::string& state_str = InvalidatorStateToString(state); |
1170 invalidator_state_ = state; | 1179 invalidator_state_ = state; |
1171 DVLOG(1) << "Invalidator state changed to: " << state_str; | 1180 DVLOG(1) << "Invalidator state changed to: " << state_str; |
(...skipping 10 matching lines...) Expand all Loading... |
1182 "onNotificationStateChange", | 1191 "onNotificationStateChange", |
1183 JsEventDetails(&details)); | 1192 JsEventDetails(&details)); |
1184 } | 1193 } |
1185 } | 1194 } |
1186 | 1195 |
1187 void SyncManagerImpl::OnIncomingInvalidation( | 1196 void SyncManagerImpl::OnIncomingInvalidation( |
1188 const ObjectIdInvalidationMap& invalidation_map) { | 1197 const ObjectIdInvalidationMap& invalidation_map) { |
1189 DCHECK(thread_checker_.CalledOnValidThread()); | 1198 DCHECK(thread_checker_.CalledOnValidThread()); |
1190 | 1199 |
1191 // We should never receive IDs from non-sync objects. | 1200 // We should never receive IDs from non-sync objects. |
1192 ObjectIdSet ids = ObjectIdInvalidationMapToSet(invalidation_map); | 1201 ObjectIdSet ids = invalidation_map.GetObjectIds(); |
1193 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | 1202 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
1194 ModelType type; | 1203 ModelType type; |
1195 if (!ObjectIdToRealModelType(*it, &type)) { | 1204 if (!ObjectIdToRealModelType(*it, &type)) { |
1196 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it); | 1205 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it); |
1197 } | 1206 } |
1198 } | 1207 } |
1199 | 1208 |
1200 if (invalidation_map.empty()) { | 1209 if (invalidation_map.Empty()) { |
1201 LOG(WARNING) << "Sync received invalidation without any type information."; | 1210 LOG(WARNING) << "Sync received invalidation without any type information."; |
1202 } else { | 1211 } else { |
1203 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); | 1212 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); |
1204 scheduler_->ScheduleInvalidationNudge( | 1213 scheduler_->ScheduleInvalidationNudge( |
1205 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1214 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
1206 invalidation_map, FROM_HERE); | 1215 invalidation_map, FROM_HERE); |
1207 allstatus_.IncrementNotificationsReceived(); | 1216 allstatus_.IncrementNotificationsReceived(); |
1208 UpdateNotificationInfo(invalidation_map); | 1217 UpdateNotificationInfo(invalidation_map); |
1209 debug_info_event_listener_.OnIncomingNotification(invalidation_map); | 1218 debug_info_event_listener_.OnIncomingNotification(invalidation_map); |
1210 } | 1219 } |
1211 | 1220 |
1212 if (js_event_handler_.IsInitialized()) { | 1221 if (js_event_handler_.IsInitialized()) { |
1213 base::DictionaryValue details; | 1222 base::DictionaryValue details; |
1214 base::ListValue* changed_types = new base::ListValue(); | 1223 base::ListValue* changed_types = new base::ListValue(); |
1215 details.Set("changedTypes", changed_types); | 1224 details.Set("changedTypes", changed_types); |
1216 ObjectIdSet id_set = ObjectIdInvalidationMapToSet(invalidation_map); | 1225 |
| 1226 ObjectIdSet id_set = invalidation_map.GetObjectIds(); |
1217 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set); | 1227 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set); |
1218 DCHECK(!nudged_types.Empty()); | 1228 DCHECK(!nudged_types.Empty()); |
1219 for (ModelTypeSet::Iterator it = nudged_types.First(); | 1229 for (ModelTypeSet::Iterator it = nudged_types.First(); |
1220 it.Good(); it.Inc()) { | 1230 it.Good(); it.Inc()) { |
1221 const std::string model_type_str = ModelTypeToString(it.Get()); | 1231 const std::string model_type_str = ModelTypeToString(it.Get()); |
1222 changed_types->Append(new base::StringValue(model_type_str)); | 1232 changed_types->Append(new base::StringValue(model_type_str)); |
1223 } | 1233 } |
1224 details.SetString("source", "REMOTE_INVALIDATION"); | 1234 details.SetString("source", "REMOTE_INVALIDATION"); |
1225 js_event_handler_.Call(FROM_HERE, | 1235 js_event_handler_.Call(FROM_HERE, |
1226 &JsEventHandler::HandleJsEvent, | 1236 &JsEventHandler::HandleJsEvent, |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1341 int SyncManagerImpl::GetDefaultNudgeDelay() { |
1332 return kDefaultNudgeDelayMilliseconds; | 1342 return kDefaultNudgeDelayMilliseconds; |
1333 } | 1343 } |
1334 | 1344 |
1335 // static. | 1345 // static. |
1336 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1346 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
1337 return kPreferencesNudgeDelayMilliseconds; | 1347 return kPreferencesNudgeDelayMilliseconds; |
1338 } | 1348 } |
1339 | 1349 |
1340 } // namespace syncer | 1350 } // namespace syncer |
OLD | NEW |