summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppapi_interface_factory.cc
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 03:19:57 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-01 03:19:57 +0000
commit593abb8eebd6d980bdea0e5ab3d933da34cbaaf4 (patch)
treebca923fa9c0fc6b8f9c8c2bfd2b6b465d5dd1ef2 /webkit/plugins/ppapi/ppapi_interface_factory.cc
parent549579776e121f7a3168a3f7abaa6ab2ccbff24c (diff)
downloadchromium_src-593abb8eebd6d980bdea0e5ab3d933da34cbaaf4.zip
chromium_src-593abb8eebd6d980bdea0e5ab3d933da34cbaaf4.tar.gz
chromium_src-593abb8eebd6d980bdea0e5ab3d933da34cbaaf4.tar.bz2
Relanding this as the previous iteration broke the chrome os build.
Added a facility in PPAPI to register interface factories which can watch GetInterface calls and return custom interfaces. Added a basic unit test to validate that the custom factory does get called. This would eventually be used to register custom interfaces for plugins like NACL which rely on chrome\renderer provided functionality via the webkit_glue namespace. This will help in eventually building src\content as a dll. BUG=82454 TEST=covered by test shell tests. TBR=apatrick Review URL: http://codereview.chromium.org/7104015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87426 0039d316-1c4b-4281-b951-d872f2087c98
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
+