diff options
| author | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-21 01:07:57 +0000 | 
|---|---|---|
| committer | sehr@google.com <sehr@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-21 01:07:57 +0000 | 
| commit | 07bb6337ff5a13d3059fbc680beb9fc19852a40d (patch) | |
| tree | dbeb7095cc9ba94165348229794e209cc2c7cdd8 | |
| parent | a27308823dcdc002d05a355404dca725532e1697 (diff) | |
| download | chromium_src-07bb6337ff5a13d3059fbc680beb9fc19852a40d.zip chromium_src-07bb6337ff5a13d3059fbc680beb9fc19852a40d.tar.gz chromium_src-07bb6337ff5a13d3059fbc680beb9fc19852a40d.tar.bz2 | |
Repeat performance for 118553 -- Add nacl private interface and state
for process creation
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9270032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118575 0039d316-1c4b-4281-b951-d872f2087c98
| -rw-r--r-- | chrome/renderer/chrome_ppapi_interfaces.cc | 21 | ||||
| -rw-r--r-- | content/public/renderer/render_thread.h | 2 | ||||
| -rw-r--r-- | content/renderer/render_thread_impl.cc | 4 | ||||
| -rw-r--r-- | content/renderer/render_thread_impl.h | 1 | ||||
| -rw-r--r-- | content/test/mock_render_thread.cc | 4 | ||||
| -rw-r--r-- | content/test/mock_render_thread.h | 1 | ||||
| -rw-r--r-- | ppapi/c/private/ppb_nacl_private.h | 6 | ||||
| -rw-r--r-- | ppapi/native_client/src/trusted/plugin/module_ppapi.cc | 12 | 
8 files changed, 44 insertions, 7 deletions
| diff --git a/chrome/renderer/chrome_ppapi_interfaces.cc b/chrome/renderer/chrome_ppapi_interfaces.cc index a01c1ee..517dbcf 100644 --- a/chrome/renderer/chrome_ppapi_interfaces.cc +++ b/chrome/renderer/chrome_ppapi_interfaces.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "chrome/renderer/chrome_ppapi_interfaces.h"  #include "base/command_line.h" +#include "base/lazy_instance.h"  #include "base/logging.h"  #include "base/rand_util_c.h"  #include "base/utf_string_conversions.h" @@ -12,6 +13,7 @@  #include "chrome/renderer/chrome_ppb_pdf_impl.h"  #include "content/public/common/content_switches.h"  #include "content/public/renderer/render_thread.h" +#include "ipc/ipc_sync_message_filter.h"  #include "ppapi/c/private/ppb_nacl_private.h"  #include "ppapi/c/private/ppb_pdf.h"  #include "webkit/plugins/ppapi/ppapi_interface_factory.h" @@ -26,13 +28,22 @@ using content::RenderThread;  namespace chrome {  #if !defined(DISABLE_NACL) +namespace { +base::LazyInstance<scoped_refptr<IPC::SyncMessageFilter> > +    g_background_thread_sender = LAZY_INSTANCE_INITIALIZER; +}  // namespace +  // Launch NaCl's sel_ldr process.  bool LaunchSelLdr(const char* alleged_url, int socket_count,                    void* imc_handles, void* nacl_process_handle,                    int* nacl_process_id) {    std::vector<nacl::FileDescriptor> sockets;    base::ProcessHandle nacl_process; -  if (!RenderThread::Get()->Send( +  IPC::Message::Sender* sender = RenderThread::Get(); +  if (sender == NULL) { +    sender = g_background_thread_sender.Pointer()->get(); +  } +  if (!sender->Send(        new ChromeViewHostMsg_LaunchNaCl(            ASCIIToWide(alleged_url),            socket_count, @@ -62,10 +73,16 @@ bool Are3DInterfacesDisabled() {    return CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisable3DAPIs);  } +void EnableBackgroundSelLdrLaunch() { +  g_background_thread_sender.Get() = +      RenderThread::Get()->GetSyncMessageFilter(); +} +  const PPB_NaCl_Private ppb_nacl = {    &LaunchSelLdr,    &UrandomFD,    &Are3DInterfacesDisabled, +  &EnableBackgroundSelLdrLaunch,  };  class PPB_NaCl_Impl { diff --git a/content/public/renderer/render_thread.h b/content/public/renderer/render_thread.h index 2140e70..83cb664 100644 --- a/content/public/renderer/render_thread.h +++ b/content/public/renderer/render_thread.h @@ -18,6 +18,7 @@ class MessageLoop;  namespace IPC {  class SyncChannel; +class SyncMessageFilter;  }  namespace v8 { @@ -41,6 +42,7 @@ class CONTENT_EXPORT RenderThread : public IPC::Message::Sender {    virtual MessageLoop* GetMessageLoop() = 0;    virtual IPC::SyncChannel* GetChannel() = 0;    virtual std::string GetLocale() = 0; +  virtual IPC::SyncMessageFilter* GetSyncMessageFilter() = 0;    // Called to add or remove a listener for a particular message routing ID.    // These methods normally get delegated to a MessageRouter. diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc index ff7df27..a041531 100644 --- a/content/renderer/render_thread_impl.cc +++ b/content/renderer/render_thread_impl.cc @@ -361,6 +361,10 @@ std::string RenderThreadImpl::GetLocale() {    return lang;  } +IPC::SyncMessageFilter* RenderThreadImpl::GetSyncMessageFilter() { +  return sync_message_filter(); +} +  void RenderThreadImpl::AddRoute(int32 routing_id,                                  IPC::Channel::Listener* listener) {    widget_count_++; diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h index f3f82a1..1b2e58e 100644 --- a/content/renderer/render_thread_impl.h +++ b/content/renderer/render_thread_impl.h @@ -85,6 +85,7 @@ class CONTENT_EXPORT RenderThreadImpl : public content::RenderThread,    virtual MessageLoop* GetMessageLoop() OVERRIDE;    virtual IPC::SyncChannel* GetChannel() OVERRIDE;    virtual std::string GetLocale() OVERRIDE; +  virtual IPC::SyncMessageFilter* GetSyncMessageFilter() OVERRIDE;    virtual void AddRoute(int32 routing_id,                          IPC::Channel::Listener* listener) OVERRIDE;    virtual void RemoveRoute(int32 routing_id) OVERRIDE; diff --git a/content/test/mock_render_thread.cc b/content/test/mock_render_thread.cc index 0dc5ca0..1663531 100644 --- a/content/test/mock_render_thread.cc +++ b/content/test/mock_render_thread.cc @@ -67,6 +67,10 @@ std::string MockRenderThread::GetLocale() {    return std::string();  } +IPC::SyncMessageFilter* MockRenderThread::GetSyncMessageFilter() { +  return NULL; +} +  void MockRenderThread::AddRoute(int32 routing_id,                                  IPC::Channel::Listener* listener) {    EXPECT_EQ(routing_id_, routing_id); diff --git a/content/test/mock_render_thread.h b/content/test/mock_render_thread.h index 0c083a7..d89ea73 100644 --- a/content/test/mock_render_thread.h +++ b/content/test/mock_render_thread.h @@ -39,6 +39,7 @@ class MockRenderThread : public content::RenderThread {    virtual MessageLoop* GetMessageLoop() OVERRIDE;    virtual IPC::SyncChannel* GetChannel() OVERRIDE;    virtual std::string GetLocale() OVERRIDE; +  virtual IPC::SyncMessageFilter* GetSyncMessageFilter() OVERRIDE;    virtual void AddRoute(int32 routing_id,                          IPC::Channel::Listener* listener) OVERRIDE;    virtual void RemoveRoute(int32 routing_id) OVERRIDE; diff --git a/ppapi/c/private/ppb_nacl_private.h b/ppapi/c/private/ppb_nacl_private.h index b741ae2..e275a90 100644 --- a/ppapi/c/private/ppb_nacl_private.h +++ b/ppapi/c/private/ppb_nacl_private.h @@ -16,7 +16,8 @@ struct PPB_NaCl_Private {    // write |socket_count| nacl::Handles to imc_handles and will write the    // nacl::Handle of the created process to |nacl_process_handle|.  Finally,    // the function will write the process ID of the created process to -  // |nacl_process_id|. +  // |nacl_process_id|.  Unless EnableBackgroundSelLdrLaunch is called, this +  // method must be invoked from the main thread.    bool (*LaunchSelLdr)(const char* alleged_url, int socket_count,                         void* imc_handles, void* nacl_process_handle,                         int* nacl_process_id); @@ -29,6 +30,9 @@ struct PPB_NaCl_Private {    // proxy. This is so paranoid admins can effectively prevent untrusted shader    // code to be processed by the graphics stack.    bool (*Are3DInterfacesDisabled)(); + +  // Enables the creation of sel_ldr processes from other than the main thread. +  void (*EnableBackgroundSelLdrLaunch)();  };  #endif  // PPAPI_C_PRIVATE_PPB_NACL_PRIVATE_H_ diff --git a/ppapi/native_client/src/trusted/plugin/module_ppapi.cc b/ppapi/native_client/src/trusted/plugin/module_ppapi.cc index 894dc37..6cde6b8c 100644 --- a/ppapi/native_client/src/trusted/plugin/module_ppapi.cc +++ b/ppapi/native_client/src/trusted/plugin/module_ppapi.cc @@ -35,18 +35,18 @@ class ModulePpapi : public pp::Module {    virtual bool Init() {      // Ask the browser for an interface which provides missing functions -    const PPB_NaCl_Private* ptr = reinterpret_cast<const PPB_NaCl_Private*>( +    private_interface_ = reinterpret_cast<const PPB_NaCl_Private*>(          GetBrowserInterface(PPB_NACL_PRIVATE_INTERFACE)); -    if (NULL == ptr) { +    if (NULL == private_interface_) {        MODULE_PRINTF(("ModulePpapi::Init failed: "                       "GetBrowserInterface returned NULL\n"));        return false;      }      launch_nacl_process = reinterpret_cast<LaunchNaClProcessFunc>( -        ptr->LaunchSelLdr); -    get_urandom_fd = ptr->UrandomFD; +        private_interface_->LaunchSelLdr); +    get_urandom_fd = private_interface_->UrandomFD;      // In the plugin, we don't need high resolution time of day.      NaClAllowLowResolutionTimeOfDay(); @@ -63,6 +63,9 @@ class ModulePpapi : public pp::Module {    virtual pp::Instance* CreateInstance(PP_Instance pp_instance) {      MODULE_PRINTF(("ModulePpapi::CreateInstance (pp_instance=%"NACL_PRId32")\n",                     pp_instance)); +    // This must be called from here rather than Init, as it relies on +    // chrome state that is not set at the time Init runs. +    private_interface_->EnableBackgroundSelLdrLaunch();      Plugin* plugin = Plugin::New(pp_instance);      MODULE_PRINTF(("ModulePpapi::CreateInstance (return %p)\n",                     static_cast<void* >(plugin))); @@ -71,6 +74,7 @@ class ModulePpapi : public pp::Module {   private:    bool init_was_successful_; +  const PPB_NaCl_Private* private_interface_;  };  }  // namespace plugin | 
