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

Side by Side Diff: sync/notifier/p2p_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
« no previous file with comments | « sync/notifier/p2p_notifier.h ('k') | sync/notifier/p2p_notifier_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/p2p_notifier.h" 5 #include "sync/notifier/p2p_notifier.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 DCHECK(send_notification_target_ == NOTIFY_OTHERS || 150 DCHECK(send_notification_target_ == NOTIFY_OTHERS ||
151 send_notification_target_ == NOTIFY_ALL); 151 send_notification_target_ == NOTIFY_ALL);
152 push_client_->AddObserver(this); 152 push_client_->AddObserver(this);
153 } 153 }
154 154
155 P2PNotifier::~P2PNotifier() { 155 P2PNotifier::~P2PNotifier() {
156 DCHECK(thread_checker_.CalledOnValidThread()); 156 DCHECK(thread_checker_.CalledOnValidThread());
157 push_client_->RemoveObserver(this); 157 push_client_->RemoveObserver(this);
158 } 158 }
159 159
160 void P2PNotifier::RegisterHandler(SyncNotifierObserver* handler) {
161 DCHECK(thread_checker_.CalledOnValidThread());
162 registrar_.RegisterHandler(handler);
163 }
164
160 void P2PNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, 165 void P2PNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler,
161 const ObjectIdSet& ids) { 166 const ObjectIdSet& ids) {
162 const ModelTypeSet enabled_types = ObjectIdSetToModelTypeSet( 167 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411).
163 helper_.UpdateRegisteredIds(handler, ids)); 168 DCHECK(thread_checker_.CalledOnValidThread());
169 registrar_.UpdateRegisteredIds(handler, ids);
170 const ModelTypeSet enabled_types =
171 ObjectIdSetToModelTypeSet(registrar_.GetAllRegisteredIds());
164 const ModelTypeSet new_enabled_types = 172 const ModelTypeSet new_enabled_types =
165 Difference(enabled_types, enabled_types_); 173 Difference(enabled_types, enabled_types_);
166 const P2PNotificationData notification_data( 174 const P2PNotificationData notification_data(
167 unique_id_, NOTIFY_SELF, new_enabled_types); 175 unique_id_, NOTIFY_SELF, new_enabled_types);
168 SendNotificationData(notification_data); 176 SendNotificationData(notification_data);
169 enabled_types_ = enabled_types; 177 enabled_types_ = enabled_types;
170 } 178 }
171 179
180 void P2PNotifier::UnregisterHandler(SyncNotifierObserver* handler) {
181 DCHECK(thread_checker_.CalledOnValidThread());
182 registrar_.UnregisterHandler(handler);
183 }
184
172 void P2PNotifier::SetUniqueId(const std::string& unique_id) { 185 void P2PNotifier::SetUniqueId(const std::string& unique_id) {
173 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
174 unique_id_ = unique_id; 187 unique_id_ = unique_id;
175 } 188 }
176 189
177 void P2PNotifier::SetStateDeprecated(const std::string& state) { 190 void P2PNotifier::SetStateDeprecated(const std::string& state) {
178 DCHECK(thread_checker_.CalledOnValidThread()); 191 DCHECK(thread_checker_.CalledOnValidThread());
179 // Do nothing. 192 // Do nothing.
180 } 193 }
181 194
(...skipping 18 matching lines...) Expand all
200 DCHECK(thread_checker_.CalledOnValidThread()); 213 DCHECK(thread_checker_.CalledOnValidThread());
201 const P2PNotificationData notification_data( 214 const P2PNotificationData notification_data(
202 unique_id_, send_notification_target_, changed_types); 215 unique_id_, send_notification_target_, changed_types);
203 SendNotificationData(notification_data); 216 SendNotificationData(notification_data);
204 } 217 }
205 218
206 void P2PNotifier::OnNotificationsEnabled() { 219 void P2PNotifier::OnNotificationsEnabled() {
207 DCHECK(thread_checker_.CalledOnValidThread()); 220 DCHECK(thread_checker_.CalledOnValidThread());
208 bool just_turned_on = (notifications_enabled_ == false); 221 bool just_turned_on = (notifications_enabled_ == false);
209 notifications_enabled_ = true; 222 notifications_enabled_ = true;
210 helper_.EmitOnNotificationsEnabled(); 223 registrar_.EmitOnNotificationsEnabled();
211 if (just_turned_on) { 224 if (just_turned_on) {
212 const P2PNotificationData notification_data( 225 const P2PNotificationData notification_data(
213 unique_id_, NOTIFY_SELF, enabled_types_); 226 unique_id_, NOTIFY_SELF, enabled_types_);
214 SendNotificationData(notification_data); 227 SendNotificationData(notification_data);
215 } 228 }
216 } 229 }
217 230
218 void P2PNotifier::OnNotificationsDisabled( 231 void P2PNotifier::OnNotificationsDisabled(
219 notifier::NotificationsDisabledReason reason) { 232 notifier::NotificationsDisabledReason reason) {
220 DCHECK(thread_checker_.CalledOnValidThread()); 233 DCHECK(thread_checker_.CalledOnValidThread());
221 helper_.EmitOnNotificationsDisabled(FromNotifierReason(reason)); 234 registrar_.EmitOnNotificationsDisabled(FromNotifierReason(reason));
222 } 235 }
223 236
224 void P2PNotifier::OnIncomingNotification( 237 void P2PNotifier::OnIncomingNotification(
225 const notifier::Notification& notification) { 238 const notifier::Notification& notification) {
226 DCHECK(thread_checker_.CalledOnValidThread()); 239 DCHECK(thread_checker_.CalledOnValidThread());
227 DVLOG(1) << "Received notification " << notification.ToString(); 240 DVLOG(1) << "Received notification " << notification.ToString();
228 if (!logged_in_) { 241 if (!logged_in_) {
229 DVLOG(1) << "Not logged in yet -- not emitting notification"; 242 DVLOG(1) << "Not logged in yet -- not emitting notification";
230 return; 243 return;
231 } 244 }
(...skipping 18 matching lines...) Expand all
250 return; 263 return;
251 } 264 }
252 const ModelTypeSet types_to_notify = 265 const ModelTypeSet types_to_notify =
253 Intersection(enabled_types_, notification_data.GetChangedTypes()); 266 Intersection(enabled_types_, notification_data.GetChangedTypes());
254 if (types_to_notify.Empty()) { 267 if (types_to_notify.Empty()) {
255 DVLOG(1) << "No enabled and changed types -- not emitting notification"; 268 DVLOG(1) << "No enabled and changed types -- not emitting notification";
256 return; 269 return;
257 } 270 }
258 const ModelTypePayloadMap& type_payloads = ModelTypePayloadMapFromEnumSet( 271 const ModelTypePayloadMap& type_payloads = ModelTypePayloadMapFromEnumSet(
259 notification_data.GetChangedTypes(), std::string()); 272 notification_data.GetChangedTypes(), std::string());
260 helper_.DispatchInvalidationsToHandlers( 273 registrar_.DispatchInvalidationsToHandlers(
261 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), 274 ModelTypePayloadMapToObjectIdPayloadMap(type_payloads),
262 REMOTE_NOTIFICATION); 275 REMOTE_NOTIFICATION);
263 } 276 }
264 277
265 void P2PNotifier::SendNotificationDataForTest( 278 void P2PNotifier::SendNotificationDataForTest(
266 const P2PNotificationData& notification_data) { 279 const P2PNotificationData& notification_data) {
267 DCHECK(thread_checker_.CalledOnValidThread()); 280 DCHECK(thread_checker_.CalledOnValidThread());
268 SendNotificationData(notification_data); 281 SendNotificationData(notification_data);
269 } 282 }
270 283
271 void P2PNotifier::SendNotificationData( 284 void P2PNotifier::SendNotificationData(
272 const P2PNotificationData& notification_data) { 285 const P2PNotificationData& notification_data) {
273 DCHECK(thread_checker_.CalledOnValidThread()); 286 DCHECK(thread_checker_.CalledOnValidThread());
274 if (notification_data.GetChangedTypes().Empty()) { 287 if (notification_data.GetChangedTypes().Empty()) {
275 DVLOG(1) << "Not sending XMPP notification with no changed types: " 288 DVLOG(1) << "Not sending XMPP notification with no changed types: "
276 << notification_data.ToString(); 289 << notification_data.ToString();
277 return; 290 return;
278 } 291 }
279 notifier::Notification notification; 292 notifier::Notification notification;
280 notification.channel = kSyncP2PNotificationChannel; 293 notification.channel = kSyncP2PNotificationChannel;
281 notification.data = notification_data.ToString(); 294 notification.data = notification_data.ToString();
282 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); 295 DVLOG(1) << "Sending XMPP notification: " << notification.ToString();
283 push_client_->SendNotification(notification); 296 push_client_->SendNotification(notification);
284 } 297 }
285 298
286 } // namespace syncer 299 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_notifier.h ('k') | sync/notifier/p2p_notifier_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698