| 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/impl/registration_manager.h" | 5 #include "components/invalidation/impl/registration_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cstddef> | 10 #include <cstddef> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 const int RegistrationManager::kMaxRegistrationDelaySeconds = 60 * 60; | 58 const int RegistrationManager::kMaxRegistrationDelaySeconds = 60 * 60; |
| 59 | 59 |
| 60 RegistrationManager::RegistrationManager( | 60 RegistrationManager::RegistrationManager( |
| 61 invalidation::InvalidationClient* invalidation_client) | 61 invalidation::InvalidationClient* invalidation_client) |
| 62 : invalidation_client_(invalidation_client) { | 62 : invalidation_client_(invalidation_client) { |
| 63 DCHECK(invalidation_client_); | 63 DCHECK(invalidation_client_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 RegistrationManager::~RegistrationManager() { | 66 RegistrationManager::~RegistrationManager() { |
| 67 DCHECK(CalledOnValidThread()); | 67 DCHECK(CalledOnValidThread()); |
| 68 STLDeleteValues(®istration_statuses_); | 68 base::STLDeleteValues(®istration_statuses_); |
| 69 } | 69 } |
| 70 | 70 |
| 71 ObjectIdSet RegistrationManager::UpdateRegisteredIds(const ObjectIdSet& ids) { | 71 ObjectIdSet RegistrationManager::UpdateRegisteredIds(const ObjectIdSet& ids) { |
| 72 DCHECK(CalledOnValidThread()); | 72 DCHECK(CalledOnValidThread()); |
| 73 | 73 |
| 74 const ObjectIdSet& old_ids = GetRegisteredIds(); | 74 const ObjectIdSet& old_ids = GetRegisteredIds(); |
| 75 const ObjectIdSet& to_register = ids; | 75 const ObjectIdSet& to_register = ids; |
| 76 ObjectIdSet to_unregister; | 76 ObjectIdSet to_unregister; |
| 77 std::set_difference(old_ids.begin(), old_ids.end(), | 77 std::set_difference(old_ids.begin(), old_ids.end(), |
| 78 ids.begin(), ids.end(), | 78 ids.begin(), ids.end(), |
| 79 std::inserter(to_unregister, to_unregister.begin()), | 79 std::inserter(to_unregister, to_unregister.begin()), |
| 80 ObjectIdLessThan()); | 80 ObjectIdLessThan()); |
| 81 | 81 |
| 82 for (ObjectIdSet::const_iterator it = to_unregister.begin(); | 82 for (ObjectIdSet::const_iterator it = to_unregister.begin(); |
| 83 it != to_unregister.end(); ++it) { | 83 it != to_unregister.end(); ++it) { |
| 84 UnregisterId(*it); | 84 UnregisterId(*it); |
| 85 } | 85 } |
| 86 | 86 |
| 87 for (ObjectIdSet::const_iterator it = to_register.begin(); | 87 for (ObjectIdSet::const_iterator it = to_register.begin(); |
| 88 it != to_register.end(); ++it) { | 88 it != to_register.end(); ++it) { |
| 89 if (!ContainsKey(registration_statuses_, *it)) { | 89 if (!base::ContainsKey(registration_statuses_, *it)) { |
| 90 registration_statuses_.insert( | 90 registration_statuses_.insert( |
| 91 std::make_pair(*it, new RegistrationStatus(*it, this))); | 91 std::make_pair(*it, new RegistrationStatus(*it, this))); |
| 92 } | 92 } |
| 93 if (!IsIdRegistered(*it)) { | 93 if (!IsIdRegistered(*it)) { |
| 94 TryRegisterId(*it, false /* is-retry */); | 94 TryRegisterId(*it, false /* is-retry */); |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 return to_unregister; | 98 return to_unregister; |
| 99 } | 99 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 bool RegistrationManager::IsIdRegistered( | 298 bool RegistrationManager::IsIdRegistered( |
| 299 const invalidation::ObjectId& id) const { | 299 const invalidation::ObjectId& id) const { |
| 300 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
| 301 RegistrationStatusMap::const_iterator it = | 301 RegistrationStatusMap::const_iterator it = |
| 302 registration_statuses_.find(id); | 302 registration_statuses_.find(id); |
| 303 return it != registration_statuses_.end() && | 303 return it != registration_statuses_.end() && |
| 304 it->second->state == invalidation::InvalidationListener::REGISTERED; | 304 it->second->state == invalidation::InvalidationListener::REGISTERED; |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace syncer | 307 } // namespace syncer |
| OLD | NEW |