OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/singleton.h" | 8 #include "base/lazy_instance.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
11 #include "chrome/renderer/extensions/bindings_utils.h" | 11 #include "chrome/renderer/extensions/bindings_utils.h" |
12 #include "chrome/renderer/extensions/event_bindings.h" | 12 #include "chrome/renderer/extensions/event_bindings.h" |
13 #include "chrome/renderer/extensions/extension_process_bindings.h" | 13 #include "chrome/renderer/extensions/extension_process_bindings.h" |
14 #include "chrome/renderer/extensions/extension_renderer_info.h" | 14 #include "chrome/renderer/extensions/extension_renderer_info.h" |
15 #include "chrome/renderer/extensions/js_only_v8_extensions.h" | 15 #include "chrome/renderer/extensions/js_only_v8_extensions.h" |
16 #include "chrome/renderer/render_thread.h" | 16 #include "chrome/renderer/render_thread.h" |
17 #include "chrome/renderer/render_view.h" | 17 #include "chrome/renderer/render_view.h" |
18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 // A map of event names to the number of listeners for that event. We notify | 55 // A map of event names to the number of listeners for that event. We notify |
56 // the browser about event listeners when we transition between 0 and 1. | 56 // the browser about event listeners when we transition between 0 and 1. |
57 typedef std::map<std::string, int> EventListenerCounts; | 57 typedef std::map<std::string, int> EventListenerCounts; |
58 | 58 |
59 struct SingletonData { | 59 struct SingletonData { |
60 // A map of extension IDs to listener counts for that extension. | 60 // A map of extension IDs to listener counts for that extension. |
61 std::map<std::string, EventListenerCounts> listener_counts_; | 61 std::map<std::string, EventListenerCounts> listener_counts_; |
62 }; | 62 }; |
63 | 63 |
| 64 static base::LazyInstance<SingletonData> g_singleton_data( |
| 65 base::LINKER_INITIALIZED); |
| 66 |
64 static EventListenerCounts& GetListenerCounts(const std::string& extension_id) { | 67 static EventListenerCounts& GetListenerCounts(const std::string& extension_id) { |
65 return Singleton<SingletonData>()->listener_counts_[extension_id]; | 68 return g_singleton_data.Get().listener_counts_[extension_id]; |
66 } | 69 } |
67 | 70 |
68 class ExtensionImpl : public ExtensionBase { | 71 class ExtensionImpl : public ExtensionBase { |
69 public: | 72 public: |
70 ExtensionImpl() | 73 ExtensionImpl() |
71 : ExtensionBase(EventBindings::kName, | 74 : ExtensionBase(EventBindings::kName, |
72 GetStringResource<IDR_EVENT_BINDINGS_JS>(), | 75 GetStringResource<IDR_EVENT_BINDINGS_JS>(), |
73 0, NULL) { | 76 0, NULL) { |
74 } | 77 } |
75 ~ExtensionImpl() {} | 78 ~ExtensionImpl() {} |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // TODO(rafaelw): Consider only doing this check if function_name == | 371 // TODO(rafaelw): Consider only doing this check if function_name == |
369 // "Event.dispatchJSON". | 372 // "Event.dispatchJSON". |
370 #ifdef _DEBUG | 373 #ifdef _DEBUG |
371 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 374 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
372 std::string error = *v8::String::AsciiValue(retval); | 375 std::string error = *v8::String::AsciiValue(retval); |
373 DCHECK(false) << error; | 376 DCHECK(false) << error; |
374 } | 377 } |
375 #endif | 378 #endif |
376 } | 379 } |
377 } | 380 } |
OLD | NEW |