OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
12 static base::LazyInstance<base::ThreadLocalPointer<NotificationServiceImpl> > | 12 static base::LazyInstance<base::ThreadLocalPointer<NotificationServiceImpl> > |
13 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER; | 13 lazy_tls_ptr = LAZY_INSTANCE_INITIALIZER; |
14 | 14 |
15 // static | 15 // static |
16 NotificationServiceImpl* NotificationServiceImpl::current() { | 16 NotificationServiceImpl* NotificationServiceImpl::current() { |
17 return lazy_tls_ptr.Pointer()->Get(); | 17 return lazy_tls_ptr.Pointer()->Get(); |
18 } | 18 } |
19 | 19 |
20 // static | 20 // static |
21 content::NotificationService* content::NotificationService::current() { | 21 content::NotificationService* content::NotificationService::current() { |
22 return NotificationServiceImpl::current(); | 22 return NotificationServiceImpl::current(); |
23 } | 23 } |
24 | 24 |
25 // static | 25 // static |
| 26 content::NotificationService* content::NotificationService::Create() { |
| 27 return new NotificationServiceImpl; |
| 28 } |
| 29 |
| 30 // static |
26 bool NotificationServiceImpl::HasKey(const NotificationSourceMap& map, | 31 bool NotificationServiceImpl::HasKey(const NotificationSourceMap& map, |
27 const content::NotificationSource& source) { | 32 const content::NotificationSource& source) { |
28 return map.find(source.map_key()) != map.end(); | 33 return map.find(source.map_key()) != map.end(); |
29 } | 34 } |
30 | 35 |
31 NotificationServiceImpl::NotificationServiceImpl() { | 36 NotificationServiceImpl::NotificationServiceImpl() { |
32 DCHECK(current() == NULL); | 37 DCHECK(current() == NULL); |
33 lazy_tls_ptr.Pointer()->Set(this); | 38 lazy_tls_ptr.Pointer()->Set(this); |
34 } | 39 } |
35 | 40 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 143 } |
139 #endif | 144 #endif |
140 | 145 |
141 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { | 146 for (int i = 0; i < static_cast<int>(observers_.size()); i++) { |
142 NotificationSourceMap omap = observers_[i]; | 147 NotificationSourceMap omap = observers_[i]; |
143 for (NotificationSourceMap::iterator it = omap.begin(); | 148 for (NotificationSourceMap::iterator it = omap.begin(); |
144 it != omap.end(); ++it) | 149 it != omap.end(); ++it) |
145 delete it->second; | 150 delete it->second; |
146 } | 151 } |
147 } | 152 } |
OLD | NEW |