summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppapi_interface_factory.cc
blob: 26df97ac088c02247b2765633c2e388f08b5f339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 = LAZY_INSTANCE_INITIALIZER;

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);
  if (index != interface_factory_list_.end())
    interface_factory_list_.erase(index);
}

const void* PpapiInterfaceFactoryManager::GetInterface(
    const std::string& interface_name) {
  FactoryList::iterator index;

  const 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