Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / components / nacl / renderer / plugin / module_ppapi.cc
blobf59e6660553d8a88040f5c7f643d14d6bfdfd366
1 /*
2 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
7 #include "components/nacl/renderer/plugin/module_ppapi.h"
8 #include "components/nacl/renderer/plugin/plugin.h"
9 #include "components/nacl/renderer/plugin/utility.h"
10 #include "native_client/src/shared/imc/nacl_imc_c.h"
11 #include "native_client/src/shared/platform/nacl_secure_random.h"
12 #include "native_client/src/shared/platform/nacl_time.h"
13 #include "native_client/src/trusted/desc/nrd_all_modules.h"
15 namespace plugin {
17 ModulePpapi::ModulePpapi() : pp::Module(),
18 init_was_successful_(false),
19 private_interface_(NULL) {
20 MODULE_PRINTF(("ModulePpapi::ModulePpapi (this=%p)\n",
21 static_cast<void*>(this)));
24 ModulePpapi::~ModulePpapi() {
25 if (init_was_successful_) {
26 NaClSrpcModuleFini();
27 NaClNrdAllModulesFini();
29 MODULE_PRINTF(("ModulePpapi::~ModulePpapi (this=%p)\n",
30 static_cast<void*>(this)));
33 bool ModulePpapi::Init() {
34 // Ask the browser for an interface which provides missing functions
35 private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>(
36 GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE));
38 if (NULL == private_interface_) {
39 MODULE_PRINTF(("ModulePpapi::Init failed: "
40 "GetBrowserInterface returned NULL\n"));
41 return false;
43 SetNaClInterface(private_interface_);
45 #if NACL_LINUX || NACL_OSX
46 // Note that currently we do not need random numbers inside the
47 // NaCl trusted plugin on Unix, but NaClSecureRngModuleInit() is
48 // strict and will raise a fatal error unless we provide it with a
49 // /dev/urandom FD beforehand.
50 NaClSecureRngModuleSetUrandomFd(dup(private_interface_->UrandomFD()));
51 #endif
53 // In the plugin, we don't need high resolution time of day.
54 NaClAllowLowResolutionTimeOfDay();
55 NaClNrdAllModulesInit();
56 NaClSrpcModuleInit();
58 #if NACL_WINDOWS
59 NaClSetBrokerDuplicateHandleFunc(private_interface_->BrokerDuplicateHandle);
60 #endif
62 init_was_successful_ = true;
63 return true;
66 pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) {
67 MODULE_PRINTF(("ModulePpapi::CreateInstance (pp_instance=%" NACL_PRId32
68 ")\n",
69 pp_instance));
70 Plugin* plugin = new Plugin(pp_instance);
71 MODULE_PRINTF(("ModulePpapi::CreateInstance (return %p)\n",
72 static_cast<void* >(plugin)));
73 return plugin;
76 } // namespace plugin
79 namespace pp {
81 Module* CreateModule() {
82 MODULE_PRINTF(("CreateModule ()\n"));
83 return new plugin::ModulePpapi();
86 } // namespace pp