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/messaging_bindings.h" | 5 #include "extensions/renderer/messaging_bindings.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // port.postMessage('I got your reponse'); | 47 // port.postMessage('I got your reponse'); |
48 // }); | 48 // }); |
49 | 49 |
50 namespace extensions { | 50 namespace extensions { |
51 | 51 |
52 using v8_helpers::ToV8String; | 52 using v8_helpers::ToV8String; |
53 | 53 |
54 namespace { | 54 namespace { |
55 | 55 |
56 // A global map between ScriptContext and MessagingBindings. | 56 // A global map between ScriptContext and MessagingBindings. |
57 base::LazyInstance<std::map<ScriptContext*, MessagingBindings*>> | 57 base::LazyInstance<std::map<ScriptContext*, MessagingBindings*>>:: |
58 g_messaging_map = LAZY_INSTANCE_INITIALIZER; | 58 DestructorAtExit g_messaging_map = LAZY_INSTANCE_INITIALIZER; |
59 | 59 |
60 void HasMessagePort(const PortId& port_id, | 60 void HasMessagePort(const PortId& port_id, |
61 bool* has_port, | 61 bool* has_port, |
62 ScriptContext* script_context) { | 62 ScriptContext* script_context) { |
63 if (*has_port) | 63 if (*has_port) |
64 return; // Stop checking if the port was found. | 64 return; // Stop checking if the port was found. |
65 | 65 |
66 MessagingBindings* bindings = g_messaging_map.Get()[script_context]; | 66 MessagingBindings* bindings = g_messaging_map.Get()[script_context]; |
67 DCHECK(bindings); | 67 DCHECK(bindings); |
68 // No need for |=; we know this is false right now from above. | 68 // No need for |=; we know this is false right now from above. |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 ports_.erase(iter); | 545 ports_.erase(iter); |
546 port->Close(force_close); | 546 port->Close(force_close); |
547 } | 547 } |
548 } | 548 } |
549 | 549 |
550 int MessagingBindings::GetNextJsId() { | 550 int MessagingBindings::GetNextJsId() { |
551 return next_js_id_++; | 551 return next_js_id_++; |
552 } | 552 } |
553 | 553 |
554 } // namespace extensions | 554 } // namespace extensions |
OLD | NEW |