OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/event_bindings.h" | 5 #include "extensions/renderer/event_bindings.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 28 matching lines...) Expand all Loading... |
39 base::LazyInstance<std::map<std::string, EventListenerCounts>> | 39 base::LazyInstance<std::map<std::string, EventListenerCounts>> |
40 g_listener_counts = LAZY_INSTANCE_INITIALIZER; | 40 g_listener_counts = LAZY_INSTANCE_INITIALIZER; |
41 | 41 |
42 // A map of (extension ID, event name) pairs to the filtered listener counts | 42 // A map of (extension ID, event name) pairs to the filtered listener counts |
43 // for that pair. The map is used to keep track of which filters are in effect | 43 // for that pair. The map is used to keep track of which filters are in effect |
44 // for which events. We notify the browser about filtered event listeners when | 44 // for which events. We notify the browser about filtered event listeners when |
45 // we transition between 0 and 1. | 45 // we transition between 0 and 1. |
46 using FilteredEventListenerKey = std::pair<std::string, std::string>; | 46 using FilteredEventListenerKey = std::pair<std::string, std::string>; |
47 using FilteredEventListenerCounts = | 47 using FilteredEventListenerCounts = |
48 std::map<FilteredEventListenerKey, std::unique_ptr<ValueCounter>>; | 48 std::map<FilteredEventListenerKey, std::unique_ptr<ValueCounter>>; |
49 base::LazyInstance<FilteredEventListenerCounts> g_filtered_listener_counts = | 49 base::LazyInstance<FilteredEventListenerCounts>::DestructorAtExit |
| 50 g_filtered_listener_counts = LAZY_INSTANCE_INITIALIZER; |
| 51 |
| 52 base::LazyInstance<EventFilter>::DestructorAtExit g_event_filter = |
50 LAZY_INSTANCE_INITIALIZER; | 53 LAZY_INSTANCE_INITIALIZER; |
51 | 54 |
52 base::LazyInstance<EventFilter> g_event_filter = LAZY_INSTANCE_INITIALIZER; | |
53 | |
54 // Gets a unique string key identifier for a ScriptContext. | 55 // Gets a unique string key identifier for a ScriptContext. |
55 // TODO(kalman): Just use pointer equality...? | 56 // TODO(kalman): Just use pointer equality...? |
56 std::string GetKeyForScriptContext(ScriptContext* script_context) { | 57 std::string GetKeyForScriptContext(ScriptContext* script_context) { |
57 const std::string& extension_id = script_context->GetExtensionID(); | 58 const std::string& extension_id = script_context->GetExtensionID(); |
58 CHECK(crx_file::id_util::IdIsValid(extension_id) || | 59 CHECK(crx_file::id_util::IdIsValid(extension_id) || |
59 script_context->url().is_valid()); | 60 script_context->url().is_valid()); |
60 return crx_file::id_util::IdIsValid(extension_id) | 61 return crx_file::id_util::IdIsValid(extension_id) |
61 ? extension_id | 62 ? extension_id |
62 : script_context->url().spec(); | 63 : script_context->url().spec(); |
63 } | 64 } |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // Same for filtered events. | 364 // Same for filtered events. |
364 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; | 365 std::set<int> attached_matcher_ids_safe = attached_matcher_ids_; |
365 for (int matcher_id : attached_matcher_ids_safe) { | 366 for (int matcher_id : attached_matcher_ids_safe) { |
366 DetachFilteredEvent(matcher_id, false /* is_manual */); | 367 DetachFilteredEvent(matcher_id, false /* is_manual */); |
367 } | 368 } |
368 DCHECK(attached_matcher_ids_.empty()) | 369 DCHECK(attached_matcher_ids_.empty()) |
369 << "Filtered events cannot be attached during invalidation"; | 370 << "Filtered events cannot be attached during invalidation"; |
370 } | 371 } |
371 | 372 |
372 } // namespace extensions | 373 } // namespace extensions |
OLD | NEW |