Commit 2f16fdd0 authored by yusukes's avatar yusukes Committed by Commit bot

Merge NaClIPCAdapter::set_resolve_file_token_callback() into the constructor

to ensure that the callback function is set before ConnectChannel()
is called. This prevents a potential race condition that could occur
if messages were pending when ipc_adapter->ConnectChannel() is called.

TEST=git cl try, ARC still works, PNaCl demo still works
BUG=nativeclient:3802

Review URL: https://codereview.chromium.org/1090043002

Cr-Commit-Position: refs/heads/master@{#325535}
parent 631a0021
...@@ -325,10 +325,12 @@ NaClIPCAdapter::IOThreadData::~IOThreadData() { ...@@ -325,10 +325,12 @@ NaClIPCAdapter::IOThreadData::~IOThreadData() {
} }
NaClIPCAdapter::NaClIPCAdapter(const IPC::ChannelHandle& handle, NaClIPCAdapter::NaClIPCAdapter(const IPC::ChannelHandle& handle,
base::TaskRunner* runner) base::TaskRunner* runner,
ResolveFileTokenCallback resolve_file_token_cb)
: lock_(), : lock_(),
cond_var_(&lock_), cond_var_(&lock_),
task_runner_(runner), task_runner_(runner),
resolve_file_token_cb_(resolve_file_token_cb),
locked_data_() { locked_data_() {
io_thread_data_.channel_ = IPC::Channel::CreateServer(handle, this); io_thread_data_.channel_ = IPC::Channel::CreateServer(handle, this);
// Note, we can not PostTask for ConnectChannelOnIOThread here. If we did, // Note, we can not PostTask for ConnectChannelOnIOThread here. If we did,
......
...@@ -72,6 +72,14 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>, ...@@ -72,6 +72,14 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
}; };
#pragma pack(pop) #pragma pack(pop)
typedef base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)>
ResolveFileTokenReplyCallback;
typedef base::Callback<void(uint64_t, // file_token_lo
uint64_t, // file_token_hi
ResolveFileTokenReplyCallback)>
ResolveFileTokenCallback;
// Creates an adapter, using the thread associated with the given task // Creates an adapter, using the thread associated with the given task
// runner for posting messages. In normal use, the task runner will post to // runner for posting messages. In normal use, the task runner will post to
// the I/O thread of the process. // the I/O thread of the process.
...@@ -79,7 +87,15 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>, ...@@ -79,7 +87,15 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
// If you use this constructor, you MUST call ConnectChannel after the // If you use this constructor, you MUST call ConnectChannel after the
// NaClIPCAdapter is constructed, or the NaClIPCAdapter's channel will not be // NaClIPCAdapter is constructed, or the NaClIPCAdapter's channel will not be
// connected. // connected.
NaClIPCAdapter(const IPC::ChannelHandle& handle, base::TaskRunner* runner); //
// |resolve_file_token_cb| is an optional callback to be invoked for
// resolving file tokens received from the renderer. When the file token
// is resolved, the ResolveFileTokenReplyCallback passed inside the
// ResolveFileTokenCallback will be invoked.
NaClIPCAdapter(
const IPC::ChannelHandle& handle,
base::TaskRunner* runner,
ResolveFileTokenCallback resolve_file_token_cb);
// Initializes with a given channel that's already created for testing // Initializes with a given channel that's already created for testing
// purposes. This function will take ownership of the given channel. // purposes. This function will take ownership of the given channel.
...@@ -115,22 +131,6 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>, ...@@ -115,22 +131,6 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
void OnChannelConnected(int32 peer_pid) override; void OnChannelConnected(int32 peer_pid) override;
void OnChannelError() override; void OnChannelError() override;
typedef base::Callback<void(IPC::PlatformFileForTransit, base::FilePath)>
ResolveFileTokenReplyCallback;
typedef base::Callback<void(uint64_t, // file_token_lo
uint64_t, // file_token_hi
ResolveFileTokenReplyCallback)>
ResolveFileTokenCallback;
// Sets a callback to be invoked for resolving file tokens received from the
// renderer. When the file token is resolved, the
// ResolveFileTokenReplyCallback passed inside the ResolveFileTokenCallback
// will be invoked.
void set_resolve_file_token_callback(ResolveFileTokenCallback cb) {
resolve_file_token_cb_ = cb;
}
private: private:
friend class base::RefCountedThreadSafe<NaClIPCAdapter>; friend class base::RefCountedThreadSafe<NaClIPCAdapter>;
......
...@@ -139,13 +139,16 @@ void DebugStubPortSelectedHandler(uint16_t port) { ...@@ -139,13 +139,16 @@ void DebugStubPortSelectedHandler(uint16_t port) {
// the given message_loop_proxy runs. // the given message_loop_proxy runs.
// Also, creates and sets the corresponding NaClDesc to the given nap with // Also, creates and sets the corresponding NaClDesc to the given nap with
// the FD #. // the FD #.
scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter( void SetUpIPCAdapter(
IPC::ChannelHandle* handle, IPC::ChannelHandle* handle,
scoped_refptr<base::MessageLoopProxy> message_loop_proxy, scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
struct NaClApp* nap, struct NaClApp* nap,
int nacl_fd) { int nacl_fd,
NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb) {
scoped_refptr<NaClIPCAdapter> ipc_adapter( scoped_refptr<NaClIPCAdapter> ipc_adapter(
new NaClIPCAdapter(*handle, message_loop_proxy.get())); new NaClIPCAdapter(*handle,
message_loop_proxy.get(),
resolve_file_token_cb));
ipc_adapter->ConnectChannel(); ipc_adapter->ConnectChannel();
#if defined(OS_POSIX) #if defined(OS_POSIX)
handle->socket = handle->socket =
...@@ -155,7 +158,6 @@ scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter( ...@@ -155,7 +158,6 @@ scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter(
// Pass a NaClDesc to the untrusted side. This will hold a ref to the // Pass a NaClDesc to the untrusted side. This will hold a ref to the
// NaClIPCAdapter. // NaClIPCAdapter.
NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc());
return ipc_adapter;
} }
} // namespace } // namespace
...@@ -311,17 +313,17 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) { ...@@ -311,17 +313,17 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
// (browser/renderer) processes. The IRT uses these channels to // (browser/renderer) processes. The IRT uses these channels to
// communicate with the host and to initialize the IPC dispatchers. // communicate with the host and to initialize the IPC dispatchers.
SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE); nap, NACL_CHROME_DESC_BASE,
NaClIPCAdapter::ResolveFileTokenCallback());
SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(),
nap, NACL_CHROME_DESC_BASE + 1); nap, NACL_CHROME_DESC_BASE + 1,
NaClIPCAdapter::ResolveFileTokenCallback());
scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter =
SetUpIPCAdapter(&manifest_service_handle, SetUpIPCAdapter(&manifest_service_handle,
io_thread_.message_loop_proxy(), io_thread_.message_loop_proxy(),
nap, nap,
NACL_CHROME_DESC_BASE + 2); NACL_CHROME_DESC_BASE + 2,
manifest_ipc_adapter->set_resolve_file_token_callback( base::Bind(&NaClListener::ResolveFileToken,
base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this))); base::Unretained(this)));
} }
trusted_listener_ = new NaClTrustedListener( trusted_listener_ = new NaClTrustedListener(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment