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

Side by Side Diff: content/browser/notification_service_impl.cc

Issue 10546025: Delete empty NotificationObserverLists. Fixes leak. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 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) 2011 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 "content/browser/notification_service_impl.h" 5 #include "content/browser/notification_service_impl.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/threading/thread_local.h" 8 #include "base/threading/thread_local.h"
9 #include "content/public/browser/notification_observer.h" 9 #include "content/public/browser/notification_observer.h"
10 #include "content/public/browser/notification_types.h" 10 #include "content/public/browser/notification_types.h"
11 11
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // has its deleted pointer in its map. A garbge object will be called in the 72 // has its deleted pointer in its map. A garbge object will be called in the
73 // future. 73 // future.
74 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or 74 // NOTE: when this check shows crashes, use BrowserThread::DeleteOnIOThread or
75 // other variants as the trait on the object. 75 // other variants as the trait on the object.
76 CHECK(HasKey(observers_[type], source)); 76 CHECK(HasKey(observers_[type], source));
77 77
78 NotificationObserverList* observer_list = 78 NotificationObserverList* observer_list =
79 observers_[type][source.map_key()]; 79 observers_[type][source.map_key()];
80 if (observer_list) { 80 if (observer_list) {
81 observer_list->RemoveObserver(observer); 81 observer_list->RemoveObserver(observer);
82 if (!observer_list->size()) {
83 observers_[type].erase(source.map_key());
84 delete observer_list;
85 observer_list = NULL;
jam 2012/06/06 16:48:05 nit: unnecessary
lengG 2012/06/07 14:08:51 Done.
86 }
82 #ifndef NDEBUG 87 #ifndef NDEBUG
83 --observer_counts_[type]; 88 --observer_counts_[type];
84 #endif 89 #endif
85 } 90 }
86
87 // TODO(jhughes): Remove observer list from map if empty?
88 } 91 }
89 92
90 void NotificationServiceImpl::Notify( 93 void NotificationServiceImpl::Notify(
91 int type, 94 int type,
92 const content::NotificationSource& source, 95 const content::NotificationSource& source,
93 const content::NotificationDetails& details) { 96 const content::NotificationDetails& details) {
94 DCHECK(type > content::NOTIFICATION_ALL) << 97 DCHECK(type > content::NOTIFICATION_ALL) <<
95 "Allowed for observing, but not posting."; 98 "Allowed for observing, but not posting.";
96 99
97 // There's no particular reason for the order in which the different 100 // There's no particular reason for the order in which the different
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 146 }
144 #endif 147 #endif
145 148
146 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { 149 for (int i = 0; i < static_cast<int>(observers_.size()); i++) {
147 NotificationSourceMap omap = observers_[i]; 150 NotificationSourceMap omap = observers_[i];
148 for (NotificationSourceMap::iterator it = omap.begin(); 151 for (NotificationSourceMap::iterator it = omap.begin();
149 it != omap.end(); ++it) 152 it != omap.end(); ++it)
150 delete it->second; 153 delete it->second;
151 } 154 }
152 } 155 }
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