OLD | NEW |
---|---|
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> | |
msw
2012/08/03 23:30:46
ditto nit/question for basictypes.h
akalin
2012/08/07 07:25:19
ditto
| |
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 { |
17 | 19 |
20 namespace { | |
21 | |
22 const char kHandlerName[] = "NonBlockingInvalidationHandler"; | |
23 | |
24 } // namespace | |
25 | |
18 class NonBlockingInvalidationNotifier::Core | 26 class NonBlockingInvalidationNotifier::Core |
19 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, | 27 : public base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>, |
20 // SyncNotifierObserver to observe the InvalidationNotifier we create. | 28 // SyncNotifierObserver to observe the InvalidationNotifier we create. |
21 public SyncNotifierObserver { | 29 public SyncNotifierObserver { |
22 public: | 30 public: |
23 // Called on parent thread. |delegate_observer| should be | 31 // Called on parent thread. |delegate_observer| should be |
24 // initialized. | 32 // initialized. |
25 explicit Core( | 33 explicit Core( |
26 const WeakHandle<SyncNotifierObserver>& delegate_observer); | 34 const WeakHandle<SyncNotifierObserver>& delegate_observer); |
27 | 35 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 network_task_runner_ = notifier_options.request_context_getter-> | 90 network_task_runner_ = notifier_options.request_context_getter-> |
83 GetNetworkTaskRunner(); | 91 GetNetworkTaskRunner(); |
84 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 92 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
85 invalidation_notifier_.reset( | 93 invalidation_notifier_.reset( |
86 new InvalidationNotifier( | 94 new InvalidationNotifier( |
87 notifier::PushClient::CreateDefaultOnIOThread(notifier_options), | 95 notifier::PushClient::CreateDefaultOnIOThread(notifier_options), |
88 initial_max_invalidation_versions, | 96 initial_max_invalidation_versions, |
89 initial_invalidation_state, | 97 initial_invalidation_state, |
90 invalidation_state_tracker, | 98 invalidation_state_tracker, |
91 client_info)); | 99 client_info)); |
100 invalidation_notifier_->SetHandler(kHandlerName, this); | |
92 } | 101 } |
93 | 102 |
94 | |
95 void NonBlockingInvalidationNotifier::Core::Teardown() { | 103 void NonBlockingInvalidationNotifier::Core::Teardown() { |
96 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 104 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
97 invalidation_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); | 105 invalidation_notifier_->SetHandler(kHandlerName, NULL); |
98 invalidation_notifier_.reset(); | 106 invalidation_notifier_.reset(); |
99 network_task_runner_ = NULL; | 107 network_task_runner_ = NULL; |
100 } | 108 } |
101 | 109 |
102 void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds( | 110 void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds( |
103 const ObjectIdSet& ids) { | 111 const ObjectIdSet& ids) { |
104 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 112 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
105 invalidation_notifier_->UpdateRegisteredIds(this, ids); | 113 invalidation_notifier_->UpdateRegisteredIds(kHandlerName, ids); |
106 } | 114 } |
107 | 115 |
108 void NonBlockingInvalidationNotifier::Core::SetUniqueId( | 116 void NonBlockingInvalidationNotifier::Core::SetUniqueId( |
109 const std::string& unique_id) { | 117 const std::string& unique_id) { |
110 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 118 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
111 invalidation_notifier_->SetUniqueId(unique_id); | 119 invalidation_notifier_->SetUniqueId(unique_id); |
112 } | 120 } |
113 | 121 |
114 void NonBlockingInvalidationNotifier::Core::SetStateDeprecated( | 122 void NonBlockingInvalidationNotifier::Core::SetStateDeprecated( |
115 const std::string& state) { | 123 const std::string& state) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { | 184 NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { |
177 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 185 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
178 if (!network_task_runner_->PostTask( | 186 if (!network_task_runner_->PostTask( |
179 FROM_HERE, | 187 FROM_HERE, |
180 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, | 188 base::Bind(&NonBlockingInvalidationNotifier::Core::Teardown, |
181 core_.get()))) { | 189 core_.get()))) { |
182 NOTREACHED(); | 190 NOTREACHED(); |
183 } | 191 } |
184 } | 192 } |
185 | 193 |
194 void NonBlockingInvalidationNotifier::SetHandler( | |
195 const std::string& handler_name, | |
196 SyncNotifierObserver* handler) { | |
197 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | |
198 helper_.SetHandler(handler_name, handler); | |
199 } | |
200 | |
186 void NonBlockingInvalidationNotifier::UpdateRegisteredIds( | 201 void NonBlockingInvalidationNotifier::UpdateRegisteredIds( |
187 SyncNotifierObserver* handler, const ObjectIdSet& ids) { | 202 const std::string& handler_name, const ObjectIdSet& ids) { |
188 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 203 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
189 const ObjectIdSet& all_registered_ids = | 204 helper_.UpdateRegisteredIds(handler_name, ids); |
190 helper_.UpdateRegisteredIds(handler, ids); | 205 const ObjectIdSet& all_registered_ids = helper_.GetAllRegisteredIds(); |
191 if (!network_task_runner_->PostTask( | 206 if (!network_task_runner_->PostTask( |
192 FROM_HERE, | 207 FROM_HERE, |
193 base::Bind( | 208 base::Bind( |
194 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, | 209 &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, |
195 core_.get(), | 210 core_.get(), |
196 all_registered_ids))) { | 211 all_registered_ids))) { |
197 NOTREACHED(); | 212 NOTREACHED(); |
198 } | 213 } |
199 } | 214 } |
200 | 215 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 helper_.DispatchInvalidationsToHandlers(id_payloads, source); |
258 } | 273 } |
259 | 274 |
260 } // namespace syncer | 275 } // namespace syncer |
OLD | NEW |