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

Side by Side Diff: chrome/browser/notifications/sync_notifier/chrome_notifier_service.cc

Issue 14862004: Fix null pointer bug, add better logging to see why pointer is sometimes null. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 7 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
« no previous file with comments | « chrome/browser/extensions/api/push_messaging/push_messaging_api.h ('k') | no next file » | 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 // The ChromeNotifierService works together with sync to maintain the state of 5 // The ChromeNotifierService works together with sync to maintain the state of
6 // user notifications, which can then be presented in the notification center, 6 // user notifications, which can then be presented in the notification center,
7 // via the Notification UI Manager. 7 // via the Notification UI Manager.
8 8
9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" 9 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h"
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 sync_processor_ = sync_processor.Pass(); 48 sync_processor_ = sync_processor.Pass();
49 49
50 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); 50 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin();
51 it != initial_sync_data.end(); ++it) { 51 it != initial_sync_data.end(); ++it) {
52 const syncer::SyncData& sync_data = *it; 52 const syncer::SyncData& sync_data = *it;
53 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType()); 53 DCHECK_EQ(syncer::SYNCED_NOTIFICATIONS, sync_data.GetDataType());
54 54
55 // Build a local notification object from the sync data. 55 // Build a local notification object from the sync data.
56 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData( 56 scoped_ptr<SyncedNotification> incoming(CreateNotificationFromSyncData(
57 sync_data)); 57 sync_data));
58 DCHECK(incoming.get()); 58 if (!incoming.get()) {
dcheng 2013/05/03 17:01:02 if (!incoming)
Pete Williamson 2013/05/03 18:09:53 Done.
59 NOTREACHED() << "Badly formed sync data in incoming notification";
dcheng 2013/05/03 17:01:02 Given that this is actually happening, NOTREACHED(
Pete Williamson 2013/05/03 18:09:53 It shouldn't ever happen. I plan to fix the rest o
dcheng 2013/05/03 18:13:32 I agree that's the eventual intent, but that's not
Pete Williamson 2013/05/03 18:30:20 OK. using LOG(WARNING) now,
60 continue;
61 }
59 62
60 // Process each incoming remote notification. 63 // Process each incoming remote notification.
61 const std::string& key = incoming->GetKey(); 64 const std::string& key = incoming->GetKey();
62 DCHECK_GT(key.length(), 0U); 65 DCHECK_GT(key.length(), 0U);
63 SyncedNotification* found = FindNotificationByKey(key); 66 SyncedNotification* found = FindNotificationByKey(key);
64 67
65 if (NULL == found) { 68 if (NULL == found) {
66 // If there are no conflicts, copy in the data from remote. 69 // If there are no conflicts, copy in the data from remote.
67 Add(incoming.Pass()); 70 Add(incoming.Pass());
68 } else { 71 } else {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 scoped_ptr<SyncedNotification> 183 scoped_ptr<SyncedNotification>
181 ChromeNotifierService::CreateNotificationFromSyncData( 184 ChromeNotifierService::CreateNotificationFromSyncData(
182 const syncer::SyncData& sync_data) { 185 const syncer::SyncData& sync_data) {
183 // Get a pointer to our data within the sync_data object. 186 // Get a pointer to our data within the sync_data object.
184 sync_pb::SyncedNotificationSpecifics specifics = 187 sync_pb::SyncedNotificationSpecifics specifics =
185 sync_data.GetSpecifics().synced_notification(); 188 sync_data.GetSpecifics().synced_notification();
186 189
187 // Check for mandatory fields in the sync_data object. 190 // Check for mandatory fields in the sync_data object.
188 if (!specifics.has_coalesced_notification() || 191 if (!specifics.has_coalesced_notification() ||
189 !specifics.coalesced_notification().has_key() || 192 !specifics.coalesced_notification().has_key() ||
190 !specifics.coalesced_notification().has_read_state()) 193 !specifics.coalesced_notification().has_read_state()) {
194 DVLOG(1) << "Synced Notification missing mandatory fields";
dcheng 2013/05/03 17:01:02 You may want to consider logging the results of th
Pete Williamson 2013/05/03 18:09:53 Done, and also done for the next DVLOG statement.
191 return scoped_ptr<SyncedNotification>(); 195 return scoped_ptr<SyncedNotification>();
196 }
192 197
193 // TODO(petewil): Is this the right set? Should I add more? 198 // TODO(petewil): Is this the right set? Should I add more?
194 bool is_well_formed_unread_notification = 199 bool is_well_formed_unread_notification =
195 (static_cast<SyncedNotification::ReadState>( 200 (static_cast<SyncedNotification::ReadState>(
196 specifics.coalesced_notification().read_state()) == 201 specifics.coalesced_notification().read_state()) ==
197 SyncedNotification::kUnread && 202 SyncedNotification::kUnread &&
198 specifics.coalesced_notification().has_render_info()); 203 specifics.coalesced_notification().has_render_info());
199 bool is_well_formed_dismissed_notification = 204 bool is_well_formed_dismissed_notification =
200 (static_cast<SyncedNotification::ReadState>( 205 (static_cast<SyncedNotification::ReadState>(
201 specifics.coalesced_notification().read_state()) == 206 specifics.coalesced_notification().read_state()) ==
202 SyncedNotification::kDismissed); 207 SyncedNotification::kDismissed);
203 208
204 // if the notification is poorly formed, return a null pointer 209 // if the notification is poorly formed, return a null pointer
205 if (!is_well_formed_unread_notification && 210 if (!is_well_formed_unread_notification &&
206 !is_well_formed_dismissed_notification) 211 !is_well_formed_dismissed_notification) {
212 DVLOG(1) << "Synced Notification is not well formed.";
207 return scoped_ptr<SyncedNotification>(); 213 return scoped_ptr<SyncedNotification>();
214 }
208 215
209 // Create a new notification object based on the supplied sync_data. 216 // Create a new notification object based on the supplied sync_data.
210 scoped_ptr<SyncedNotification> notification( 217 scoped_ptr<SyncedNotification> notification(
211 new SyncedNotification(sync_data)); 218 new SyncedNotification(sync_data));
212 219
213 return notification.Pass(); 220 return notification.Pass();
214 } 221 }
215 222
216 // This returns a pointer into a vector that we own. Caller must not free it. 223 // This returns a pointer into a vector that we own. Caller must not free it.
217 // Returns NULL if no match is found. 224 // Returns NULL if no match is found.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) { 262 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) {
256 SyncedNotification* notification_copy = notification.get(); 263 SyncedNotification* notification_copy = notification.get();
257 // Take ownership of the object and put it into our local storage. 264 // Take ownership of the object and put it into our local storage.
258 notification_data_.push_back(notification.release()); 265 notification_data_.push_back(notification.release());
259 266
260 // Get the contained bitmaps, and show the notification once we have them. 267 // Get the contained bitmaps, and show the notification once we have them.
261 notification_copy->Show(notification_manager_, this, profile_); 268 notification_copy->Show(notification_manager_, this, profile_);
262 } 269 }
263 270
264 } // namespace notifier 271 } // namespace notifier
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/push_messaging/push_messaging_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698