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

Side by Side Diff: chrome/renderer/extensions/event_bindings.cc

Issue 8491043: Allow linker initialization of lazy instance (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: willchan comments + rebase Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/chrome_webstore_bindings.cc ('k') | chrome/renderer/extensions/extension_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698