summaryrefslogtreecommitdiffstats
path: root/webkit/plugins/ppapi/ppapi_interface_factory.h
blob: 1b574aae9a32cd4635b52d84ce4fd8b6a6852a91 (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
// 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.

#ifndef WEBKIT_PLUGINS_PPAPI_PLUGIN_INTERFACE_FACTORY_H_
#define WEBKIT_PLUGINS_PPAPI_PLUGIN_INTERFACE_FACTORY_H_

#include <string>
#include <vector>

#include "base/basictypes.h"
#include "base/lazy_instance.h"
#include "webkit/plugins/webkit_plugins_export.h"

namespace webkit {
namespace ppapi {

// This class provides functionality to manage custom PPAPI interface
// factories.
class PpapiInterfaceFactoryManager {
 public:
  typedef const void* (InterfaceFactory)(const std::string& interface_name);

  // Registers a custom PPAPI interface factory.
  WEBKIT_PLUGINS_EXPORT void RegisterFactory(InterfaceFactory* factory);

  // Unregisters the custom PPAPI interface factory passed in.
  WEBKIT_PLUGINS_EXPORT void UnregisterFactory(InterfaceFactory* factory);

  // Returns a pointer to the interface identified by the name passed in.
  // Returns NULL if no factory handles this interface.
  const void* GetInterface(const std::string& interface_name);

  // Returns a pointer to the global instance of the
  // PpapiInterfaceFactoryManager class.
  WEBKIT_PLUGINS_EXPORT static PpapiInterfaceFactoryManager* GetInstance();

 private:
  friend struct base::DefaultLazyInstanceTraits<PpapiInterfaceFactoryManager>;

  PpapiInterfaceFactoryManager();
  ~PpapiInterfaceFactoryManager();

  typedef std::vector<InterfaceFactory*> FactoryList;

  // List of registered factories.
  FactoryList interface_factory_list_;

  DISALLOW_COPY_AND_ASSIGN(PpapiInterfaceFactoryManager);
};

}  // namespace ppapi
}  // namespace webkit

#endif  // WEBKIT_PLUGINS_PPAPI_PLUGIN_INTERFACE_FACTORY_H_