Chromium Code Reviews| 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 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1240 JsEventDetails(&details)); | 1240 JsEventDetails(&details)); |
| 1241 } | 1241 } |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 void SyncManagerImpl::OnIncomingInvalidation( | 1244 void SyncManagerImpl::OnIncomingInvalidation( |
| 1245 const ObjectIdInvalidationMap& invalidation_map, | 1245 const ObjectIdInvalidationMap& invalidation_map, |
| 1246 IncomingInvalidationSource source) { | 1246 IncomingInvalidationSource source) { |
| 1247 DCHECK(thread_checker_.CalledOnValidThread()); | 1247 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1248 const ModelTypeInvalidationMap& type_invalidation_map = | 1248 const ModelTypeInvalidationMap& type_invalidation_map = |
| 1249 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); | 1249 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); |
| 1250 if (source == LOCAL_INVALIDATION) { | 1250 if (type_invalidation_map.empty()) { |
| 1251 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); | 1251 LOG(WARNING) << "Sync received invalidation without any type information."; |
| 1252 scheduler_->ScheduleNudgeWithStatesAsync( | 1252 } else { |
| 1253 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | |
| 1254 NUDGE_SOURCE_LOCAL_REFRESH, | |
| 1255 type_invalidation_map, FROM_HERE); | |
| 1256 } else if (!type_invalidation_map.empty()) { | |
| 1257 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); | 1253 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); |
| 1258 scheduler_->ScheduleNudgeWithStatesAsync( | 1254 scheduler_->ScheduleNudgeWithStatesAsync( |
| 1259 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1255 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 1260 NUDGE_SOURCE_NOTIFICATION, | 1256 NUDGE_SOURCE_NOTIFICATION, |
| 1261 type_invalidation_map, FROM_HERE); | 1257 type_invalidation_map, FROM_HERE); |
| 1262 allstatus_.IncrementNotificationsReceived(); | 1258 allstatus_.IncrementNotificationsReceived(); |
| 1263 UpdateNotificationInfo(type_invalidation_map); | 1259 UpdateNotificationInfo(type_invalidation_map); |
| 1264 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); | 1260 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); |
| 1265 } else { | |
| 1266 LOG(WARNING) << "Sync received invalidation without any type information."; | |
| 1267 } | 1261 } |
| 1268 | 1262 |
| 1269 if (js_event_handler_.IsInitialized()) { | 1263 if (js_event_handler_.IsInitialized()) { |
| 1270 DictionaryValue details; | 1264 DictionaryValue details; |
| 1271 ListValue* changed_types = new ListValue(); | 1265 ListValue* changed_types = new ListValue(); |
| 1272 details.Set("changedTypes", changed_types); | 1266 details.Set("changedTypes", changed_types); |
| 1273 for (ModelTypeInvalidationMap::const_iterator it = | 1267 for (ModelTypeInvalidationMap::const_iterator it = |
| 1274 type_invalidation_map.begin(); it != type_invalidation_map.end(); | 1268 type_invalidation_map.begin(); it != type_invalidation_map.end(); |
| 1275 ++it) { | 1269 ++it) { |
| 1276 const std::string& model_type_str = | 1270 const std::string& model_type_str = |
| 1277 ModelTypeToString(it->first); | 1271 ModelTypeToString(it->first); |
| 1278 changed_types->Append(Value::CreateStringValue(model_type_str)); | 1272 changed_types->Append(Value::CreateStringValue(model_type_str)); |
| 1279 } | 1273 } |
| 1280 details.SetString("source", (source == LOCAL_INVALIDATION) ? | 1274 details.SetString("source", "REMOTE_INVALIDATION"); |
| 1281 "LOCAL_INVALIDATION" : "REMOTE_INVALIDATION"); | |
| 1282 js_event_handler_.Call(FROM_HERE, | 1275 js_event_handler_.Call(FROM_HERE, |
| 1283 &JsEventHandler::HandleJsEvent, | 1276 &JsEventHandler::HandleJsEvent, |
| 1284 "onIncomingNotification", | 1277 "onIncomingNotification", |
| 1278 JsEventDetails(&details)); | |
| 1279 } | |
| 1280 } | |
| 1281 | |
| 1282 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { | |
| 1283 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1284 const ModelTypeInvalidationMap& type_invalidation_map = | |
| 1285 ModelTypeSetToInvalidationMap(types, ""); | |
|
Nicolas Zea
2013/01/28 23:48:43
handle the empty type invalidation map case here t
rlarocque
2013/01/29 18:48:58
Fixed. I'm not sure that it's necessary, but it c
| |
| 1286 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); | |
| 1287 scheduler_->ScheduleNudgeWithStatesAsync( | |
| 1288 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | |
| 1289 NUDGE_SOURCE_LOCAL_REFRESH, | |
| 1290 type_invalidation_map, FROM_HERE); | |
| 1291 | |
| 1292 if (js_event_handler_.IsInitialized()) { | |
| 1293 DictionaryValue details; | |
| 1294 ListValue* changed_types = new ListValue(); | |
| 1295 details.Set("changedTypes", changed_types); | |
| 1296 for (ModelTypeInvalidationMap::const_iterator it = | |
| 1297 type_invalidation_map.begin(); it != type_invalidation_map.end(); | |
| 1298 ++it) { | |
| 1299 const std::string& model_type_str = | |
| 1300 ModelTypeToString(it->first); | |
| 1301 changed_types->Append(Value::CreateStringValue(model_type_str)); | |
| 1302 } | |
| 1303 details.SetString("source", "LOCAL_INVALIDATION"); | |
| 1304 js_event_handler_.Call(FROM_HERE, | |
| 1305 &JsEventHandler::HandleJsEvent, | |
| 1306 "onIncomingNotification", | |
| 1285 JsEventDetails(&details)); | 1307 JsEventDetails(&details)); |
| 1286 } | 1308 } |
| 1287 } | 1309 } |
| 1288 | 1310 |
| 1289 SyncStatus SyncManagerImpl::GetDetailedStatus() const { | 1311 SyncStatus SyncManagerImpl::GetDetailedStatus() const { |
| 1290 return allstatus_.status(); | 1312 return allstatus_.status(); |
| 1291 } | 1313 } |
| 1292 | 1314 |
| 1293 void SyncManagerImpl::SaveChanges() { | 1315 void SyncManagerImpl::SaveChanges() { |
| 1294 directory()->SaveChanges(); | 1316 directory()->SaveChanges(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1356 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1378 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1357 return kDefaultNudgeDelayMilliseconds; | 1379 return kDefaultNudgeDelayMilliseconds; |
| 1358 } | 1380 } |
| 1359 | 1381 |
| 1360 // static. | 1382 // static. |
| 1361 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1383 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1362 return kPreferencesNudgeDelayMilliseconds; | 1384 return kPreferencesNudgeDelayMilliseconds; |
| 1363 } | 1385 } |
| 1364 | 1386 |
| 1365 } // namespace syncer | 1387 } // namespace syncer |
| OLD | NEW |