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