| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 invalidation_state_tracker_.Call( | 154 invalidation_state_tracker_.Call( |
| 155 FROM_HERE, | 155 FROM_HERE, |
| 156 &InvalidationStateTracker::SetMaxVersion, | 156 &InvalidationStateTracker::SetMaxVersion, |
| 157 id, invalidation.version()); | 157 id, invalidation.version()); |
| 158 | 158 |
| 159 std::string payload; | 159 std::string payload; |
| 160 // payload() CHECK()'s has_payload(), so we must check it ourselves first. | 160 // payload() CHECK()'s has_payload(), so we must check it ourselves first. |
| 161 if (invalidation.has_payload()) | 161 if (invalidation.has_payload()) |
| 162 payload = invalidation.payload(); | 162 payload = invalidation.payload(); |
| 163 | 163 |
| 164 ObjectIdStateMap id_state_map; | 164 ObjectIdInvalidationMap invalidation_map; |
| 165 id_state_map[id].payload = payload; | 165 invalidation_map[id].payload = payload; |
| 166 EmitInvalidation(id_state_map); | 166 EmitInvalidation(invalidation_map); |
| 167 // TODO(akalin): We should really acknowledge only after we get the | 167 // TODO(akalin): We should really acknowledge only after we get the |
| 168 // updates from the sync server. (see http://crbug.com/78462). | 168 // updates from the sync server. (see http://crbug.com/78462). |
| 169 client->Acknowledge(ack_handle); | 169 client->Acknowledge(ack_handle); |
| 170 } | 170 } |
| 171 | 171 |
| 172 void SyncInvalidationListener::InvalidateUnknownVersion( | 172 void SyncInvalidationListener::InvalidateUnknownVersion( |
| 173 invalidation::InvalidationClient* client, | 173 invalidation::InvalidationClient* client, |
| 174 const invalidation::ObjectId& object_id, | 174 const invalidation::ObjectId& object_id, |
| 175 const invalidation::AckHandle& ack_handle) { | 175 const invalidation::AckHandle& ack_handle) { |
| 176 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
| 177 DCHECK_EQ(client, invalidation_client_.get()); | 177 DCHECK_EQ(client, invalidation_client_.get()); |
| 178 DVLOG(1) << "InvalidateUnknownVersion"; | 178 DVLOG(1) << "InvalidateUnknownVersion"; |
| 179 | 179 |
| 180 ObjectIdStateMap id_state_map; | 180 ObjectIdInvalidationMap invalidation_map; |
| 181 id_state_map[object_id].payload = std::string(); | 181 invalidation_map[object_id].payload = std::string(); |
| 182 EmitInvalidation(id_state_map); | 182 EmitInvalidation(invalidation_map); |
| 183 // TODO(akalin): We should really acknowledge only after we get the | 183 // TODO(akalin): We should really acknowledge only after we get the |
| 184 // updates from the sync server. (see http://crbug.com/78462). | 184 // updates from the sync server. (see http://crbug.com/78462). |
| 185 client->Acknowledge(ack_handle); | 185 client->Acknowledge(ack_handle); |
| 186 } | 186 } |
| 187 | 187 |
| 188 // This should behave as if we got an invalidation with version | 188 // This should behave as if we got an invalidation with version |
| 189 // UNKNOWN_OBJECT_VERSION for all known data types. | 189 // UNKNOWN_OBJECT_VERSION for all known data types. |
| 190 void SyncInvalidationListener::InvalidateAll( | 190 void SyncInvalidationListener::InvalidateAll( |
| 191 invalidation::InvalidationClient* client, | 191 invalidation::InvalidationClient* client, |
| 192 const invalidation::AckHandle& ack_handle) { | 192 const invalidation::AckHandle& ack_handle) { |
| 193 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 194 DCHECK_EQ(client, invalidation_client_.get()); | 194 DCHECK_EQ(client, invalidation_client_.get()); |
| 195 DVLOG(1) << "InvalidateAll"; | 195 DVLOG(1) << "InvalidateAll"; |
| 196 | 196 |
| 197 ObjectIdStateMap id_state_map; | 197 const ObjectIdInvalidationMap& invalidation_map = |
| 198 for (ObjectIdSet::const_iterator it = registered_ids_.begin(); | 198 ObjectIdSetToInvalidationMap(registered_ids_, std::string()); |
| 199 it != registered_ids_.end(); ++it) { | 199 EmitInvalidation(invalidation_map); |
| 200 id_state_map[*it].payload = std::string(); | |
| 201 } | |
| 202 EmitInvalidation(id_state_map); | |
| 203 // TODO(akalin): We should really acknowledge only after we get the | 200 // TODO(akalin): We should really acknowledge only after we get the |
| 204 // updates from the sync server. (see http://crbug.com/76482). | 201 // updates from the sync server. (see http://crbug.com/76482). |
| 205 client->Acknowledge(ack_handle); | 202 client->Acknowledge(ack_handle); |
| 206 } | 203 } |
| 207 | 204 |
| 208 void SyncInvalidationListener::EmitInvalidation( | 205 void SyncInvalidationListener::EmitInvalidation( |
| 209 const ObjectIdStateMap& id_state_map) { | 206 const ObjectIdInvalidationMap& invalidation_map) { |
| 210 DCHECK(CalledOnValidThread()); | 207 DCHECK(CalledOnValidThread()); |
| 211 delegate_->OnInvalidate(id_state_map); | 208 delegate_->OnInvalidate(invalidation_map); |
| 212 } | 209 } |
| 213 | 210 |
| 214 void SyncInvalidationListener::InformRegistrationStatus( | 211 void SyncInvalidationListener::InformRegistrationStatus( |
| 215 invalidation::InvalidationClient* client, | 212 invalidation::InvalidationClient* client, |
| 216 const invalidation::ObjectId& object_id, | 213 const invalidation::ObjectId& object_id, |
| 217 InvalidationListener::RegistrationState new_state) { | 214 InvalidationListener::RegistrationState new_state) { |
| 218 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
| 219 DCHECK_EQ(client, invalidation_client_.get()); | 216 DCHECK_EQ(client, invalidation_client_.get()); |
| 220 DVLOG(1) << "InformRegistrationStatus: " | 217 DVLOG(1) << "InformRegistrationStatus: " |
| 221 << ObjectIdToString(object_id) << " " << new_state; | 218 << ObjectIdToString(object_id) << " " << new_state; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 EmitStateChange(); | 353 EmitStateChange(); |
| 357 } | 354 } |
| 358 | 355 |
| 359 void SyncInvalidationListener::OnIncomingNotification( | 356 void SyncInvalidationListener::OnIncomingNotification( |
| 360 const notifier::Notification& notification) { | 357 const notifier::Notification& notification) { |
| 361 DCHECK(CalledOnValidThread()); | 358 DCHECK(CalledOnValidThread()); |
| 362 // Do nothing, since this is already handled by |invalidation_client_|. | 359 // Do nothing, since this is already handled by |invalidation_client_|. |
| 363 } | 360 } |
| 364 | 361 |
| 365 } // namespace syncer | 362 } // namespace syncer |
| OLD | NEW |