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 "chrome/renderer/extensions/event_bindings.h" | 5 #include "chrome/renderer/extensions/event_bindings.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 // A map of event names to the number of listeners for that event. We notify | 40 // A map of event names to the number of listeners for that event. We notify |
41 // the browser about event listeners when we transition between 0 and 1. | 41 // the browser about event listeners when we transition between 0 and 1. |
42 typedef std::map<std::string, int> EventListenerCounts; | 42 typedef std::map<std::string, int> EventListenerCounts; |
43 | 43 |
44 struct SingletonData { | 44 struct SingletonData { |
45 // A map of extension IDs to listener counts for that extension. | 45 // A map of extension IDs to listener counts for that extension. |
46 std::map<std::string, EventListenerCounts> listener_counts_; | 46 std::map<std::string, EventListenerCounts> listener_counts_; |
47 }; | 47 }; |
48 | 48 |
49 static base::LazyInstance<SingletonData> g_singleton_data( | 49 static base::LazyInstance<SingletonData> g_singleton_data = |
50 base::LINKER_INITIALIZED); | 50 LAZY_INSTANCE_INITIALIZER; |
51 | 51 |
52 static EventListenerCounts& GetListenerCounts(const std::string& extension_id) { | 52 static EventListenerCounts& GetListenerCounts(const std::string& extension_id) { |
53 return g_singleton_data.Get().listener_counts_[extension_id]; | 53 return g_singleton_data.Get().listener_counts_[extension_id]; |
54 } | 54 } |
55 | 55 |
56 class ExtensionImpl : public ChromeV8Extension { | 56 class ExtensionImpl : public ChromeV8Extension { |
57 public: | 57 public: |
58 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) | 58 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) |
59 : ChromeV8Extension("extensions/event.js", | 59 : ChromeV8Extension("extensions/event.js", |
60 IDR_EVENT_BINDINGS_JS, | 60 IDR_EVENT_BINDINGS_JS, |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 return v8::Undefined(); | 127 return v8::Undefined(); |
128 } | 128 } |
129 }; | 129 }; |
130 | 130 |
131 } // namespace | 131 } // namespace |
132 | 132 |
133 v8::Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { | 133 v8::Extension* EventBindings::Get(ExtensionDispatcher* dispatcher) { |
134 static v8::Extension* extension = new ExtensionImpl(dispatcher); | 134 static v8::Extension* extension = new ExtensionImpl(dispatcher); |
135 return extension; | 135 return extension; |
136 } | 136 } |
OLD | NEW |