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

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: Work around brittle unit test 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);
191 if (!network_task_runner_->PostTask( 199 if (!network_task_runner_->PostTask(
192 FROM_HERE, 200 FROM_HERE,
193 base::Bind( 201 base::Bind(
194 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, 202 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds,
195 core_.get(), 203 core_.get(),
196 all_registered_ids))) { 204 registrar_.GetAllRegisteredIds()))) {
197 NOTREACHED(); 205 NOTREACHED();
198 } 206 }
199 } 207 }
200 208
209 void NonBlockingInvalidationNotifier::UnregisterHandler(
210 SyncNotifierObserver* handler) {
211 DCHECK(parent_task_runner_->BelongsToCurrentThread());
212 registrar_.UnregisterHandler(handler);
213 }
214
201 void NonBlockingInvalidationNotifier::SetUniqueId( 215 void NonBlockingInvalidationNotifier::SetUniqueId(
202 const std::string& unique_id) { 216 const std::string& unique_id) {
203 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 217 DCHECK(parent_task_runner_->BelongsToCurrentThread());
204 if (!network_task_runner_->PostTask( 218 if (!network_task_runner_->PostTask(
205 FROM_HERE, 219 FROM_HERE,
206 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId, 220 base::Bind(&NonBlockingInvalidationNotifier::Core::SetUniqueId,
207 core_.get(), unique_id))) { 221 core_.get(), unique_id))) {
208 NOTREACHED(); 222 NOTREACHED();
209 } 223 }
210 } 224 }
(...skipping 23 matching lines...) Expand all
234 248
235 void NonBlockingInvalidationNotifier::SendNotification( 249 void NonBlockingInvalidationNotifier::SendNotification(
236 ModelTypeSet changed_types) { 250 ModelTypeSet changed_types) {
237 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 251 DCHECK(parent_task_runner_->BelongsToCurrentThread());
238 // InvalidationClient doesn't implement SendNotification(), so no 252 // InvalidationClient doesn't implement SendNotification(), so no
239 // need to forward on the call. 253 // need to forward on the call.
240 } 254 }
241 255
242 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { 256 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() {
243 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 257 DCHECK(parent_task_runner_->BelongsToCurrentThread());
244 helper_.EmitOnNotificationsEnabled(); 258 registrar_.EmitOnNotificationsEnabled();
245 } 259 }
246 260
247 void NonBlockingInvalidationNotifier::OnNotificationsDisabled( 261 void NonBlockingInvalidationNotifier::OnNotificationsDisabled(
248 NotificationsDisabledReason reason) { 262 NotificationsDisabledReason reason) {
249 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 263 DCHECK(parent_task_runner_->BelongsToCurrentThread());
250 helper_.EmitOnNotificationsDisabled(reason); 264 registrar_.EmitOnNotificationsDisabled(reason);
251 } 265 }
252 266
253 void NonBlockingInvalidationNotifier::OnIncomingNotification( 267 void NonBlockingInvalidationNotifier::OnIncomingNotification(
254 const ObjectIdPayloadMap& id_payloads, 268 const ObjectIdPayloadMap& id_payloads,
255 IncomingNotificationSource source) { 269 IncomingNotificationSource source) {
256 DCHECK(parent_task_runner_->BelongsToCurrentThread()); 270 DCHECK(parent_task_runner_->BelongsToCurrentThread());
257 helper_.DispatchInvalidationsToHandlers(id_payloads, source); 271 registrar_.DispatchInvalidationsToHandlers(id_payloads, source);
258 } 272 }
259 273
260 } // namespace syncer 274 } // 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