| 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/chrome_invalidation_client.h" | 5 #include "sync/notifier/chrome_invalidation_client.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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 chrome_system_resources_.network()->UpdateCredentials(email, token); | 102 chrome_system_resources_.network()->UpdateCredentials(email, token); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void ChromeInvalidationClient::UpdateRegisteredIds(const ObjectIdSet& ids) { | 105 void ChromeInvalidationClient::UpdateRegisteredIds(const ObjectIdSet& ids) { |
| 106 DCHECK(CalledOnValidThread()); | 106 DCHECK(CalledOnValidThread()); |
| 107 registered_ids_ = ids; | 107 registered_ids_ = ids; |
| 108 // |ticl_state_| can go to NO_NOTIFICATION_ERROR even without a | 108 // |ticl_state_| can go to NO_NOTIFICATION_ERROR even without a |
| 109 // working XMPP connection (as observed by us), so check it instead | 109 // working XMPP connection (as observed by us), so check it instead |
| 110 // of GetState() (see http://crbug.com/139424). | 110 // of GetState() (see http://crbug.com/139424). |
| 111 if (ticl_state_ == NO_NOTIFICATION_ERROR && registration_manager_.get()) { | 111 if (ticl_state_ == NO_NOTIFICATION_ERROR && registration_manager_.get()) { |
| 112 registration_manager_->UpdateRegisteredIds(registered_ids_); | 112 DoRegistrationUpdate(); |
| 113 } | 113 } |
| 114 // TODO(akalin): Clear invalidation versions for unregistered types. | |
| 115 } | 114 } |
| 116 | 115 |
| 117 void ChromeInvalidationClient::Ready( | 116 void ChromeInvalidationClient::Ready( |
| 118 invalidation::InvalidationClient* client) { | 117 invalidation::InvalidationClient* client) { |
| 119 DCHECK(CalledOnValidThread()); | 118 DCHECK(CalledOnValidThread()); |
| 120 DCHECK_EQ(client, invalidation_client_.get()); | 119 DCHECK_EQ(client, invalidation_client_.get()); |
| 121 ticl_state_ = NO_NOTIFICATION_ERROR; | 120 ticl_state_ = NO_NOTIFICATION_ERROR; |
| 122 EmitStateChange(); | 121 EmitStateChange(); |
| 123 registration_manager_->UpdateRegisteredIds(registered_ids_); | 122 DoRegistrationUpdate(); |
| 124 } | 123 } |
| 125 | 124 |
| 126 void ChromeInvalidationClient::Invalidate( | 125 void ChromeInvalidationClient::Invalidate( |
| 127 invalidation::InvalidationClient* client, | 126 invalidation::InvalidationClient* client, |
| 128 const invalidation::Invalidation& invalidation, | 127 const invalidation::Invalidation& invalidation, |
| 129 const invalidation::AckHandle& ack_handle) { | 128 const invalidation::AckHandle& ack_handle) { |
| 130 DCHECK(CalledOnValidThread()); | 129 DCHECK(CalledOnValidThread()); |
| 131 DCHECK_EQ(client, invalidation_client_.get()); | 130 DCHECK_EQ(client, invalidation_client_.get()); |
| 132 DVLOG(1) << "Invalidate: " << InvalidationToString(invalidation); | 131 DVLOG(1) << "Invalidate: " << InvalidationToString(invalidation); |
| 133 | 132 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 DVLOG(1) << "InformRegistrationFailure: " | 236 DVLOG(1) << "InformRegistrationFailure: " |
| 238 << ObjectIdToString(object_id) | 237 << ObjectIdToString(object_id) |
| 239 << "is_transient=" << is_transient | 238 << "is_transient=" << is_transient |
| 240 << ", message=" << error_message; | 239 << ", message=" << error_message; |
| 241 | 240 |
| 242 if (is_transient) { | 241 if (is_transient) { |
| 243 // We don't care about |unknown_hint|; we let | 242 // We don't care about |unknown_hint|; we let |
| 244 // |registration_manager_| handle the registration backoff policy. | 243 // |registration_manager_| handle the registration backoff policy. |
| 245 registration_manager_->MarkRegistrationLost(object_id); | 244 registration_manager_->MarkRegistrationLost(object_id); |
| 246 } else { | 245 } else { |
| 247 // Non-transient failures are permanent, so block any future | 246 // Non-transient failures require an action to resolve. This could happen |
| 248 // registration requests for |model_type|. (This happens if the | 247 // because: |
| 249 // server doesn't recognize the data type, which could happen for | 248 // - the server doesn't yet recognize the data type, which could happen for |
| 250 // brand-new data types.) | 249 // brand-new data types. |
| 250 // - the user has changed his password and hasn't updated it yet locally. |
| 251 // Either way, block future registration attempts for |object_id|. However, |
| 252 // we don't forget any saved invalidation state since we may use it once the |
| 253 // error is addressed. |
| 251 registration_manager_->DisableId(object_id); | 254 registration_manager_->DisableId(object_id); |
| 252 } | 255 } |
| 253 } | 256 } |
| 254 | 257 |
| 255 void ChromeInvalidationClient::ReissueRegistrations( | 258 void ChromeInvalidationClient::ReissueRegistrations( |
| 256 invalidation::InvalidationClient* client, | 259 invalidation::InvalidationClient* client, |
| 257 const std::string& prefix, | 260 const std::string& prefix, |
| 258 int prefix_length) { | 261 int prefix_length) { |
| 259 DCHECK(CalledOnValidThread()); | 262 DCHECK(CalledOnValidThread()); |
| 260 DCHECK_EQ(client, invalidation_client_.get()); | 263 DCHECK_EQ(client, invalidation_client_.get()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 278 EmitStateChange(); | 281 EmitStateChange(); |
| 279 } | 282 } |
| 280 | 283 |
| 281 void ChromeInvalidationClient::WriteState(const std::string& state) { | 284 void ChromeInvalidationClient::WriteState(const std::string& state) { |
| 282 DCHECK(CalledOnValidThread()); | 285 DCHECK(CalledOnValidThread()); |
| 283 DVLOG(1) << "WriteState"; | 286 DVLOG(1) << "WriteState"; |
| 284 invalidation_state_tracker_.Call( | 287 invalidation_state_tracker_.Call( |
| 285 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state); | 288 FROM_HERE, &InvalidationStateTracker::SetInvalidationState, state); |
| 286 } | 289 } |
| 287 | 290 |
| 291 void ChromeInvalidationClient::DoRegistrationUpdate() { |
| 292 DCHECK(CalledOnValidThread()); |
| 293 const ObjectIdSet& unregistered_ids = |
| 294 registration_manager_->UpdateRegisteredIds(registered_ids_); |
| 295 invalidation_state_tracker_.Call( |
| 296 FROM_HERE, &InvalidationStateTracker::Forget, unregistered_ids); |
| 297 } |
| 298 |
| 288 void ChromeInvalidationClient::StopForTest() { | 299 void ChromeInvalidationClient::StopForTest() { |
| 289 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
| 290 Stop(); | 301 Stop(); |
| 291 } | 302 } |
| 292 | 303 |
| 293 void ChromeInvalidationClient::Stop() { | 304 void ChromeInvalidationClient::Stop() { |
| 294 DCHECK(CalledOnValidThread()); | 305 DCHECK(CalledOnValidThread()); |
| 295 if (!invalidation_client_.get()) { | 306 if (!invalidation_client_.get()) { |
| 296 return; | 307 return; |
| 297 } | 308 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 EmitStateChange(); | 360 EmitStateChange(); |
| 350 } | 361 } |
| 351 | 362 |
| 352 void ChromeInvalidationClient::OnIncomingNotification( | 363 void ChromeInvalidationClient::OnIncomingNotification( |
| 353 const notifier::Notification& notification) { | 364 const notifier::Notification& notification) { |
| 354 DCHECK(CalledOnValidThread()); | 365 DCHECK(CalledOnValidThread()); |
| 355 // Do nothing, since this is already handled by |invalidation_client_|. | 366 // Do nothing, since this is already handled by |invalidation_client_|. |
| 356 } | 367 } |
| 357 | 368 |
| 358 } // namespace syncer | 369 } // namespace syncer |
| OLD | NEW |