| 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 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 JsEventDetails(&details)); | 1233 JsEventDetails(&details)); |
| 1234 } | 1234 } |
| 1235 } | 1235 } |
| 1236 | 1236 |
| 1237 void SyncManagerImpl::OnIncomingInvalidation( | 1237 void SyncManagerImpl::OnIncomingInvalidation( |
| 1238 const ObjectIdInvalidationMap& invalidation_map, | 1238 const ObjectIdInvalidationMap& invalidation_map, |
| 1239 IncomingInvalidationSource source) { | 1239 IncomingInvalidationSource source) { |
| 1240 DCHECK(thread_checker_.CalledOnValidThread()); | 1240 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1241 const ModelTypeInvalidationMap& type_invalidation_map = | 1241 const ModelTypeInvalidationMap& type_invalidation_map = |
| 1242 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); | 1242 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); |
| 1243 if (source == LOCAL_INVALIDATION) { | 1243 if (type_invalidation_map.empty()) { |
| 1244 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); | 1244 LOG(WARNING) << "Sync received invalidation without any type information."; |
| 1245 scheduler_->ScheduleNudgeWithStatesAsync( | 1245 } else { |
| 1246 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | |
| 1247 NUDGE_SOURCE_LOCAL_REFRESH, | |
| 1248 type_invalidation_map, FROM_HERE); | |
| 1249 } else if (!type_invalidation_map.empty()) { | |
| 1250 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); | 1246 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); |
| 1251 scheduler_->ScheduleNudgeWithStatesAsync( | 1247 scheduler_->ScheduleNudgeWithStatesAsync( |
| 1252 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1248 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 1253 NUDGE_SOURCE_NOTIFICATION, | 1249 NUDGE_SOURCE_NOTIFICATION, |
| 1254 type_invalidation_map, FROM_HERE); | 1250 type_invalidation_map, FROM_HERE); |
| 1255 allstatus_.IncrementNotificationsReceived(); | 1251 allstatus_.IncrementNotificationsReceived(); |
| 1256 UpdateNotificationInfo(type_invalidation_map); | 1252 UpdateNotificationInfo(type_invalidation_map); |
| 1257 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); | 1253 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); |
| 1258 } else { | |
| 1259 LOG(WARNING) << "Sync received invalidation without any type information."; | |
| 1260 } | 1254 } |
| 1261 | 1255 |
| 1262 if (js_event_handler_.IsInitialized()) { | 1256 if (js_event_handler_.IsInitialized()) { |
| 1257 DictionaryValue details; |
| 1258 ListValue* changed_types = new ListValue(); |
| 1259 details.Set("changedTypes", changed_types); |
| 1260 for (ModelTypeInvalidationMap::const_iterator it = |
| 1261 type_invalidation_map.begin(); it != type_invalidation_map.end(); |
| 1262 ++it) { |
| 1263 const std::string& model_type_str = |
| 1264 ModelTypeToString(it->first); |
| 1265 changed_types->Append(Value::CreateStringValue(model_type_str)); |
| 1266 } |
| 1267 details.SetString("source", "REMOTE_INVALIDATION"); |
| 1268 js_event_handler_.Call(FROM_HERE, |
| 1269 &JsEventHandler::HandleJsEvent, |
| 1270 "onIncomingNotification", |
| 1271 JsEventDetails(&details)); |
| 1272 } |
| 1273 } |
| 1274 |
| 1275 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { |
| 1276 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1277 const ModelTypeInvalidationMap& type_invalidation_map = |
| 1278 ModelTypeSetToInvalidationMap(types, ""); |
| 1279 if (type_invalidation_map.empty()) { |
| 1280 LOG(WARNING) << "Sync received refresh request with no types specified."; |
| 1281 } else { |
| 1282 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); |
| 1283 scheduler_->ScheduleNudgeWithStatesAsync( |
| 1284 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 1285 NUDGE_SOURCE_LOCAL_REFRESH, |
| 1286 type_invalidation_map, FROM_HERE); |
| 1287 } |
| 1288 |
| 1289 if (js_event_handler_.IsInitialized()) { |
| 1263 DictionaryValue details; | 1290 DictionaryValue details; |
| 1264 ListValue* changed_types = new ListValue(); | 1291 ListValue* changed_types = new ListValue(); |
| 1265 details.Set("changedTypes", changed_types); | 1292 details.Set("changedTypes", changed_types); |
| 1266 for (ModelTypeInvalidationMap::const_iterator it = | 1293 for (ModelTypeInvalidationMap::const_iterator it = |
| 1267 type_invalidation_map.begin(); it != type_invalidation_map.end(); | 1294 type_invalidation_map.begin(); it != type_invalidation_map.end(); |
| 1268 ++it) { | 1295 ++it) { |
| 1269 const std::string& model_type_str = | 1296 const std::string& model_type_str = |
| 1270 ModelTypeToString(it->first); | 1297 ModelTypeToString(it->first); |
| 1271 changed_types->Append(Value::CreateStringValue(model_type_str)); | 1298 changed_types->Append(Value::CreateStringValue(model_type_str)); |
| 1272 } | 1299 } |
| 1273 details.SetString("source", (source == LOCAL_INVALIDATION) ? | 1300 details.SetString("source", "LOCAL_INVALIDATION"); |
| 1274 "LOCAL_INVALIDATION" : "REMOTE_INVALIDATION"); | |
| 1275 js_event_handler_.Call(FROM_HERE, | 1301 js_event_handler_.Call(FROM_HERE, |
| 1276 &JsEventHandler::HandleJsEvent, | 1302 &JsEventHandler::HandleJsEvent, |
| 1277 "onIncomingNotification", | 1303 "onIncomingNotification", |
| 1278 JsEventDetails(&details)); | 1304 JsEventDetails(&details)); |
| 1279 } | 1305 } |
| 1280 } | 1306 } |
| 1281 | 1307 |
| 1282 SyncStatus SyncManagerImpl::GetDetailedStatus() const { | 1308 SyncStatus SyncManagerImpl::GetDetailedStatus() const { |
| 1283 return allstatus_.status(); | 1309 return allstatus_.status(); |
| 1284 } | 1310 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1349 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1375 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1350 return kDefaultNudgeDelayMilliseconds; | 1376 return kDefaultNudgeDelayMilliseconds; |
| 1351 } | 1377 } |
| 1352 | 1378 |
| 1353 // static. | 1379 // static. |
| 1354 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1380 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1355 return kPreferencesNudgeDelayMilliseconds; | 1381 return kPreferencesNudgeDelayMilliseconds; |
| 1356 } | 1382 } |
| 1357 | 1383 |
| 1358 } // namespace syncer | 1384 } // namespace syncer |
| OLD | NEW |