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

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

Issue 13145003: Rewrite std::string("") to std::string(), Linux edition. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ugh Created 7 years, 8 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/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 22 matching lines...) Expand all
33 std::string P2PNotificationTargetToString(P2PNotificationTarget target) { 33 std::string P2PNotificationTargetToString(P2PNotificationTarget target) {
34 switch (target) { 34 switch (target) {
35 case NOTIFY_SELF: 35 case NOTIFY_SELF:
36 return kNotifySelf; 36 return kNotifySelf;
37 case NOTIFY_OTHERS: 37 case NOTIFY_OTHERS:
38 return kNotifyOthers; 38 return kNotifyOthers;
39 case NOTIFY_ALL: 39 case NOTIFY_ALL:
40 return kNotifyAll; 40 return kNotifyAll;
41 default: 41 default:
42 NOTREACHED(); 42 NOTREACHED();
43 return ""; 43 return std::string();
44 } 44 }
45 } 45 }
46 46
47 P2PNotificationTarget P2PNotificationTargetFromString( 47 P2PNotificationTarget P2PNotificationTargetFromString(
48 const std::string& target_str) { 48 const std::string& target_str) {
49 if (target_str == kNotifySelf) { 49 if (target_str == kNotifySelf) {
50 return NOTIFY_SELF; 50 return NOTIFY_SELF;
51 } 51 }
52 if (target_str == kNotifyOthers) { 52 if (target_str == kNotifyOthers) {
53 return NOTIFY_OTHERS; 53 return NOTIFY_OTHERS;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411). 164 // TODO(akalin): Handle arbitrary object IDs (http://crbug.com/140411).
165 DCHECK(thread_checker_.CalledOnValidThread()); 165 DCHECK(thread_checker_.CalledOnValidThread());
166 ObjectIdSet new_ids; 166 ObjectIdSet new_ids;
167 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler); 167 const ObjectIdSet& old_ids = registrar_.GetRegisteredIds(handler);
168 std::set_difference(ids.begin(), ids.end(), 168 std::set_difference(ids.begin(), ids.end(),
169 old_ids.begin(), old_ids.end(), 169 old_ids.begin(), old_ids.end(),
170 std::inserter(new_ids, new_ids.end()), 170 std::inserter(new_ids, new_ids.end()),
171 ObjectIdLessThan()); 171 ObjectIdLessThan());
172 registrar_.UpdateRegisteredIds(handler, ids); 172 registrar_.UpdateRegisteredIds(handler, ids);
173 const P2PNotificationData notification_data( 173 const P2PNotificationData notification_data(
174 invalidator_client_id_, NOTIFY_SELF, 174 invalidator_client_id_,
175 ObjectIdSetToInvalidationMap(new_ids, "")); 175 NOTIFY_SELF,
176 ObjectIdSetToInvalidationMap(new_ids, std::string()));
176 SendNotificationData(notification_data); 177 SendNotificationData(notification_data);
177 } 178 }
178 179
179 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) { 180 void P2PInvalidator::UnregisterHandler(InvalidationHandler* handler) {
180 DCHECK(thread_checker_.CalledOnValidThread()); 181 DCHECK(thread_checker_.CalledOnValidThread());
181 registrar_.UnregisterHandler(handler); 182 registrar_.UnregisterHandler(handler);
182 } 183 }
183 184
184 void P2PInvalidator::Acknowledge(const invalidation::ObjectId& id, 185 void P2PInvalidator::Acknowledge(const invalidation::ObjectId& id,
185 const AckHandle& ack_handle) { 186 const AckHandle& ack_handle) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 SendNotificationData(notification_data); 218 SendNotificationData(notification_data);
218 } 219 }
219 220
220 void P2PInvalidator::OnNotificationsEnabled() { 221 void P2PInvalidator::OnNotificationsEnabled() {
221 DCHECK(thread_checker_.CalledOnValidThread()); 222 DCHECK(thread_checker_.CalledOnValidThread());
222 bool just_turned_on = (notifications_enabled_ == false); 223 bool just_turned_on = (notifications_enabled_ == false);
223 notifications_enabled_ = true; 224 notifications_enabled_ = true;
224 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED); 225 registrar_.UpdateInvalidatorState(INVALIDATIONS_ENABLED);
225 if (just_turned_on) { 226 if (just_turned_on) {
226 const P2PNotificationData notification_data( 227 const P2PNotificationData notification_data(
227 invalidator_client_id_, NOTIFY_SELF, 228 invalidator_client_id_,
228 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), "")); 229 NOTIFY_SELF,
230 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(),
231 std::string()));
229 SendNotificationData(notification_data); 232 SendNotificationData(notification_data);
230 } 233 }
231 } 234 }
232 235
233 void P2PInvalidator::OnNotificationsDisabled( 236 void P2PInvalidator::OnNotificationsDisabled(
234 notifier::NotificationsDisabledReason reason) { 237 notifier::NotificationsDisabledReason reason) {
235 DCHECK(thread_checker_.CalledOnValidThread()); 238 DCHECK(thread_checker_.CalledOnValidThread());
236 registrar_.UpdateInvalidatorState(FromNotifierReason(reason)); 239 registrar_.UpdateInvalidatorState(FromNotifierReason(reason));
237 } 240 }
238 241
(...skipping 10 matching lines...) Expand all
249 return; 252 return;
250 } 253 }
251 if (notification.channel != kSyncP2PNotificationChannel) { 254 if (notification.channel != kSyncP2PNotificationChannel) {
252 LOG(WARNING) << "Notification from unexpected source " 255 LOG(WARNING) << "Notification from unexpected source "
253 << notification.channel; 256 << notification.channel;
254 } 257 }
255 P2PNotificationData notification_data; 258 P2PNotificationData notification_data;
256 if (!notification_data.ResetFromString(notification.data)) { 259 if (!notification_data.ResetFromString(notification.data)) {
257 LOG(WARNING) << "Could not parse notification data from " 260 LOG(WARNING) << "Could not parse notification data from "
258 << notification.data; 261 << notification.data;
259 notification_data = 262 notification_data = P2PNotificationData(
260 P2PNotificationData( 263 invalidator_client_id_,
261 invalidator_client_id_, NOTIFY_ALL, 264 NOTIFY_ALL,
262 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), "")); 265 ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(),
266 std::string()));
263 } 267 }
264 if (!notification_data.IsTargeted(invalidator_client_id_)) { 268 if (!notification_data.IsTargeted(invalidator_client_id_)) {
265 DVLOG(1) << "Not a target of the notification -- " 269 DVLOG(1) << "Not a target of the notification -- "
266 << "not emitting notification"; 270 << "not emitting notification";
267 return; 271 return;
268 } 272 }
269 registrar_.DispatchInvalidationsToHandlers( 273 registrar_.DispatchInvalidationsToHandlers(
270 notification_data.GetIdInvalidationMap()); 274 notification_data.GetIdInvalidationMap());
271 } 275 }
272 276
(...skipping 12 matching lines...) Expand all
285 return; 289 return;
286 } 290 }
287 notifier::Notification notification; 291 notifier::Notification notification;
288 notification.channel = kSyncP2PNotificationChannel; 292 notification.channel = kSyncP2PNotificationChannel;
289 notification.data = notification_data.ToString(); 293 notification.data = notification_data.ToString();
290 DVLOG(1) << "Sending XMPP notification: " << notification.ToString(); 294 DVLOG(1) << "Sending XMPP notification: " << notification.ToString();
291 push_client_->SendNotification(notification); 295 push_client_->SendNotification(notification);
292 } 296 }
293 297
294 } // namespace syncer 298 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/syncapi_server_connection_manager_unittest.cc ('k') | sync/notifier/p2p_invalidator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698