summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppapi_interface_factory.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/plugins/ppapi/ppapi_interface_factory.cc')
-rw-r--r--webkit/plugins/ppapi/ppapi_interface_factory.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/webkit/plugins/ppapi/ppapi_interface_factory.cc b/webkit/plugins/ppapi/ppapi_interface_factory.cc
new file mode 100644
index 0000000..587469a
--- /dev/null
+++ b/webkit/plugins/ppapi/ppapi_interface_factory.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/plugins/ppapi/ppapi_interface_factory.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+
+namespace webkit {
+namespace ppapi {
+
+base::LazyInstance<PpapiInterfaceFactoryManager>
+ g_ppapi_interface_factory_manager(base::LINKER_INITIALIZED);
+
+PpapiInterfaceFactoryManager::PpapiInterfaceFactoryManager() {
+}
+
+PpapiInterfaceFactoryManager::~PpapiInterfaceFactoryManager() {
+}
+
+void PpapiInterfaceFactoryManager::RegisterFactory(InterfaceFactory* factory) {
+ DCHECK(std::find(interface_factory_list_.begin(),
+ interface_factory_list_.end(), factory) ==
+ interface_factory_list_.end());
+ interface_factory_list_.push_back(factory);
+}
+
+void PpapiInterfaceFactoryManager::UnregisterFactory(
+ InterfaceFactory* factory) {
+ FactoryList::iterator index =
+ std::find(interface_factory_list_.begin(), interface_factory_list_.end(),
+ factory);
+ DCHECK(index != interface_factory_list_.end());
+ interface_factory_list_.erase(index);
+}
+
+void* PpapiInterfaceFactoryManager::GetInterface(
+ const std::string& interface_name) {
+ FactoryList::iterator index;
+
+ void* ppapi_interface = NULL;
+
+ for (index = interface_factory_list_.begin();
+ index != interface_factory_list_.end();
+ ++index) {
+ ppapi_interface = (*index)(interface_name);
+ if (ppapi_interface)
+ break;
+ }
+ return ppapi_interface;
+}
+
+// static
+PpapiInterfaceFactoryManager* PpapiInterfaceFactoryManager::GetInstance() {
+ return &g_ppapi_interface_factory_manager.Get();
+}
+
+} // namespace ppapi
+} // namespace webkit
+