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

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

Issue 12092091: Separate sync and invalidation client IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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_invalidator.h ('k') | sync/notifier/p2p_invalidator_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_invalidator.h" 5 #include "sync/notifier/p2p_invalidator.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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 } 151 }
152 int source_num = 0; 152 int source_num = 0;
153 if (!data_dict->GetInteger(kSourceKey, &source_num)) { 153 if (!data_dict->GetInteger(kSourceKey, &source_num)) {
154 LOG(WARNING) << "Could not find integer value for " << kSourceKey; 154 LOG(WARNING) << "Could not find integer value for " << kSourceKey;
155 } 155 }
156 source_ = P2PNotificationSourceFromInteger(source_num); 156 source_ = P2PNotificationSourceFromInteger(source_num);
157 return true; 157 return true;
158 } 158 }
159 159
160 P2PInvalidator::P2PInvalidator(scoped_ptr<notifier::PushClient> push_client, 160 P2PInvalidator::P2PInvalidator(scoped_ptr<notifier::PushClient> push_client,
161 const std::string& invalidator_client_id,
161 P2PNotificationTarget send_notification_target) 162 P2PNotificationTarget send_notification_target)
162 : push_client_(push_client.Pass()), 163 : push_client_(push_client.Pass()),
164 invalidator_client_id_(invalidator_client_id),
163 logged_in_(false), 165 logged_in_(false),
164 notifications_enabled_(false), 166 notifications_enabled_(false),
165 send_notification_target_(send_notification_target) { 167 send_notification_target_(send_notification_target) {
166 DCHECK(send_notification_target_ == NOTIFY_OTHERS || 168 DCHECK(send_notification_target_ == NOTIFY_OTHERS ||
167 send_notification_target_ == NOTIFY_ALL); 169 send_notification_target_ == NOTIFY_ALL);
168 push_client_->AddObserver(this); 170 push_client_->AddObserver(this);
169 } 171 }
170 172
171 P2PInvalidator::~P2PInvalidator() { 173 P2PInvalidator::~P2PInvalidator() {
172 DCHECK(thread_checker_.CalledOnValidThread()); 174 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 10 matching lines...) Expand all
183 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411). 185 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411).
184 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
185 ObjectIdSet new_ids; 187 ObjectIdSet new_ids;
186 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); 188 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler);
187 std::set_difference(ids.begin(), ids.end(), 189 std::set_difference(ids.begin(), ids.end(),
188 old_ids.begin(), old_ids.end(), 190 old_ids.begin(), old_ids.end(),
189 std::inserter(new_ids, new_ids.end()), 191 std::inserter(new_ids, new_ids.end()),
190 ObjectIdLessThan()); 192 ObjectIdLessThan());
191 registrar_.UpdateRegisteredIds(handler, ids); 193 registrar_.UpdateRegisteredIds(handler, ids);
192 const P2PNotificationData notification_data( 194 const P2PNotificationData notification_data(
193 unique_id_, NOTIFY_SELF, ObjectIdSetToInvalidationMap(new_ids, ""), 195 invalidator_client_id_, NOTIFY_SELF,
194 REMOTE_INVALIDATION); 196 ObjectIdSetToInvalidationMap(new_ids, ""), REMOTE_INVALIDATION);
195 SendNotificationData(notification_data); 197 SendNotificationData(notification_data);
196 } 198 }
197 199
198 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { 200 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) {
199 DCHECK(thread_checker_.CalledOnValidThread()); 201 DCHECK(thread_checker_.CalledOnValidThread());
200 registrar_.UnregisterHandler(handler); 202 registrar_.UnregisterHandler(handler);
201 } 203 }
202 204
203 InvalidatorState P2PInvalidator::GetInvalidatorState() const { 205 InvalidatorState P2PInvalidator::GetInvalidatorState() const {
204 DCHECK(thread_checker_.CalledOnValidThread()); 206 DCHECK(thread_checker_.CalledOnValidThread());
205 return registrar_.GetInvalidatorState(); 207 return registrar_.GetInvalidatorState();
206 } 208 }
207 209
208 void P2PInvalidator::SetUniqueId(const std::string& unique_id) {
209 DCHECK(thread_checker_.CalledOnValidThread());
210 unique_id_ = unique_id;
211 }
212
213 void P2PInvalidator::UpdateCredentials( 210 void P2PInvalidator::UpdateCredentials(
214 const std::string& email, const std::string& token) { 211 const std::string& email, const std::string& token) {
215 DCHECK(thread_checker_.CalledOnValidThread()); 212 DCHECK(thread_checker_.CalledOnValidThread());
216 notifier::Subscription subscription; 213 notifier::Subscription subscription;
217 subscription.channel = kSyncP2PNotificationChannel; 214 subscription.channel = kSyncP2PNotificationChannel;
218 // There may be some subtle issues around case sensitivity of the 215 // There may be some subtle issues around case sensitivity of the
219 // from field, but it doesn't matter too much since this is only 216 // from field, but it doesn't matter too much since this is only
220 // used in p2p mode (which is only used in testing). 217 // used in p2p mode (which is only used in testing).
221 subscription.from = email; 218 subscription.from = email;
222 push_client_->UpdateSubscriptions( 219 push_client_->UpdateSubscriptions(
223 notifier::SubscriptionList(1, subscription)); 220 notifier::SubscriptionList(1, subscription));
224 // If already logged in, the new credentials will take effect on the 221 // If already logged in, the new credentials will take effect on the
225 // next reconnection. 222 // next reconnection.
226 push_client_->UpdateCredentials(email, token); 223 push_client_->UpdateCredentials(email, token);
227 logged_in_ = true; 224 logged_in_ = true;
228 } 225 }
229 226
230 void P2PInvalidator::SendInvalidation( 227 void P2PInvalidator::SendInvalidation(
231 const ObjectIdInvalidationMap& invalidation_map) { 228 const ObjectIdInvalidationMap& invalidation_map) {
232 DCHECK(thread_checker_.CalledOnValidThread()); 229 DCHECK(thread_checker_.CalledOnValidThread());
233 const P2PNotificationData notification_data( 230 const P2PNotificationData notification_data(
234 unique_id_, send_notification_target_, invalidation_map, 231 invalidator_client_id_, send_notification_target_, invalidation_map,
235 REMOTE_INVALIDATION); 232 REMOTE_INVALIDATION);
236 SendNotificationData(notification_data); 233 SendNotificationData(notification_data);
237 } 234 }
238 235
239 void P2PInvalidator::OnNotificationsEnabled() { 236 void P2PInvalidator::OnNotificationsEnabled() {
240 DCHECK(thread_checker_.CalledOnValidThread()); 237 DCHECK(thread_checker_.CalledOnValidThread());
241 bool just_turned_on = (notifications_enabled_ == false); 238 bool just_turned_on = (notifications_enabled_ == false);
242 notifications_enabled_ = true; 239 notifications_enabled_ = true;
243 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED); 240 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED);
244 if (just_turned_on) { 241 if (just_turned_on) {
245 const P2PNotificationData notification_data( 242 const P2PNotificationData notification_data(
246 unique_id_, NOTIFY_SELF, 243 invalidator_client_id_, NOTIFY_SELF,
247 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), ""), 244 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), ""),
248 REMOTE_INVALIDATION); 245 REMOTE_INVALIDATION);
249 SendNotificationData(notification_data); 246 SendNotificationData(notification_data);
250 } 247 }
251 } 248 }
252 249
253 void P2PInvalidator::OnNotificationsDisabled( 250 void P2PInvalidator::OnNotificationsDisabled(
254 notifier::NotificationsDisabledReason reason) { 251 notifier::NotificationsDisabledReason reason) {
255 DCHECK(thread_checker_.CalledOnValidThread()); 252 DCHECK(thread_checker_.CalledOnValidThread());
256 registrar_.UpdateInvalidatorState(FromNotifierReason(reason)); 253 registrar_.UpdateInvalidatorState(FromNotifierReason(reason));
(...skipping 14 matching lines...) Expand all
271 if (notification.channel != kSyncP2PNotificationChannel) { 268 if (notification.channel != kSyncP2PNotificationChannel) {
272 LOG(WARNING) << "Notification from unexpected source " 269 LOG(WARNING) << "Notification from unexpected source "
273 << notification.channel; 270 << notification.channel;
274 } 271 }
275 P2PNotificationData notification_data; 272 P2PNotificationData notification_data;
276 if (!notification_data.ResetFromString(notification.data)) { 273 if (!notification_data.ResetFromString(notification.data)) {
277 LOG(WARNING) << "Could not parse notification data from " 274 LOG(WARNING) << "Could not parse notification data from "
278 << notification.data; 275 << notification.data;
279 notification_data = 276 notification_data =
280 P2PNotificationData( 277 P2PNotificationData(
281 unique_id_, NOTIFY_ALL, 278 invalidator_client_id_, NOTIFY_ALL,
282 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), ""), 279 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), ""),
283 REMOTE_INVALIDATION); 280 REMOTE_INVALIDATION);
284 } 281 }
285 if (!notification_data.IsTargeted(unique_id_)) { 282 if (!notification_data.IsTargeted(invalidator_client_id_)) {
286 DVLOG(1) << "Not a target of the notification -- " 283 DVLOG(1) << "Not a target of the notification -- "
287 << "not emitting notification"; 284 << "not emitting notification";
288 return; 285 return;
289 } 286 }
290 registrar_.DispatchInvalidationsToHandlers( 287 registrar_.DispatchInvalidationsToHandlers(
291 notification_data.GetIdInvalidationMap(), 288 notification_data.GetIdInvalidationMap(),
292 REMOTE_INVALIDATION); 289 REMOTE_INVALIDATION);
293 } 290 }
294 291
295 void P2PInvalidator::SendNotificationDataForTest( 292 void P2PInvalidator::SendNotificationDataForTest(
(...skipping 11 matching lines...) Expand all
307 return; 304 return;
308 } 305 }
309 notifier::Notification notification; 306 notifier::Notification notification;
310 notification.channel = kSyncP2PNotificationChannel; 307 notification.channel = kSyncP2PNotificationChannel;
311 notification.data = notification_data.ToString(); 308 notification.data = notification_data.ToString();
312 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); 309 DVLOG(1) << "Sending XMPP notification: " << notification.ToString();
313 push_client_->SendNotification(notification); 310 push_client_->SendNotification(notification);
314 } 311 }
315 312
316 } // namespace syncer 313 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/p2p_invalidator.h ('k') | sync/notifier/p2p_invalidator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698