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

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

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

Powered by Google App Engine
This is Rietveld 408576698