| 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/notifier/sync_invalidation_listener.h" | 5 #include "sync/notifier/sync_invalidation_listener.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 << " to " << invalidation.version(); | 198 << " to " << invalidation.version(); |
| 199 invalidation_state_map_[id].version = invalidation.version(); | 199 invalidation_state_map_[id].version = invalidation.version(); |
| 200 invalidation_state_map_[id].payload = payload; | 200 invalidation_state_map_[id].payload = payload; |
| 201 invalidation_state_tracker_.Call( | 201 invalidation_state_tracker_.Call( |
| 202 FROM_HERE, | 202 FROM_HERE, |
| 203 &InvalidationStateTracker::SetMaxVersionAndPayload, | 203 &InvalidationStateTracker::SetMaxVersionAndPayload, |
| 204 id, invalidation.version(), payload); | 204 id, invalidation.version(), payload); |
| 205 | 205 |
| 206 ObjectIdSet ids; | 206 ObjectIdSet ids; |
| 207 ids.insert(id); | 207 ids.insert(id); |
| 208 PrepareInvalidation(ids, payload, client, ack_handle); | 208 PrepareInvalidation(ids, invalidation.version(), payload, client, ack_handle); |
| 209 } | 209 } |
| 210 | 210 |
| 211 void SyncInvalidationListener::InvalidateUnknownVersion( | 211 void SyncInvalidationListener::InvalidateUnknownVersion( |
| 212 invalidation::InvalidationClient* client, | 212 invalidation::InvalidationClient* client, |
| 213 const invalidation::ObjectId& object_id, | 213 const invalidation::ObjectId& object_id, |
| 214 const invalidation::AckHandle& ack_handle) { | 214 const invalidation::AckHandle& ack_handle) { |
| 215 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 216 DCHECK_EQ(client, invalidation_client_.get()); | 216 DCHECK_EQ(client, invalidation_client_.get()); |
| 217 DVLOG(1) << "InvalidateUnknownVersion"; | 217 DVLOG(1) << "InvalidateUnknownVersion"; |
| 218 | 218 |
| 219 ObjectIdSet ids; | 219 ObjectIdSet ids; |
| 220 ids.insert(object_id); | 220 ids.insert(object_id); |
| 221 PrepareInvalidation(ids, std::string(), client, ack_handle); | 221 PrepareInvalidation( |
| 222 ids, |
| 223 Invalidation::kUnknownVersion, |
| 224 std::string(), |
| 225 client, |
| 226 ack_handle); |
| 222 } | 227 } |
| 223 | 228 |
| 224 // This should behave as if we got an invalidation with version | 229 // This should behave as if we got an invalidation with version |
| 225 // UNKNOWN_OBJECT_VERSION for all known data types. | 230 // UNKNOWN_OBJECT_VERSION for all known data types. |
| 226 void SyncInvalidationListener::InvalidateAll( | 231 void SyncInvalidationListener::InvalidateAll( |
| 227 invalidation::InvalidationClient* client, | 232 invalidation::InvalidationClient* client, |
| 228 const invalidation::AckHandle& ack_handle) { | 233 const invalidation::AckHandle& ack_handle) { |
| 229 DCHECK(CalledOnValidThread()); | 234 DCHECK(CalledOnValidThread()); |
| 230 DCHECK_EQ(client, invalidation_client_.get()); | 235 DCHECK_EQ(client, invalidation_client_.get()); |
| 231 DVLOG(1) << "InvalidateAll"; | 236 DVLOG(1) << "InvalidateAll"; |
| 232 | 237 |
| 233 PrepareInvalidation(registered_ids_, std::string(), client, ack_handle); | 238 PrepareInvalidation( |
| 239 registered_ids_, |
| 240 Invalidation::kUnknownVersion, |
| 241 std::string(), |
| 242 client, |
| 243 ack_handle); |
| 234 } | 244 } |
| 235 | 245 |
| 236 void SyncInvalidationListener::PrepareInvalidation( | 246 void SyncInvalidationListener::PrepareInvalidation( |
| 237 const ObjectIdSet& ids, | 247 const ObjectIdSet& ids, |
| 248 int64 version, |
| 238 const std::string& payload, | 249 const std::string& payload, |
| 239 invalidation::InvalidationClient* client, | 250 invalidation::InvalidationClient* client, |
| 240 const invalidation::AckHandle& ack_handle) { | 251 const invalidation::AckHandle& ack_handle) { |
| 241 DCHECK(CalledOnValidThread()); | 252 DCHECK(CalledOnValidThread()); |
| 242 | 253 |
| 243 // A server invalidation resets the local retry count. | 254 // A server invalidation resets the local retry count. |
| 244 ack_tracker_.Ack(ids); | 255 ack_tracker_.Ack(ids); |
| 245 invalidation_state_tracker_.Call( | 256 invalidation_state_tracker_.Call( |
| 246 FROM_HERE, | 257 FROM_HERE, |
| 247 &InvalidationStateTracker::GenerateAckHandles, | 258 &InvalidationStateTracker::GenerateAckHandles, |
| 248 ids, | 259 ids, |
| 249 base::MessageLoopProxy::current(), | 260 base::MessageLoopProxy::current(), |
| 250 base::Bind(&SyncInvalidationListener::EmitInvalidation, | 261 base::Bind(&SyncInvalidationListener::EmitInvalidation, |
| 251 weak_ptr_factory_.GetWeakPtr(), | 262 weak_ptr_factory_.GetWeakPtr(), |
| 252 ids, | 263 ids, |
| 264 version, |
| 253 payload, | 265 payload, |
| 254 client, | 266 client, |
| 255 ack_handle)); | 267 ack_handle)); |
| 256 } | 268 } |
| 257 | 269 |
| 258 void SyncInvalidationListener::EmitInvalidation( | 270 void SyncInvalidationListener::EmitInvalidation( |
| 259 const ObjectIdSet& ids, | 271 const ObjectIdSet& ids, |
| 272 int64 version, |
| 260 const std::string& payload, | 273 const std::string& payload, |
| 261 invalidation::InvalidationClient* client, | 274 invalidation::InvalidationClient* client, |
| 262 const invalidation::AckHandle& ack_handle, | 275 const invalidation::AckHandle& ack_handle, |
| 263 const AckHandleMap& local_ack_handles) { | 276 const AckHandleMap& local_ack_handles) { |
| 264 DCHECK(CalledOnValidThread()); | 277 DCHECK(CalledOnValidThread()); |
| 265 ObjectIdInvalidationMap invalidation_map = | 278 ObjectIdInvalidationMap invalidation_map = |
| 266 ObjectIdSetToInvalidationMap(ids, payload); | 279 ObjectIdSetToInvalidationMap(ids, version, payload); |
| 267 for (AckHandleMap::const_iterator it = local_ack_handles.begin(); | 280 for (AckHandleMap::const_iterator it = local_ack_handles.begin(); |
| 268 it != local_ack_handles.end(); ++it) { | 281 it != local_ack_handles.end(); ++it) { |
| 269 // Update in-memory copy of the invalidation state. | 282 // Update in-memory copy of the invalidation state. |
| 270 invalidation_state_map_[it->first].expected = it->second; | 283 invalidation_state_map_[it->first].expected = it->second; |
| 271 invalidation_map[it->first].ack_handle = it->second; | 284 invalidation_map[it->first].ack_handle = it->second; |
| 272 } | 285 } |
| 273 ack_tracker_.Track(ids); | 286 ack_tracker_.Track(ids); |
| 274 delegate_->OnInvalidate(invalidation_map); | 287 delegate_->OnInvalidate(invalidation_map); |
| 275 client->Acknowledge(ack_handle); | 288 client->Acknowledge(ack_handle); |
| 276 } | 289 } |
| 277 | 290 |
| 278 void SyncInvalidationListener::OnTimeout(const ObjectIdSet& ids) { | 291 void SyncInvalidationListener::OnTimeout(const ObjectIdSet& ids) { |
| 279 ObjectIdInvalidationMap invalidation_map; | 292 ObjectIdInvalidationMap invalidation_map; |
| 280 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | 293 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
| 281 Invalidation invalidation; | 294 Invalidation invalidation; |
| 282 invalidation.ack_handle = invalidation_state_map_[*it].expected; | 295 invalidation.ack_handle = invalidation_state_map_[*it].expected; |
| 296 invalidation.version = invalidation_state_map_[*it].version; |
| 283 invalidation.payload = invalidation_state_map_[*it].payload; | 297 invalidation.payload = invalidation_state_map_[*it].payload; |
| 284 invalidation_map.insert(std::make_pair(*it, invalidation)); | 298 invalidation_map.insert(std::make_pair(*it, invalidation)); |
| 285 } | 299 } |
| 286 | 300 |
| 287 delegate_->OnInvalidate(invalidation_map); | 301 delegate_->OnInvalidate(invalidation_map); |
| 288 } | 302 } |
| 289 | 303 |
| 290 void SyncInvalidationListener::InformRegistrationStatus( | 304 void SyncInvalidationListener::InformRegistrationStatus( |
| 291 invalidation::InvalidationClient* client, | 305 invalidation::InvalidationClient* client, |
| 292 const invalidation::ObjectId& object_id, | 306 const invalidation::ObjectId& object_id, |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 EmitStateChange(); | 462 EmitStateChange(); |
| 449 } | 463 } |
| 450 | 464 |
| 451 void SyncInvalidationListener::OnIncomingNotification( | 465 void SyncInvalidationListener::OnIncomingNotification( |
| 452 const notifier::Notification& notification) { | 466 const notifier::Notification& notification) { |
| 453 DCHECK(CalledOnValidThread()); | 467 DCHECK(CalledOnValidThread()); |
| 454 // Do nothing, since this is already handled by |invalidation_client_|. | 468 // Do nothing, since this is already handled by |invalidation_client_|. |
| 455 } | 469 } |
| 456 | 470 |
| 457 } // namespace syncer | 471 } // namespace syncer |
| OLD | NEW |