Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: sync/internal_api/sync_manager_impl.cc

Issue 23754021: Invalidation trickles mega-patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 #include "sync/internal_api/public/write_node.h" 32 #include "sync/internal_api/public/write_node.h"
33 #include "sync/internal_api/public/write_transaction.h" 33 #include "sync/internal_api/public/write_transaction.h"
34 #include "sync/internal_api/syncapi_internal.h" 34 #include "sync/internal_api/syncapi_internal.h"
35 #include "sync/internal_api/syncapi_server_connection_manager.h" 35 #include "sync/internal_api/syncapi_server_connection_manager.h"
36 #include "sync/js/js_arg_list.h" 36 #include "sync/js/js_arg_list.h"
37 #include "sync/js/js_event_details.h" 37 #include "sync/js/js_event_details.h"
38 #include "sync/js/js_event_handler.h" 38 #include "sync/js/js_event_handler.h"
39 #include "sync/js/js_reply_handler.h" 39 #include "sync/js/js_reply_handler.h"
40 #include "sync/notifier/invalidation_util.h" 40 #include "sync/notifier/invalidation_util.h"
41 #include "sync/notifier/invalidator.h" 41 #include "sync/notifier/invalidator.h"
42 #include "sync/notifier/object_id_invalidation_map.h"
42 #include "sync/protocol/proto_value_conversions.h" 43 #include "sync/protocol/proto_value_conversions.h"
43 #include "sync/protocol/sync.pb.h" 44 #include "sync/protocol/sync.pb.h"
44 #include "sync/syncable/directory.h" 45 #include "sync/syncable/directory.h"
45 #include "sync/syncable/entry.h" 46 #include "sync/syncable/entry.h"
46 #include "sync/syncable/in_memory_directory_backing_store.h" 47 #include "sync/syncable/in_memory_directory_backing_store.h"
47 #include "sync/syncable/on_disk_directory_backing_store.h" 48 #include "sync/syncable/on_disk_directory_backing_store.h"
48 49
49 using base::TimeDelta; 50 using base::TimeDelta;
50 using sync_pb::GetUpdatesCallerInfo; 51 using sync_pb::GetUpdatesCallerInfo;
51 52
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 js_message_handlers_[name] = 1003 js_message_handlers_[name] =
1003 base::Bind(unbound_message_handler, base::Unretained(this)); 1004 base::Bind(unbound_message_handler, base::Unretained(this));
1004 } 1005 }
1005 1006
1006 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue( 1007 base::DictionaryValue* SyncManagerImpl::NotificationInfoToValue(
1007 const NotificationInfoMap& notification_info) { 1008 const NotificationInfoMap& notification_info) {
1008 base::DictionaryValue* value = new base::DictionaryValue(); 1009 base::DictionaryValue* value = new base::DictionaryValue();
1009 1010
1010 for (NotificationInfoMap::const_iterator it = notification_info.begin(); 1011 for (NotificationInfoMap::const_iterator it = notification_info.begin();
1011 it != notification_info.end(); ++it) { 1012 it != notification_info.end(); ++it) {
1012 const std::string& model_type_str = ModelTypeToString(it->first); 1013 const std::string model_type_str = ModelTypeToString(it->first);
1013 value->Set(model_type_str, it->second.ToValue()); 1014 value->Set(model_type_str, it->second.ToValue());
1014 } 1015 }
1015 1016
1016 return value; 1017 return value;
1017 } 1018 }
1018 1019
1019 std::string SyncManagerImpl::NotificationInfoToString( 1020 std::string SyncManagerImpl::NotificationInfoToString(
1020 const NotificationInfoMap& notification_info) { 1021 const NotificationInfoMap& notification_info) {
1021 scoped_ptr<base::DictionaryValue> value( 1022 scoped_ptr<base::DictionaryValue> value(
1022 NotificationInfoToValue(notification_info)); 1023 NotificationInfoToValue(notification_info));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 for (syncable::Directory::Metahandles::const_iterator it = 1146 for (syncable::Directory::Metahandles::const_iterator it =
1146 child_handles.begin(); it != child_handles.end(); ++it) { 1147 child_handles.begin(); it != child_handles.end(); ++it) {
1147 child_ids->Append(new base::StringValue(base::Int64ToString(*it))); 1148 child_ids->Append(new base::StringValue(base::Int64ToString(*it)));
1148 } 1149 }
1149 } 1150 }
1150 return JsArgList(&return_args); 1151 return JsArgList(&return_args);
1151 } 1152 }
1152 1153
1153 void SyncManagerImpl::UpdateNotificationInfo( 1154 void SyncManagerImpl::UpdateNotificationInfo(
1154 const ObjectIdInvalidationMap& invalidation_map) { 1155 const ObjectIdInvalidationMap& invalidation_map) {
1155 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); 1156 ObjectIdSet ids = invalidation_map.GetObjectIds();
1156 it != invalidation_map.end(); ++it) { 1157 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
1157 ModelType type = UNSPECIFIED; 1158 ModelType type = UNSPECIFIED;
1158 if (ObjectIdToRealModelType(it->first, &type)) { 1159 if (!ObjectIdToRealModelType(*it, &type)) {
1160 continue;
1161 }
1162 const OrderedInvalidationList& type_invalidations =
1163 invalidation_map.ForObject(*it);
1164 for (OrderedInvalidationList::const_iterator inv_it =
1165 type_invalidations.begin(); inv_it != type_invalidations.end();
1166 ++inv_it) {
1159 NotificationInfo* info = &notification_info_map_[type]; 1167 NotificationInfo* info = &notification_info_map_[type];
1160 info->total_count++; 1168 info->total_count++;
1161 info->payload = it->second.payload; 1169 std::string payload =
1170 inv_it->IsUnknownVersion() ? "UNKNOWN" : inv_it->GetPayload();
1171 info->payload = payload;
1162 } 1172 }
1163 } 1173 }
1164 } 1174 }
1165 1175
1166 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { 1176 void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) {
1167 DCHECK(thread_checker_.CalledOnValidThread()); 1177 DCHECK(thread_checker_.CalledOnValidThread());
1168 1178
1169 const std::string& state_str = InvalidatorStateToString(state); 1179 const std::string& state_str = InvalidatorStateToString(state);
1170 invalidator_state_ = state; 1180 invalidator_state_ = state;
1171 DVLOG(1) << "Invalidator state changed to: " << state_str; 1181 DVLOG(1) << "Invalidator state changed to: " << state_str;
(...skipping 10 matching lines...) Expand all
1182 "onNotificationStateChange", 1192 "onNotificationStateChange",
1183 JsEventDetails(&details)); 1193 JsEventDetails(&details));
1184 } 1194 }
1185 } 1195 }
1186 1196
1187 void SyncManagerImpl::OnIncomingInvalidation( 1197 void SyncManagerImpl::OnIncomingInvalidation(
1188 const ObjectIdInvalidationMap& invalidation_map) { 1198 const ObjectIdInvalidationMap& invalidation_map) {
1189 DCHECK(thread_checker_.CalledOnValidThread()); 1199 DCHECK(thread_checker_.CalledOnValidThread());
1190 1200
1191 // We should never receive IDs from non-sync objects. 1201 // We should never receive IDs from non-sync objects.
1192 ObjectIdSet ids = ObjectIdInvalidationMapToSet(invalidation_map); 1202 ObjectIdSet ids = invalidation_map.GetObjectIds();
1193 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { 1203 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
1194 ModelType type; 1204 ModelType type;
1195 if (!ObjectIdToRealModelType(*it, &type)) { 1205 if (!ObjectIdToRealModelType(*it, &type)) {
1196 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it); 1206 DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it);
1197 } 1207 }
1198 } 1208 }
1199 1209
1200 if (invalidation_map.empty()) { 1210 if (invalidation_map.Empty()) {
1201 LOG(WARNING) << "Sync received invalidation without any type information."; 1211 LOG(WARNING) << "Sync received invalidation without any type information.";
1202 } else { 1212 } else {
1203 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); 1213 allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION);
1204 scheduler_->ScheduleInvalidationNudge( 1214 scheduler_->ScheduleInvalidationNudge(
1205 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), 1215 TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec),
1206 invalidation_map, FROM_HERE); 1216 invalidation_map, FROM_HERE);
1207 allstatus_.IncrementNotificationsReceived(); 1217 allstatus_.IncrementNotificationsReceived();
1208 UpdateNotificationInfo(invalidation_map); 1218 UpdateNotificationInfo(invalidation_map);
1209 debug_info_event_listener_.OnIncomingNotification(invalidation_map); 1219 debug_info_event_listener_.OnIncomingNotification(invalidation_map);
1210 } 1220 }
1211 1221
1212 if (js_event_handler_.IsInitialized()) { 1222 if (js_event_handler_.IsInitialized()) {
1213 base::DictionaryValue details; 1223 base::DictionaryValue details;
1214 base::ListValue* changed_types = new base::ListValue(); 1224 base::ListValue* changed_types = new base::ListValue();
1215 details.Set("changedTypes", changed_types); 1225 details.Set("changedTypes", changed_types);
1216 ObjectIdSet id_set = ObjectIdInvalidationMapToSet(invalidation_map); 1226
1227 ObjectIdSet id_set = invalidation_map.GetObjectIds();
1217 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set); 1228 ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set);
1218 DCHECK(!nudged_types.Empty()); 1229 DCHECK(!nudged_types.Empty());
1219 for (ModelTypeSet::Iterator it = nudged_types.First(); 1230 for (ModelTypeSet::Iterator it = nudged_types.First();
1220 it.Good(); it.Inc()) { 1231 it.Good(); it.Inc()) {
1221 const std::string model_type_str = ModelTypeToString(it.Get()); 1232 const std::string model_type_str = ModelTypeToString(it.Get());
1222 changed_types->Append(new base::StringValue(model_type_str)); 1233 changed_types->Append(new base::StringValue(model_type_str));
1223 } 1234 }
1224 details.SetString("source", "REMOTE_INVALIDATION"); 1235 details.SetString("source", "REMOTE_INVALIDATION");
1225 js_event_handler_.Call(FROM_HERE, 1236 js_event_handler_.Call(FROM_HERE,
1226 &JsEventHandler::HandleJsEvent, 1237 &JsEventHandler::HandleJsEvent,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 int SyncManagerImpl::GetDefaultNudgeDelay() { 1342 int SyncManagerImpl::GetDefaultNudgeDelay() {
1332 return kDefaultNudgeDelayMilliseconds; 1343 return kDefaultNudgeDelayMilliseconds;
1333 } 1344 }
1334 1345
1335 // static. 1346 // static.
1336 int SyncManagerImpl::GetPreferencesNudgeDelay() { 1347 int SyncManagerImpl::GetPreferencesNudgeDelay() {
1337 return kPreferencesNudgeDelayMilliseconds; 1348 return kPreferencesNudgeDelayMilliseconds;
1338 } 1349 }
1339 1350
1340 } // namespace syncer 1351 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/object_id_invalidation_map_test_util.cc ('k') | sync/internal_api/sync_manager_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698