| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/invalidation/sync_invalidation_listener.h" | 5 #include "components/invalidation/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/location.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/thread_task_runner_handle.h" |
| 13 #include "base/tracked_objects.h" | 16 #include "base/tracked_objects.h" |
| 14 #include "components/invalidation/invalidation_util.h" | 17 #include "components/invalidation/invalidation_util.h" |
| 15 #include "components/invalidation/object_id_invalidation_map.h" | 18 #include "components/invalidation/object_id_invalidation_map.h" |
| 16 #include "components/invalidation/registration_manager.h" | 19 #include "components/invalidation/registration_manager.h" |
| 17 #include "google/cacheinvalidation/include/invalidation-client.h" | 20 #include "google/cacheinvalidation/include/invalidation-client.h" |
| 18 #include "google/cacheinvalidation/include/types.h" | 21 #include "google/cacheinvalidation/include/types.h" |
| 19 #include "jingle/notifier/listener/push_client.h" | 22 #include "jingle/notifier/listener/push_client.h" |
| 20 | 23 |
| 21 namespace { | 24 namespace { |
| 22 | 25 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 std::string payload; | 133 std::string payload; |
| 131 // payload() CHECK()'s has_payload(), so we must check it ourselves first. | 134 // payload() CHECK()'s has_payload(), so we must check it ourselves first. |
| 132 if (invalidation.has_payload()) | 135 if (invalidation.has_payload()) |
| 133 payload = invalidation.payload(); | 136 payload = invalidation.payload(); |
| 134 | 137 |
| 135 DVLOG(2) << "Received invalidation with version " << invalidation.version() | 138 DVLOG(2) << "Received invalidation with version " << invalidation.version() |
| 136 << " for " << ObjectIdToString(id); | 139 << " for " << ObjectIdToString(id); |
| 137 | 140 |
| 138 ObjectIdInvalidationMap invalidations; | 141 ObjectIdInvalidationMap invalidations; |
| 139 Invalidation inv = Invalidation::Init(id, invalidation.version(), payload); | 142 Invalidation inv = Invalidation::Init(id, invalidation.version(), payload); |
| 140 inv.SetAckHandler(AsWeakPtr(), base::MessageLoopProxy::current()); | 143 inv.SetAckHandler(AsWeakPtr(), base::ThreadTaskRunnerHandle::Get()); |
| 141 invalidations.Insert(inv); | 144 invalidations.Insert(inv); |
| 142 | 145 |
| 143 DispatchInvalidations(invalidations); | 146 DispatchInvalidations(invalidations); |
| 144 } | 147 } |
| 145 | 148 |
| 146 void SyncInvalidationListener::InvalidateUnknownVersion( | 149 void SyncInvalidationListener::InvalidateUnknownVersion( |
| 147 invalidation::InvalidationClient* client, | 150 invalidation::InvalidationClient* client, |
| 148 const invalidation::ObjectId& object_id, | 151 const invalidation::ObjectId& object_id, |
| 149 const invalidation::AckHandle& ack_handle) { | 152 const invalidation::AckHandle& ack_handle) { |
| 150 DCHECK(CalledOnValidThread()); | 153 DCHECK(CalledOnValidThread()); |
| 151 DCHECK_EQ(client, invalidation_client_.get()); | 154 DCHECK_EQ(client, invalidation_client_.get()); |
| 152 DVLOG(1) << "InvalidateUnknownVersion"; | 155 DVLOG(1) << "InvalidateUnknownVersion"; |
| 153 client->Acknowledge(ack_handle); | 156 client->Acknowledge(ack_handle); |
| 154 | 157 |
| 155 ObjectIdInvalidationMap invalidations; | 158 ObjectIdInvalidationMap invalidations; |
| 156 Invalidation unknown_version = Invalidation::InitUnknownVersion(object_id); | 159 Invalidation unknown_version = Invalidation::InitUnknownVersion(object_id); |
| 157 unknown_version.SetAckHandler(AsWeakPtr(), base::MessageLoopProxy::current()); | 160 unknown_version.SetAckHandler(AsWeakPtr(), |
| 161 base::ThreadTaskRunnerHandle::Get()); |
| 158 invalidations.Insert(unknown_version); | 162 invalidations.Insert(unknown_version); |
| 159 | 163 |
| 160 DispatchInvalidations(invalidations); | 164 DispatchInvalidations(invalidations); |
| 161 } | 165 } |
| 162 | 166 |
| 163 // This should behave as if we got an invalidation with version | 167 // This should behave as if we got an invalidation with version |
| 164 // UNKNOWN_OBJECT_VERSION for all known data types. | 168 // UNKNOWN_OBJECT_VERSION for all known data types. |
| 165 void SyncInvalidationListener::InvalidateAll( | 169 void SyncInvalidationListener::InvalidateAll( |
| 166 invalidation::InvalidationClient* client, | 170 invalidation::InvalidationClient* client, |
| 167 const invalidation::AckHandle& ack_handle) { | 171 const invalidation::AckHandle& ack_handle) { |
| 168 DCHECK(CalledOnValidThread()); | 172 DCHECK(CalledOnValidThread()); |
| 169 DCHECK_EQ(client, invalidation_client_.get()); | 173 DCHECK_EQ(client, invalidation_client_.get()); |
| 170 DVLOG(1) << "InvalidateAll"; | 174 DVLOG(1) << "InvalidateAll"; |
| 171 client->Acknowledge(ack_handle); | 175 client->Acknowledge(ack_handle); |
| 172 | 176 |
| 173 ObjectIdInvalidationMap invalidations; | 177 ObjectIdInvalidationMap invalidations; |
| 174 for (ObjectIdSet::iterator it = registered_ids_.begin(); | 178 for (ObjectIdSet::iterator it = registered_ids_.begin(); |
| 175 it != registered_ids_.end(); ++it) { | 179 it != registered_ids_.end(); ++it) { |
| 176 Invalidation unknown_version = Invalidation::InitUnknownVersion(*it); | 180 Invalidation unknown_version = Invalidation::InitUnknownVersion(*it); |
| 177 unknown_version.SetAckHandler(AsWeakPtr(), | 181 unknown_version.SetAckHandler(AsWeakPtr(), |
| 178 base::MessageLoopProxy::current()); | 182 base::ThreadTaskRunnerHandle::Get()); |
| 179 invalidations.Insert(unknown_version); | 183 invalidations.Insert(unknown_version); |
| 180 } | 184 } |
| 181 | 185 |
| 182 DispatchInvalidations(invalidations); | 186 DispatchInvalidations(invalidations); |
| 183 } | 187 } |
| 184 | 188 |
| 185 // If a handler is registered, emit right away. Otherwise, save it for later. | 189 // If a handler is registered, emit right away. Otherwise, save it for later. |
| 186 void SyncInvalidationListener::DispatchInvalidations( | 190 void SyncInvalidationListener::DispatchInvalidations( |
| 187 const ObjectIdInvalidationMap& invalidations) { | 191 const ObjectIdInvalidationMap& invalidations) { |
| 188 DCHECK(CalledOnValidThread()); | 192 DCHECK(CalledOnValidThread()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 unacked_invalidations_map_)); | 355 unacked_invalidations_map_)); |
| 352 | 356 |
| 353 ObjectIdInvalidationMap object_id_invalidation_map; | 357 ObjectIdInvalidationMap object_id_invalidation_map; |
| 354 for (UnackedInvalidationsMap::iterator map_it = | 358 for (UnackedInvalidationsMap::iterator map_it = |
| 355 unacked_invalidations_map_.begin(); | 359 unacked_invalidations_map_.begin(); |
| 356 map_it != unacked_invalidations_map_.end(); ++map_it) { | 360 map_it != unacked_invalidations_map_.end(); ++map_it) { |
| 357 if (registered_ids_.find(map_it->first) == registered_ids_.end()) { | 361 if (registered_ids_.find(map_it->first) == registered_ids_.end()) { |
| 358 continue; | 362 continue; |
| 359 } | 363 } |
| 360 map_it->second.ExportInvalidations(AsWeakPtr(), | 364 map_it->second.ExportInvalidations(AsWeakPtr(), |
| 361 base::MessageLoopProxy::current(), | 365 base::ThreadTaskRunnerHandle::Get(), |
| 362 &object_id_invalidation_map); | 366 &object_id_invalidation_map); |
| 363 } | 367 } |
| 364 | 368 |
| 365 // There's no need to run these through DispatchInvalidations(); they've | 369 // There's no need to run these through DispatchInvalidations(); they've |
| 366 // already been saved to storage (that's where we found them) so all we need | 370 // already been saved to storage (that's where we found them) so all we need |
| 367 // to do now is emit them. | 371 // to do now is emit them. |
| 368 EmitSavedInvalidations(object_id_invalidation_map); | 372 EmitSavedInvalidations(object_id_invalidation_map); |
| 369 } | 373 } |
| 370 | 374 |
| 371 void SyncInvalidationListener::RequestDetailedStatus( | 375 void SyncInvalidationListener::RequestDetailedStatus( |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 } | 452 } |
| 449 | 453 |
| 450 void SyncInvalidationListener::OnNetworkChannelStateChanged( | 454 void SyncInvalidationListener::OnNetworkChannelStateChanged( |
| 451 InvalidatorState invalidator_state) { | 455 InvalidatorState invalidator_state) { |
| 452 DCHECK(CalledOnValidThread()); | 456 DCHECK(CalledOnValidThread()); |
| 453 push_client_state_ = invalidator_state; | 457 push_client_state_ = invalidator_state; |
| 454 EmitStateChange(); | 458 EmitStateChange(); |
| 455 } | 459 } |
| 456 | 460 |
| 457 } // namespace syncer | 461 } // namespace syncer |
| OLD | NEW |