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

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: Synced Notifications null pointer bug fix. 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 | « no previous file | 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) {
59 // TODO(petewil): Turn this into a NOTREACHED() call once we fix the
60 // underlying problem causing bad data.
61 LOG(WARNING) << "Badly formed sync data in incoming notification";
62 continue;
63 }
59 64
60 // Process each incoming remote notification. 65 // Process each incoming remote notification.
61 const std::string& key = incoming->GetKey(); 66 const std::string& key = incoming->GetKey();
62 DCHECK_GT(key.length(), 0U); 67 DCHECK_GT(key.length(), 0U);
63 SyncedNotification* found = FindNotificationByKey(key); 68 SyncedNotification* found = FindNotificationByKey(key);
64 69
65 if (NULL == found) { 70 if (NULL == found) {
66 // If there are no conflicts, copy in the data from remote. 71 // If there are no conflicts, copy in the data from remote.
67 Add(incoming.Pass()); 72 Add(incoming.Pass());
68 } else { 73 } else {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 scoped_ptr<SyncedNotification> 185 scoped_ptr<SyncedNotification>
181 ChromeNotifierService::CreateNotificationFromSyncData( 186 ChromeNotifierService::CreateNotificationFromSyncData(
182 const syncer::SyncData& sync_data) { 187 const syncer::SyncData& sync_data) {
183 // Get a pointer to our data within the sync_data object. 188 // Get a pointer to our data within the sync_data object.
184 sync_pb::SyncedNotificationSpecifics specifics = 189 sync_pb::SyncedNotificationSpecifics specifics =
185 sync_data.GetSpecifics().synced_notification(); 190 sync_data.GetSpecifics().synced_notification();
186 191
187 // Check for mandatory fields in the sync_data object. 192 // Check for mandatory fields in the sync_data object.
188 if (!specifics.has_coalesced_notification() || 193 if (!specifics.has_coalesced_notification() ||
189 !specifics.coalesced_notification().has_key() || 194 !specifics.coalesced_notification().has_key() ||
190 !specifics.coalesced_notification().has_read_state()) 195 !specifics.coalesced_notification().has_read_state()) {
196 DVLOG(1) << "Synced Notification missing mandatory fields "
197 << "has coalesced notification? "
198 << specifics.has_coalesced_notification()
199 << " has key? " << specifics.coalesced_notification().has_key()
200 << " has read state? "
201 << specifics.coalesced_notification().has_read_state();
191 return scoped_ptr<SyncedNotification>(); 202 return scoped_ptr<SyncedNotification>();
203 }
192 204
193 // TODO(petewil): Is this the right set? Should I add more? 205 // TODO(petewil): Is this the right set? Should I add more?
194 bool is_well_formed_unread_notification = 206 bool is_well_formed_unread_notification =
195 (static_cast<SyncedNotification::ReadState>( 207 (static_cast<SyncedNotification::ReadState>(
196 specifics.coalesced_notification().read_state()) == 208 specifics.coalesced_notification().read_state()) ==
197 SyncedNotification::kUnread && 209 SyncedNotification::kUnread &&
198 specifics.coalesced_notification().has_render_info()); 210 specifics.coalesced_notification().has_render_info());
199 bool is_well_formed_dismissed_notification = 211 bool is_well_formed_dismissed_notification =
200 (static_cast<SyncedNotification::ReadState>( 212 (static_cast<SyncedNotification::ReadState>(
201 specifics.coalesced_notification().read_state()) == 213 specifics.coalesced_notification().read_state()) ==
202 SyncedNotification::kDismissed); 214 SyncedNotification::kDismissed);
203 215
204 // if the notification is poorly formed, return a null pointer 216 // if the notification is poorly formed, return a null pointer
205 if (!is_well_formed_unread_notification && 217 if (!is_well_formed_unread_notification &&
206 !is_well_formed_dismissed_notification) 218 !is_well_formed_dismissed_notification) {
219 DVLOG(1) << "Synced Notification is not well formed."
220 << " unread well formed? "
221 << is_well_formed_unread_notification
222 << " dismissed well formed? "
223 << is_well_formed_dismissed_notification;
207 return scoped_ptr<SyncedNotification>(); 224 return scoped_ptr<SyncedNotification>();
225 }
208 226
209 // Create a new notification object based on the supplied sync_data. 227 // Create a new notification object based on the supplied sync_data.
210 scoped_ptr<SyncedNotification> notification( 228 scoped_ptr<SyncedNotification> notification(
211 new SyncedNotification(sync_data)); 229 new SyncedNotification(sync_data));
212 230
213 return notification.Pass(); 231 return notification.Pass();
214 } 232 }
215 233
216 // This returns a pointer into a vector that we own. Caller must not free it. 234 // This returns a pointer into a vector that we own. Caller must not free it.
217 // Returns NULL if no match is found. 235 // 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) { 273 void ChromeNotifierService::Add(scoped_ptr<SyncedNotification> notification) {
256 SyncedNotification* notification_copy = notification.get(); 274 SyncedNotification* notification_copy = notification.get();
257 // Take ownership of the object and put it into our local storage. 275 // Take ownership of the object and put it into our local storage.
258 notification_data_.push_back(notification.release()); 276 notification_data_.push_back(notification.release());
259 277
260 // Get the contained bitmaps, and show the notification once we have them. 278 // Get the contained bitmaps, and show the notification once we have them.
261 notification_copy->Show(notification_manager_, this, profile_); 279 notification_copy->Show(notification_manager_, this, profile_);
262 } 280 }
263 281
264 } // namespace notifier 282 } // namespace notifier
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698