Chromium Code Reviews| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "google/cacheinvalidation/include/invalidation-client.h" | 14 #include "google/cacheinvalidation/include/invalidation-client.h" |
| 15 #include "google/cacheinvalidation/include/types.h" | 15 #include "google/cacheinvalidation/include/types.h" |
| 16 #include "google/cacheinvalidation/types.pb.h" | 16 #include "google/cacheinvalidation/types.pb.h" |
| 17 #include "jingle/notifier/listener/push_client.h" | 17 #include "jingle/notifier/listener/push_client.h" |
| 18 #include "sync/notifier/invalidation_util.h" | 18 #include "sync/notifier/invalidation_util.h" |
| 19 #include "sync/notifier/registration_manager.h" | 19 #include "sync/notifier/registration_manager.h" |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const char kApplicationName[] = "chrome-sync"; | 23 const char kApplicationName[] = "chrome-sync"; |
| 24 | 24 |
| 25 static const int64 kUnknownVersion = -1; | |
| 26 | |
| 25 } // namespace | 27 } // namespace |
| 26 | 28 |
| 27 namespace syncer { | 29 namespace syncer { |
| 28 | 30 |
| 29 SyncInvalidationListener::Delegate::~Delegate() {} | 31 SyncInvalidationListener::Delegate::~Delegate() {} |
| 30 | 32 |
| 31 SyncInvalidationListener::SyncInvalidationListener( | 33 SyncInvalidationListener::SyncInvalidationListener( |
| 32 base::TickClock* tick_clock, | 34 base::TickClock* tick_clock, |
| 33 scoped_ptr<notifier::PushClient> push_client) | 35 scoped_ptr<notifier::PushClient> push_client) |
| 34 : weak_ptr_factory_(this), | 36 : weak_ptr_factory_(this), |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 const invalidation::ObjectId& object_id, | 215 const invalidation::ObjectId& object_id, |
| 214 const invalidation::AckHandle& ack_handle) { | 216 const invalidation::AckHandle& ack_handle) { |
| 215 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
| 216 DCHECK_EQ(client, invalidation_client_.get()); | 218 DCHECK_EQ(client, invalidation_client_.get()); |
| 217 DVLOG(1) << "InvalidateUnknownVersion"; | 219 DVLOG(1) << "InvalidateUnknownVersion"; |
| 218 | 220 |
| 219 ObjectIdSet ids; | 221 ObjectIdSet ids; |
| 220 ids.insert(object_id); | 222 ids.insert(object_id); |
| 221 PrepareInvalidation( | 223 PrepareInvalidation( |
| 222 ids, | 224 ids, |
| 223 Invalidation::kUnknownVersion, | 225 kUnknownVersion, |
| 224 std::string(), | 226 std::string(), |
| 225 client, | 227 client, |
| 226 ack_handle); | 228 ack_handle); |
| 227 } | 229 } |
| 228 | 230 |
| 229 // This should behave as if we got an invalidation with version | 231 // This should behave as if we got an invalidation with version |
| 230 // UNKNOWN_OBJECT_VERSION for all known data types. | 232 // UNKNOWN_OBJECT_VERSION for all known data types. |
| 231 void SyncInvalidationListener::InvalidateAll( | 233 void SyncInvalidationListener::InvalidateAll( |
| 232 invalidation::InvalidationClient* client, | 234 invalidation::InvalidationClient* client, |
| 233 const invalidation::AckHandle& ack_handle) { | 235 const invalidation::AckHandle& ack_handle) { |
| 234 DCHECK(CalledOnValidThread()); | 236 DCHECK(CalledOnValidThread()); |
| 235 DCHECK_EQ(client, invalidation_client_.get()); | 237 DCHECK_EQ(client, invalidation_client_.get()); |
| 236 DVLOG(1) << "InvalidateAll"; | 238 DVLOG(1) << "InvalidateAll"; |
| 237 | 239 |
| 238 PrepareInvalidation( | 240 PrepareInvalidation( |
| 239 registered_ids_, | 241 registered_ids_, |
| 240 Invalidation::kUnknownVersion, | 242 kUnknownVersion, |
| 241 std::string(), | 243 std::string(), |
| 242 client, | 244 client, |
| 243 ack_handle); | 245 ack_handle); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void SyncInvalidationListener::PrepareInvalidation( | 248 void SyncInvalidationListener::PrepareInvalidation( |
| 247 const ObjectIdSet& ids, | 249 const ObjectIdSet& ids, |
| 248 int64 version, | 250 int64 version, |
| 249 const std::string& payload, | 251 const std::string& payload, |
| 250 invalidation::InvalidationClient* client, | 252 invalidation::InvalidationClient* client, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 268 } | 270 } |
| 269 | 271 |
| 270 void SyncInvalidationListener::EmitInvalidation( | 272 void SyncInvalidationListener::EmitInvalidation( |
| 271 const ObjectIdSet& ids, | 273 const ObjectIdSet& ids, |
| 272 int64 version, | 274 int64 version, |
| 273 const std::string& payload, | 275 const std::string& payload, |
| 274 invalidation::InvalidationClient* client, | 276 invalidation::InvalidationClient* client, |
| 275 const invalidation::AckHandle& ack_handle, | 277 const invalidation::AckHandle& ack_handle, |
| 276 const AckHandleMap& local_ack_handles) { | 278 const AckHandleMap& local_ack_handles) { |
| 277 DCHECK(CalledOnValidThread()); | 279 DCHECK(CalledOnValidThread()); |
| 278 ObjectIdInvalidationMap invalidation_map = | 280 |
| 279 ObjectIdSetToInvalidationMap(ids, version, payload); | 281 ObjectIdInvalidationMap invalidation_map; |
| 280 for (AckHandleMap::const_iterator it = local_ack_handles.begin(); | 282 for (AckHandleMap::const_iterator it = local_ack_handles.begin(); |
| 281 it != local_ack_handles.end(); ++it) { | 283 it != local_ack_handles.end(); ++it) { |
| 282 // Update in-memory copy of the invalidation state. | 284 // Update in-memory copy of the invalidation state. |
| 283 invalidation_state_map_[it->first].expected = it->second; | 285 invalidation_state_map_[it->first].expected = it->second; |
| 284 invalidation_map[it->first].ack_handle = it->second; | 286 |
| 287 if (version == kUnknownVersion) { | |
|
tim (not reviewing)
2013/09/20 21:53:46
So is the contract with clients such that they dec
rlarocque
2013/09/23 18:38:19
No, I've rewritten the interface to the Invalidati
| |
| 288 Invalidation inv = Invalidation::InitUnknownVersion(it->first); | |
| 289 inv.SetAckHandle(it->second); | |
| 290 invalidation_map.Insert(inv); | |
| 291 } else { | |
| 292 Invalidation inv = Invalidation::Init(it->first, version, payload); | |
| 293 inv.SetAckHandle(it->second); | |
| 294 invalidation_map.Insert(inv); | |
| 295 } | |
| 285 } | 296 } |
| 286 ack_tracker_.Track(ids); | 297 ack_tracker_.Track(ids); |
| 287 delegate_->OnInvalidate(invalidation_map); | 298 delegate_->OnInvalidate(invalidation_map); |
| 288 client->Acknowledge(ack_handle); | 299 client->Acknowledge(ack_handle); |
| 289 } | 300 } |
| 290 | 301 |
| 291 void SyncInvalidationListener::OnTimeout(const ObjectIdSet& ids) { | 302 void SyncInvalidationListener::OnTimeout(const ObjectIdSet& ids) { |
| 292 ObjectIdInvalidationMap invalidation_map; | 303 ObjectIdInvalidationMap invalidation_map; |
| 293 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | 304 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
| 294 Invalidation invalidation; | 305 Invalidation inv; |
| 295 invalidation.ack_handle = invalidation_state_map_[*it].expected; | 306 if (invalidation_state_map_[*it].version == kUnknownVersion) { |
| 296 invalidation.version = invalidation_state_map_[*it].version; | 307 inv = Invalidation::InitUnknownVersion(*it); |
| 297 invalidation.payload = invalidation_state_map_[*it].payload; | 308 inv.SetAckHandle(invalidation_state_map_[*it].expected); |
| 298 invalidation_map.insert(std::make_pair(*it, invalidation)); | 309 } else { |
| 310 inv = Invalidation::Init( | |
| 311 *it, | |
| 312 invalidation_state_map_[*it].version, | |
| 313 invalidation_state_map_[*it].payload); | |
| 314 inv.SetAckHandle(invalidation_state_map_[*it].expected); | |
| 315 } | |
| 316 invalidation_map.Insert(inv); | |
| 299 } | 317 } |
| 300 | |
| 301 delegate_->OnInvalidate(invalidation_map); | 318 delegate_->OnInvalidate(invalidation_map); |
| 302 } | 319 } |
| 303 | 320 |
| 304 void SyncInvalidationListener::InformRegistrationStatus( | 321 void SyncInvalidationListener::InformRegistrationStatus( |
| 305 invalidation::InvalidationClient* client, | 322 invalidation::InvalidationClient* client, |
| 306 const invalidation::ObjectId& object_id, | 323 const invalidation::ObjectId& object_id, |
| 307 InvalidationListener::RegistrationState new_state) { | 324 InvalidationListener::RegistrationState new_state) { |
| 308 DCHECK(CalledOnValidThread()); | 325 DCHECK(CalledOnValidThread()); |
| 309 DCHECK_EQ(client, invalidation_client_.get()); | 326 DCHECK_EQ(client, invalidation_client_.get()); |
| 310 DVLOG(1) << "InformRegistrationStatus: " | 327 DVLOG(1) << "InformRegistrationStatus: " |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 462 EmitStateChange(); | 479 EmitStateChange(); |
| 463 } | 480 } |
| 464 | 481 |
| 465 void SyncInvalidationListener::OnIncomingNotification( | 482 void SyncInvalidationListener::OnIncomingNotification( |
| 466 const notifier::Notification& notification) { | 483 const notifier::Notification& notification) { |
| 467 DCHECK(CalledOnValidThread()); | 484 DCHECK(CalledOnValidThread()); |
| 468 // Do nothing, since this is already handled by |invalidation_client_|. | 485 // Do nothing, since this is already handled by |invalidation_client_|. |
| 469 } | 486 } |
| 470 | 487 |
| 471 } // namespace syncer | 488 } // namespace syncer |
| OLD | NEW |