Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: sync/notifier/non_blocking_invalidation_notifier.cc

Issue 10824252: Revert 150990 - [Sync] Avoid unregistering object IDs on shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/non_blocking_invalidation_notifier.h" 5 #include "sync/notifier/non_blocking_invalidation_notifier.h"
6 6
7 #include <cstddef>
8
9 #include "base/location.h" 7 #include "base/location.h"
10 #include "base/logging.h" 8 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
12 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
13 #include "base/thread_task_runner_handle.h" 11 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/thread.h" 12 #include "base/threading/thread.h"
15 #include "jingle/notifier/listener/push_client.h" 13 #include "jingle/notifier/listener/push_client.h"
16 #include "sync/notifier/invalidation_notifier.h" 14 #include "sync/notifier/invalidation_notifier.h"
17 15
18 namespace syncer { 16 namespace syncer {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 network_task_runner_ = notifier_options.request_context_getter-> 82 network_task_runner_ = notifier_options.request_context_getter->
85 GetNetworkTaskRunner(); 83 GetNetworkTaskRunner();
86 DCHECK(network_task_runner_->BelongsToCurrentThread()); 84 DCHECK(network_task_runner_->BelongsToCurrentThread());
87 invalidation_notifier_.reset( 85 invalidation_notifier_.reset(
88 new InvalidationNotifier( 86 new InvalidationNotifier(
89 notifier::PushClient::CreateDefaultOnIOThread(notifier_options), 87 notifier::PushClient::CreateDefaultOnIOThread(notifier_options),
90 initial_max_invalidation_versions, 88 initial_max_invalidation_versions,
91 initial_invalidation_state, 89 initial_invalidation_state,
92 invalidation_state_tracker, 90 invalidation_state_tracker,
93 client_info)); 91 client_info));
94 invalidation_notifier_->RegisterHandler(this);
95 } 92 }
96 93
94
97 void NonBlockingInvalidationNotifier::Core::Teardown() { 95 void NonBlockingInvalidationNotifier::Core::Teardown() {
98 DCHECK(network_task_runner_->BelongsToCurrentThread()); 96 DCHECK(network_task_runner_->BelongsToCurrentThread());
99 invalidation_notifier_->UnregisterHandler(this); 97 invalidation_notifier_->UpdateRegisteredIds(this, ObjectIdSet());
100 invalidation_notifier_.reset(); 98 invalidation_notifier_.reset();
101 network_task_runner_ = NULL; 99 network_task_runner_ = NULL;
102 } 100 }
103 101
104 void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds( 102 void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds(
105 const ObjectIdSet& ids) { 103 const ObjectIdSet& ids) {
106 DCHECK(network_task_runner_->BelongsToCurrentThread()); 104 DCHECK(network_task_runner_->BelongsToCurrentThread());
107 invalidation_notifier_->UpdateRegisteredIds(this, ids); 105 invalidation_notifier_->UpdateRegisteredIds(this, ids);
108 } 106 }
109 107
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { 176 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() {
179 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 177 DCHECK(parent_task_runner_->BelongsToCurrentThread());
180 if (!network_task_runner_->PostTask( 178 if (!network_task_runner_->PostTask(
181 FROM_HERE, 179 FROM_HERE,
182 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, 180 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown,
183 core_.get()))) { 181 core_.get()))) {
184 NOTREACHED(); 182 NOTREACHED();
185 } 183 }
186 } 184 }
187 185
188 void NonBlockingInvalidationNotifier::RegisterHandler( 186 void NonBlockingInvalidationNotifier::UpdateRegisteredIds(
189 SyncNotifierObserver* handler) { 187 SyncNotifierObserver* handler, const ObjectIdSet& ids) {
190 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 188 DCHECK(parent_task_runner_->BelongsToCurrentThread());
191 registrar_.RegisterHandler(handler); 189 const ObjectIdSet& all_registered_ids =
192 } 190 helper_.UpdateRegisteredIds(handler, ids);
193
194 void NonBlockingInvalidationNotifier::UpdateRegisteredIds(
195 SyncNotifierObserver* handler,
196 const ObjectIdSet& ids) {
197 DCHECK(parent_task_runner_->BelongsToCurrentThread());
198 registrar_.UpdateRegisteredIds(handler, ids);
199 if (!network_task_runner_->PostTask( 191 if (!network_task_runner_->PostTask(
200 FROM_HERE, 192 FROM_HERE,
201 base::Bind( 193 base::Bind(
202 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, 194 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds,
203 core_.get(), 195 core_.get(),
204 registrar_.GetAllRegisteredIds()))) { 196 all_registered_ids))) {
205 NOTREACHED(); 197 NOTREACHED();
206 } 198 }
207 } 199 }
208 200
209 void NonBlockingInvalidationNotifier::UnregisterHandler(
210 SyncNotifierObserver* handler) {
211 DCHECK(parent_task_runner_->BelongsToCurrentThread());
212 registrar_.UnregisterHandler(handler);
213 }
214
215 void NonBlockingInvalidationNotifier::SetUniqueId( 201 void NonBlockingInvalidationNotifier::SetUniqueId(
216 const std::string& unique_id) { 202 const std::string& unique_id) {
217 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 203 DCHECK(parent_task_runner_->BelongsToCurrentThread());
218 if (!network_task_runner_->PostTask( 204 if (!network_task_runner_->PostTask(
219 FROM_HERE, 205 FROM_HERE,
220 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, 206 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId,
221 core_.get(), unique_id))) { 207 core_.get(), unique_id))) {
222 NOTREACHED(); 208 NOTREACHED();
223 } 209 }
224 } 210 }
(...skipping 23 matching lines...) Expand all
248 234
249 void NonBlockingInvalidationNotifier::SendNotification( 235 void NonBlockingInvalidationNotifier::SendNotification(
250 ModelTypeSet changed_types) { 236 ModelTypeSet changed_types) {
251 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 237 DCHECK(parent_task_runner_->BelongsToCurrentThread());
252 // InvalidationClient doesn't implement SendNotification(), so no 238 // InvalidationClient doesn't implement SendNotification(), so no
253 // need to forward on the call. 239 // need to forward on the call.
254 } 240 }
255 241
256 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { 242 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() {
257 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 243 DCHECK(parent_task_runner_->BelongsToCurrentThread());
258 registrar_.EmitOnNotificationsEnabled(); 244 helper_.EmitOnNotificationsEnabled();
259 } 245 }
260 246
261 void NonBlockingInvalidationNotifier::OnNotificationsDisabled( 247 void NonBlockingInvalidationNotifier::OnNotificationsDisabled(
262 NotificationsDisabledReason reason) { 248 NotificationsDisabledReason reason) {
263 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 249 DCHECK(parent_task_runner_->BelongsToCurrentThread());
264 registrar_.EmitOnNotificationsDisabled(reason); 250 helper_.EmitOnNotificationsDisabled(reason);
265 } 251 }
266 252
267 void NonBlockingInvalidationNotifier::OnIncomingNotification( 253 void NonBlockingInvalidationNotifier::OnIncomingNotification(
268 const ObjectIdPayloadMap& id_payloads, 254 const ObjectIdPayloadMap& id_payloads,
269 IncomingNotificationSource source) { 255 IncomingNotificationSource source) {
270 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 256 DCHECK(parent_task_runner_->BelongsToCurrentThread());
271 registrar_.DispatchInvalidationsToHandlers(id_payloads, source); 257 helper_.DispatchInvalidationsToHandlers(id_payloads, source);
272 } 258 }
273 259
274 } // namespace syncer 260 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/non_blocking_invalidation_notifier.h ('k') | sync/notifier/non_blocking_invalidation_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698