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 // A class that manages the registration of types for server-issued | 5 // A class that manages the registration of types for server-issued |
6 // notifications. | 6 // notifications. |
7 | 7 |
8 #ifndef COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ | 8 #ifndef COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ |
9 #define COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ | 9 #define COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
| 12 #include <memory> |
12 | 13 |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/threading/non_thread_safe.h" | 15 #include "base/threading/non_thread_safe.h" |
15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
17 // For invalidation::InvalidationListener::RegistrationState. | 18 // For invalidation::InvalidationListener::RegistrationState. |
18 #include "components/invalidation/public/invalidation_export.h" | 19 #include "components/invalidation/public/invalidation_export.h" |
19 #include "components/invalidation/public/invalidation_util.h" | 20 #include "components/invalidation/public/invalidation_util.h" |
20 #include "google/cacheinvalidation/include/invalidation-listener.h" | 21 #include "google/cacheinvalidation/include/invalidation-listener.h" |
21 #include "google/cacheinvalidation/include/types.h" | 22 #include "google/cacheinvalidation/include/types.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // negative). | 141 // negative). |
141 base::TimeDelta delay; | 142 base::TimeDelta delay; |
142 // The minimum time to wait until any next registration attempt. | 143 // The minimum time to wait until any next registration attempt. |
143 // Increased after each consecutive failure. | 144 // Increased after each consecutive failure. |
144 base::TimeDelta next_delay; | 145 base::TimeDelta next_delay; |
145 // The actual timer for registration. | 146 // The actual timer for registration. |
146 base::OneShotTimer registration_timer; | 147 base::OneShotTimer registration_timer; |
147 | 148 |
148 DISALLOW_COPY_AND_ASSIGN(RegistrationStatus); | 149 DISALLOW_COPY_AND_ASSIGN(RegistrationStatus); |
149 }; | 150 }; |
150 typedef std::map<invalidation::ObjectId, | |
151 RegistrationStatus*, | |
152 ObjectIdLessThan> | |
153 RegistrationStatusMap; | |
154 | 151 |
155 // Does nothing if the given id is disabled. Otherwise, if | 152 // Does nothing if the given id is disabled. Otherwise, if |
156 // |is_retry| is not set, registers the given type immediately and | 153 // |is_retry| is not set, registers the given type immediately and |
157 // resets all backoff parameters. If |is_retry| is set, registers | 154 // resets all backoff parameters. If |is_retry| is set, registers |
158 // the given type at some point in the future and increases the | 155 // the given type at some point in the future and increases the |
159 // delay until the next retry. | 156 // delay until the next retry. |
160 void TryRegisterId(const invalidation::ObjectId& id, | 157 void TryRegisterId(const invalidation::ObjectId& id, |
161 bool is_retry); | 158 bool is_retry); |
162 | 159 |
163 // Registers the given id, which must be valid, immediately. | 160 // Registers the given id, which must be valid, immediately. |
164 // Updates |last_registration| in the appropriate | 161 // Updates |last_registration| in the appropriate |
165 // RegistrationStatus. Should only be called by | 162 // RegistrationStatus. Should only be called by |
166 // RegistrationStatus::DoRegister(). | 163 // RegistrationStatus::DoRegister(). |
167 void DoRegisterId(const invalidation::ObjectId& id); | 164 void DoRegisterId(const invalidation::ObjectId& id); |
168 | 165 |
169 // Unregisters the given object ID. | 166 // Unregisters the given object ID. |
170 void UnregisterId(const invalidation::ObjectId& id); | 167 void UnregisterId(const invalidation::ObjectId& id); |
171 | 168 |
172 // Gets all currently registered ids. | 169 // Gets all currently registered ids. |
173 ObjectIdSet GetRegisteredIds() const; | 170 ObjectIdSet GetRegisteredIds() const; |
174 | 171 |
175 // Returns true iff the given object ID is registered. | 172 // Returns true iff the given object ID is registered. |
176 bool IsIdRegistered(const invalidation::ObjectId& id) const; | 173 bool IsIdRegistered(const invalidation::ObjectId& id) const; |
177 | 174 |
178 RegistrationStatusMap registration_statuses_; | 175 std::map<invalidation::ObjectId, |
| 176 std::unique_ptr<RegistrationStatus>, |
| 177 ObjectIdLessThan> |
| 178 registration_statuses_; |
179 // Weak pointer. | 179 // Weak pointer. |
180 invalidation::InvalidationClient* invalidation_client_; | 180 invalidation::InvalidationClient* invalidation_client_; |
181 | 181 |
182 DISALLOW_COPY_AND_ASSIGN(RegistrationManager); | 182 DISALLOW_COPY_AND_ASSIGN(RegistrationManager); |
183 }; | 183 }; |
184 | 184 |
185 } // namespace syncer | 185 } // namespace syncer |
186 | 186 |
187 #endif // COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ | 187 #endif // COMPONENTS_INVALIDATION_IMPL_REGISTRATION_MANAGER_H_ |
OLD | NEW |