| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 | |
| 11 namespace webkit { | |
| 12 namespace ppapi { | |
| 13 | |
| 14 base::LazyInstance<PpapiInterfaceFactoryManager> | |
| 15 g_ppapi_interface_factory_manager = LAZY_INSTANCE_INITIALIZER; | |
| 16 | |
| 17 PpapiInterfaceFactoryManager::PpapiInterfaceFactoryManager() { | |
| 18 } | |
| 19 | |
| 20 PpapiInterfaceFactoryManager::~PpapiInterfaceFactoryManager() { | |
| 21 } | |
| 22 | |
| 23 void PpapiInterfaceFactoryManager::RegisterFactory(InterfaceFactory* factory) { | |
| 24 DCHECK(std::find(interface_factory_list_.begin(), | |
| 25 interface_factory_list_.end(), factory) == | |
| 26 interface_factory_list_.end()); | |
| 27 interface_factory_list_.push_back(factory); | |
| 28 } | |
| 29 | |
| 30 void PpapiInterfaceFactoryManager::UnregisterFactory( | |
| 31 InterfaceFactory* factory) { | |
| 32 FactoryList::iterator index = | |
| 33 std::find(interface_factory_list_.begin(), interface_factory_list_.end(), | |
| 34 factory); | |
| 35 if (index != interface_factory_list_.end()) | |
| 36 interface_factory_list_.erase(index); | |
| 37 } | |
| 38 | |
| 39 const void* PpapiInterfaceFactoryManager::GetInterface( | |
| 40 const std::string& interface_name) { | |
| 41 FactoryList::iterator index; | |
| 42 | |
| 43 const void* ppapi_interface = NULL; | |
| 44 | |
| 45 for (index = interface_factory_list_.begin(); | |
| 46 index != interface_factory_list_.end(); | |
| 47 ++index) { | |
| 48 ppapi_interface = (*index)(interface_name); | |
| 49 if (ppapi_interface) | |
| 50 break; | |
| 51 } | |
| 52 return ppapi_interface; | |
| 53 } | |
| 54 | |
| 55 // static | |
| 56 PpapiInterfaceFactoryManager* PpapiInterfaceFactoryManager::GetInstance() { | |
| 57 return &g_ppapi_interface_factory_manager.Get(); | |
| 58 } | |
| 59 | |
| 60 } // namespace ppapi | |
| 61 } // namespace webkit | |
| 62 | |
| OLD | NEW |