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() {
}
NaClIPCAdapter::NaClIPCAdapter(const IPC::ChannelHandle& handle,
base::TaskRunner* runner)
base::TaskRunner* runner,
ResolveFileTokenCallback resolve_file_token_cb)
: lock_(),
cond_var_(&lock_),
task_runner_(runner),
resolve_file_token_cb_(resolve_file_token_cb),
locked_data_() {
io_thread_data_.channel_ = IPC::Channel::CreateServer(handle, this);
// Note, we can not PostTask for ConnectChannelOnIOThread here. If we did,
......
......@@ -72,6 +72,14 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
};
#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
// runner for posting messages. In normal use, the task runner will post to
// the I/O thread of the process.
......@@ -79,7 +87,15 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
// If you use this constructor, you MUST call ConnectChannel after the
// NaClIPCAdapter is constructed, or the NaClIPCAdapter's channel will not be
// 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
// purposes. This function will take ownership of the given channel.
......@@ -115,22 +131,6 @@ class NaClIPCAdapter : public base::RefCountedThreadSafe<NaClIPCAdapter>,
void OnChannelConnected(int32 peer_pid) 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:
friend class base::RefCountedThreadSafe<NaClIPCAdapter>;
......
......@@ -139,13 +139,16 @@ void DebugStubPortSelectedHandler(uint16_t port) {
// the given message_loop_proxy runs.
// Also, creates and sets the corresponding NaClDesc to the given nap with
// the FD #.
scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter(
void SetUpIPCAdapter(
IPC::ChannelHandle* handle,
scoped_refptr<base::MessageLoopProxy> message_loop_proxy,
struct NaClApp* nap,
int nacl_fd) {
int nacl_fd,
NaClIPCAdapter::ResolveFileTokenCallback resolve_file_token_cb) {
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();
#if defined(OS_POSIX)
handle->socket =
......@@ -155,7 +158,6 @@ scoped_refptr<NaClIPCAdapter> SetUpIPCAdapter(
// Pass a NaClDesc to the untrusted side. This will hold a ref to the
// NaClIPCAdapter.
NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc());
return ipc_adapter;
}
} // namespace
......@@ -311,17 +313,17 @@ void NaClListener::OnStart(const nacl::NaClStartParams& params) {
// (browser/renderer) processes. The IRT uses these channels to
// communicate with the host and to initialize the IPC dispatchers.
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(),
nap, NACL_CHROME_DESC_BASE + 1);
scoped_refptr<NaClIPCAdapter> manifest_ipc_adapter =
SetUpIPCAdapter(&manifest_service_handle,
io_thread_.message_loop_proxy(),
nap,
NACL_CHROME_DESC_BASE + 2);
manifest_ipc_adapter->set_resolve_file_token_callback(
base::Bind(&NaClListener::ResolveFileToken, base::Unretained(this)));
nap, NACL_CHROME_DESC_BASE + 1,
NaClIPCAdapter::ResolveFileTokenCallback());
SetUpIPCAdapter(&manifest_service_handle,
io_thread_.message_loop_proxy(),
nap,
NACL_CHROME_DESC_BASE + 2,
base::Bind(&NaClListener::ResolveFileToken,
base::Unretained(this)));
}
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