OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/proxy/browser_dispatcher.h" |
| 6 |
| 7 #include <map> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "ppapi/proxy/browser_var_serialization.h" |
| 11 |
| 12 namespace pp { |
| 13 namespace proxy { |
| 14 |
| 15 namespace { |
| 16 |
| 17 typedef std::map<PP_Instance, BrowserDispatcher*> InstanceToDispatcherMap; |
| 18 InstanceToDispatcherMap* g_instance_to_dispatcher = NULL; |
| 19 |
| 20 } // namespace |
| 21 |
| 22 BrowserDispatcher::BrowserDispatcher(const PPB_Var_Deprecated* var_interface, |
| 23 PP_Module module, |
| 24 GetInterfaceFunc local_get_interface) |
| 25 : Dispatcher(local_get_interface) { |
| 26 SetSerialization(new BrowserVarSerialization(var_interface, module)); |
| 27 } |
| 28 |
| 29 BrowserDispatcher::~BrowserDispatcher() { |
| 30 } |
| 31 |
| 32 // static |
| 33 BrowserDispatcher* BrowserDispatcher::GetForInstance(PP_Instance instance) { |
| 34 if (!g_instance_to_dispatcher) |
| 35 return NULL; |
| 36 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
| 37 instance); |
| 38 if (found == g_instance_to_dispatcher->end()) |
| 39 return NULL; |
| 40 return found->second; |
| 41 } |
| 42 |
| 43 // static |
| 44 void BrowserDispatcher::SetForInstance(PP_Instance instance, |
| 45 BrowserDispatcher* dispatcher) { |
| 46 if (!g_instance_to_dispatcher) |
| 47 g_instance_to_dispatcher = new InstanceToDispatcherMap; |
| 48 (*g_instance_to_dispatcher)[instance] = dispatcher; |
| 49 } |
| 50 |
| 51 // static |
| 52 void BrowserDispatcher::RemoveForInstance(PP_Instance instance) { |
| 53 if (!g_instance_to_dispatcher) |
| 54 return; |
| 55 InstanceToDispatcherMap::iterator found = g_instance_to_dispatcher->find( |
| 56 instance); |
| 57 if (found != g_instance_to_dispatcher->end()) |
| 58 g_instance_to_dispatcher->erase(found); |
| 59 } |
| 60 |
| 61 } // namespace proxy |
| 62 } // namespace pp |
| 63 |
OLD | NEW |