Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: ppapi/cpp/ppp_entrypoints.cc

Issue 10069035: Add a way to implement GetInterface in the broker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // When used in conjunction with module_embedder.h, this gives a default 5 // When used in conjunction with module_embedder.h, this gives a default
6 // implementation of ppp.h for clients of the ppapi C++ interface. Most 6 // implementation of ppp.h for clients of the ppapi C++ interface. Most
7 // plugin implementors can export their derivation of Module by just 7 // plugin implementors can export their derivation of Module by just
8 // linking to this implementation. 8 // linking to this implementation.
9 9
10 #include "ppapi/c/ppb.h" 10 #include "ppapi/c/ppb.h"
11 #include "ppapi/c/ppp.h" 11 #include "ppapi/c/ppp.h"
12 #include "ppapi/c/pp_errors.h" 12 #include "ppapi/c/pp_errors.h"
13 #include "ppapi/cpp/module.h" 13 #include "ppapi/cpp/module.h"
14 #include "ppapi/cpp/module_embedder.h" 14 #include "ppapi/cpp/module_embedder.h"
15 15
16 static pp::Module* g_module_singleton = NULL; 16 static pp::Module* g_module_singleton = NULL;
17 static PP_GetInterface_Func g_broker_get_interface = NULL;
17 18
18 namespace pp { 19 namespace pp {
19 20
20 // Give a default implementation of Module::Get(). See module.cc for details. 21 // Give a default implementation of Module::Get(). See module.cc for details.
21 pp::Module* Module::Get() { 22 pp::Module* Module::Get() {
22 return g_module_singleton; 23 return g_module_singleton;
23 } 24 }
24 25
26 void SetBrokerGetIntefaceFunc(PP_GetInterface_Func broker_get_interface) {
27 g_broker_get_interface = broker_get_interface;
28 }
29
25 } // namespace pp 30 } // namespace pp
26 31
27 // Global PPP functions -------------------------------------------------------- 32 // Global PPP functions --------------------------------------------------------
28 33
29 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id, 34 PP_EXPORT int32_t PPP_InitializeModule(PP_Module module_id,
30 PPB_GetInterface get_browser_interface) { 35 PPB_GetInterface get_browser_interface) {
31 pp::Module* module = pp::CreateModule(); 36 pp::Module* module = pp::CreateModule();
32 if (!module) 37 if (!module)
33 return PP_ERROR_FAILED; 38 return PP_ERROR_FAILED;
34 39
35 if (!module->InternalInit(module_id, get_browser_interface)) { 40 if (!module->InternalInit(module_id, get_browser_interface)) {
36 delete module; 41 delete module;
37 return PP_ERROR_FAILED; 42 return PP_ERROR_FAILED;
38 } 43 }
39 g_module_singleton = module; 44 g_module_singleton = module;
40 return PP_OK; 45 return PP_OK;
41 } 46 }
42 47
43 PP_EXPORT void PPP_ShutdownModule() { 48 PP_EXPORT void PPP_ShutdownModule() {
44 delete g_module_singleton; 49 delete g_module_singleton;
45 g_module_singleton = NULL; 50 g_module_singleton = NULL;
46 } 51 }
47 52
48 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) { 53 PP_EXPORT const void* PPP_GetInterface(const char* interface_name) {
49 if (!g_module_singleton) 54 if (!g_module_singleton) {
viettrungluu 2012/04/12 22:14:07 Nit: Maybe it'd be nicer to write this function as
55 // If there's no module, we might be a broker.
56 if (g_broker_get_interface)
57 return g_broker_get_interface(interface_name);
50 return NULL; 58 return NULL;
59 }
51 return g_module_singleton->GetPluginInterface(interface_name); 60 return g_module_singleton->GetPluginInterface(interface_name);
52 } 61 }
OLDNEW
« ppapi/c/ppp.h ('K') | « ppapi/cpp/module_embedder.h ('k') | ppapi/proxy/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698