Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / webkit / plugins / ppapi / ppapi_interface_factory.cc
blob26df97ac088c02247b2765633c2e388f08b5f339
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.
5 #include "webkit/plugins/ppapi/ppapi_interface_factory.h"
7 #include <algorithm>
9 #include "base/logging.h"
11 namespace webkit {
12 namespace ppapi {
14 base::LazyInstance<PpapiInterfaceFactoryManager>
15 g_ppapi_interface_factory_manager = LAZY_INSTANCE_INITIALIZER;
17 PpapiInterfaceFactoryManager::PpapiInterfaceFactoryManager() {
20 PpapiInterfaceFactoryManager::~PpapiInterfaceFactoryManager() {
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);
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);
39 const void* PpapiInterfaceFactoryManager::GetInterface(
40 const std::string& interface_name) {
41 FactoryList::iterator index;
43 const void* ppapi_interface = NULL;
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;
52 return ppapi_interface;
55 // static
56 PpapiInterfaceFactoryManager* PpapiInterfaceFactoryManager::GetInstance() {
57 return &g_ppapi_interface_factory_manager.Get();
60 } // namespace ppapi
61 } // namespace webkit