| 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 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 948 void SyncManagerImpl::RequestNudgeForDataTypes( | 948 void SyncManagerImpl::RequestNudgeForDataTypes( |
| 949 const tracked_objects::Location& nudge_location, | 949 const tracked_objects::Location& nudge_location, |
| 950 ModelTypeSet types) { | 950 ModelTypeSet types) { |
| 951 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); | 951 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); |
| 952 | 952 |
| 953 // TODO(lipalani) : Calculate the nudge delay based on all types. | 953 // TODO(lipalani) : Calculate the nudge delay based on all types. |
| 954 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( | 954 base::TimeDelta nudge_delay = NudgeStrategy::GetNudgeDelayTimeDelta( |
| 955 types.First().Get(), | 955 types.First().Get(), |
| 956 this); | 956 this); |
| 957 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL); | 957 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL); |
| 958 scheduler_->ScheduleNudgeAsync(nudge_delay, | 958 scheduler_->ScheduleLocalNudge(nudge_delay, |
| 959 NUDGE_SOURCE_LOCAL, | |
| 960 types, | 959 types, |
| 961 nudge_location); | 960 nudge_location); |
| 962 } | 961 } |
| 963 | 962 |
| 964 void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { | 963 void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { |
| 965 DCHECK(thread_checker_.CalledOnValidThread()); | 964 DCHECK(thread_checker_.CalledOnValidThread()); |
| 966 // Only send an event if this is due to a cycle ending and this cycle | 965 // Only send an event if this is due to a cycle ending and this cycle |
| 967 // concludes a canonical "sync" process; that is, based on what is known | 966 // concludes a canonical "sync" process; that is, based on what is known |
| 968 // locally we are "all happy" and up-to-date. There may be new changes on | 967 // locally we are "all happy" and up-to-date. There may be new changes on |
| 969 // the server, but we'll get them on a subsequent sync. | 968 // the server, but we'll get them on a subsequent sync. |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 it != invalidation_map.end(); ++it) { | 1251 it != invalidation_map.end(); ++it) { |
| 1253 invalidator_->Acknowledge(it->first, it->second.ack_handle); | 1252 invalidator_->Acknowledge(it->first, it->second.ack_handle); |
| 1254 } | 1253 } |
| 1255 | 1254 |
| 1256 const ModelTypeInvalidationMap& type_invalidation_map = | 1255 const ModelTypeInvalidationMap& type_invalidation_map = |
| 1257 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); | 1256 ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); |
| 1258 if (type_invalidation_map.empty()) { | 1257 if (type_invalidation_map.empty()) { |
| 1259 LOG(WARNING) << "Sync received invalidation without any type information."; | 1258 LOG(WARNING) << "Sync received invalidation without any type information."; |
| 1260 } else { | 1259 } else { |
| 1261 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); | 1260 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); |
| 1262 scheduler_->ScheduleNudgeWithStatesAsync( | 1261 scheduler_->ScheduleInvalidation( |
| 1263 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), | 1262 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), |
| 1264 NUDGE_SOURCE_NOTIFICATION, | |
| 1265 type_invalidation_map, FROM_HERE); | 1263 type_invalidation_map, FROM_HERE); |
| 1266 allstatus_.IncrementNotificationsReceived(); | 1264 allstatus_.IncrementNotificationsReceived(); |
| 1267 UpdateNotificationInfo(type_invalidation_map); | 1265 UpdateNotificationInfo(type_invalidation_map); |
| 1268 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); | 1266 debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); |
| 1269 } | 1267 } |
| 1270 | 1268 |
| 1271 if (js_event_handler_.IsInitialized()) { | 1269 if (js_event_handler_.IsInitialized()) { |
| 1272 base::DictionaryValue details; | 1270 base::DictionaryValue details; |
| 1273 base::ListValue* changed_types = new base::ListValue(); | 1271 base::ListValue* changed_types = new base::ListValue(); |
| 1274 details.Set("changedTypes", changed_types); | 1272 details.Set("changedTypes", changed_types); |
| 1275 for (ModelTypeInvalidationMap::const_iterator it = | 1273 for (ModelTypeInvalidationMap::const_iterator it = |
| 1276 type_invalidation_map.begin(); it != type_invalidation_map.end(); | 1274 type_invalidation_map.begin(); it != type_invalidation_map.end(); |
| 1277 ++it) { | 1275 ++it) { |
| 1278 const std::string& model_type_str = | 1276 const std::string& model_type_str = |
| 1279 ModelTypeToString(it->first); | 1277 ModelTypeToString(it->first); |
| 1280 changed_types->Append(new base::StringValue(model_type_str)); | 1278 changed_types->Append(new base::StringValue(model_type_str)); |
| 1281 } | 1279 } |
| 1282 details.SetString("source", "REMOTE_INVALIDATION"); | 1280 details.SetString("source", "REMOTE_INVALIDATION"); |
| 1283 js_event_handler_.Call(FROM_HERE, | 1281 js_event_handler_.Call(FROM_HERE, |
| 1284 &JsEventHandler::HandleJsEvent, | 1282 &JsEventHandler::HandleJsEvent, |
| 1285 "onIncomingNotification", | 1283 "onIncomingNotification", |
| 1286 JsEventDetails(&details)); | 1284 JsEventDetails(&details)); |
| 1287 } | 1285 } |
| 1288 } | 1286 } |
| 1289 | 1287 |
| 1290 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { | 1288 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { |
| 1291 DCHECK(thread_checker_.CalledOnValidThread()); | 1289 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1292 const ModelTypeInvalidationMap& type_invalidation_map = | 1290 if (types.Empty()) { |
| 1293 ModelTypeSetToInvalidationMap(types, std::string()); | |
| 1294 if (type_invalidation_map.empty()) { | |
| 1295 LOG(WARNING) << "Sync received refresh request with no types specified."; | 1291 LOG(WARNING) << "Sync received refresh request with no types specified."; |
| 1296 } else { | 1292 } else { |
| 1297 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); | 1293 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_LOCAL_REFRESH); |
| 1298 scheduler_->ScheduleNudgeWithStatesAsync( | 1294 scheduler_->ScheduleLocalRefreshRequest( |
| 1299 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), | 1295 TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), |
| 1300 NUDGE_SOURCE_LOCAL_REFRESH, | 1296 types, FROM_HERE); |
| 1301 type_invalidation_map, FROM_HERE); | |
| 1302 } | 1297 } |
| 1303 | 1298 |
| 1304 if (js_event_handler_.IsInitialized()) { | 1299 if (js_event_handler_.IsInitialized()) { |
| 1305 base::DictionaryValue details; | 1300 base::DictionaryValue details; |
| 1306 base::ListValue* changed_types = new base::ListValue(); | 1301 base::ListValue* changed_types = new base::ListValue(); |
| 1307 details.Set("changedTypes", changed_types); | 1302 details.Set("changedTypes", changed_types); |
| 1308 for (ModelTypeInvalidationMap::const_iterator it = | 1303 for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { |
| 1309 type_invalidation_map.begin(); it != type_invalidation_map.end(); | |
| 1310 ++it) { | |
| 1311 const std::string& model_type_str = | 1304 const std::string& model_type_str = |
| 1312 ModelTypeToString(it->first); | 1305 ModelTypeToString(it.Get()); |
| 1313 changed_types->Append(new base::StringValue(model_type_str)); | 1306 changed_types->Append(new base::StringValue(model_type_str)); |
| 1314 } | 1307 } |
| 1315 details.SetString("source", "LOCAL_INVALIDATION"); | 1308 details.SetString("source", "LOCAL_INVALIDATION"); |
| 1316 js_event_handler_.Call(FROM_HERE, | 1309 js_event_handler_.Call(FROM_HERE, |
| 1317 &JsEventHandler::HandleJsEvent, | 1310 &JsEventHandler::HandleJsEvent, |
| 1318 "onIncomingNotification", | 1311 "onIncomingNotification", |
| 1319 JsEventDetails(&details)); | 1312 JsEventDetails(&details)); |
| 1320 } | 1313 } |
| 1321 } | 1314 } |
| 1322 | 1315 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1387 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1395 return kDefaultNudgeDelayMilliseconds; | 1388 return kDefaultNudgeDelayMilliseconds; |
| 1396 } | 1389 } |
| 1397 | 1390 |
| 1398 // static. | 1391 // static. |
| 1399 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1392 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1400 return kPreferencesNudgeDelayMilliseconds; | 1393 return kPreferencesNudgeDelayMilliseconds; |
| 1401 } | 1394 } |
| 1402 | 1395 |
| 1403 } // namespace syncer | 1396 } // namespace syncer |
| OLD | NEW |