Skip to content

Commit

Permalink
Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30
Browse files Browse the repository at this point in the history
Also apply mojo 8fda9302f51f99dc25e6e0c95cfd0a04e1adc802 (https://codereview.chromium.org/902783004/).

Also apply mojo e62ed5fbf8bb4d7cfa87f499b1d1b50bdf8e0b3b (https://codereview.chromium.org/905253005/).

Also apply dcf5a5e1dbccb91f774d545b5f31d06042d8a8e3 (https://codereview.chromium.org/909903003/).

Also apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/).

(Reland of https://crrev.com/2e86fb9356e3a693762d3c86c70e63951bd9d1be a.k.a. refs/heads/master@{#315432}.)

TBR=jamesr@chromium.org
NOPRESUBMIT=true
CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win8_chromium_gn_dbg,win8_chromium_gn_rel

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

Cr-Commit-Position: refs/heads/master@{#315471}
  • Loading branch information
viettrungluu-cr authored and Commit bot committed Feb 10, 2015
1 parent c2a67e9 commit 17e878c
Show file tree
Hide file tree
Showing 74 changed files with 1,531 additions and 437 deletions.
74 changes: 42 additions & 32 deletions third_party/mojo/src/mojo/edk/embedder/embedder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "mojo/edk/embedder/embedder_internal.h"
#include "mojo/edk/embedder/platform_support.h"
#include "mojo/edk/system/channel.h"
#include "mojo/edk/system/channel_endpoint.h"
#include "mojo/edk/system/channel_manager.h"
#include "mojo/edk/system/configuration.h"
#include "mojo/edk/system/core.h"
Expand Down Expand Up @@ -55,9 +54,15 @@ namespace internal {
PlatformSupport* g_platform_support = nullptr;
system::Core* g_core = nullptr;
system::ChannelManager* g_channel_manager = nullptr;
MasterProcessDelegate* g_master_process_delegate = nullptr;
SlaveProcessDelegate* g_slave_process_delegate = nullptr;

} // namespace internal

Configuration* GetConfiguration() {
return system::GetMutableConfiguration();
}

void Init(scoped_ptr<PlatformSupport> platform_support) {
DCHECK(platform_support);

Expand All @@ -72,8 +77,27 @@ void Init(scoped_ptr<PlatformSupport> platform_support) {
new system::ChannelManager(internal::g_platform_support);
}

Configuration* GetConfiguration() {
return system::GetMutableConfiguration();
void InitMaster(scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
MasterProcessDelegate* master_process_delegate,
scoped_refptr<base::TaskRunner> io_thread_task_runner) {
// |Init()| must have already been called.
DCHECK(internal::g_core);

// TODO(vtl): This is temporary. We really want to construct a
// |MasterConnectionManager| here, which will in turn hold on to the delegate.
internal::g_master_process_delegate = master_process_delegate;
}

void InitSlave(scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
SlaveProcessDelegate* slave_process_delegate,
scoped_refptr<base::TaskRunner> io_thread_task_runner,
ScopedPlatformHandle platform_handle) {
// |Init()| must have already been called.
DCHECK(internal::g_core);

// TODO(vtl): This is temporary. We really want to construct a
// |SlaveConnectionManager| here, which will in turn hold on to the delegate.
internal::g_slave_process_delegate = slave_process_delegate;
}

// TODO(vtl): Write tests for this.
Expand All @@ -83,18 +107,16 @@ ScopedMessagePipeHandle CreateChannelOnIOThread(
DCHECK(platform_handle.is_valid());
DCHECK(channel_info);

scoped_refptr<system::ChannelEndpoint> channel_endpoint;
*channel_info = new ChannelInfo(MakeChannelId());
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
internal::g_channel_manager->CreateChannelOnIOThread(
(*channel_info)->channel_id, platform_handle.Pass());

DCHECK(internal::g_core);
ScopedMessagePipeHandle rv(
MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));

*channel_info = new ChannelInfo(MakeChannelId());
internal::g_channel_manager->CreateChannelOnIOThread(
(*channel_info)->channel_id, platform_handle.Pass(), channel_endpoint);

CHECK(rv.is_valid());
// TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it
// once that's fixed.
return rv.Pass();
}

Expand All @@ -107,31 +129,19 @@ ScopedMessagePipeHandle CreateChannel(
DCHECK(io_thread_task_runner);
DCHECK(!callback.is_null());

scoped_refptr<system::ChannelEndpoint> channel_endpoint;
system::ChannelId channel_id = MakeChannelId();
scoped_ptr<ChannelInfo> channel_info(new ChannelInfo(channel_id));
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(&channel_endpoint);
internal::g_channel_manager->CreateChannel(
channel_id, platform_handle.Pass(), io_thread_task_runner,
base::Bind(callback, base::Unretained(channel_info.release())),
callback_thread_task_runner);

DCHECK(internal::g_core);
ScopedMessagePipeHandle rv(
MessagePipeHandle(internal::g_core->AddDispatcher(dispatcher)));

// We'll have to set |channel_info->channel_id| on the I/O thread.
scoped_ptr<ChannelInfo> channel_info(new ChannelInfo());

if (rv.is_valid()) {
system::ChannelId channel_id = MakeChannelId();
channel_info->channel_id = channel_id;
internal::g_channel_manager->CreateChannel(
channel_id, platform_handle.Pass(), channel_endpoint,
io_thread_task_runner,
base::Bind(callback, base::Unretained(channel_info.release())),
callback_thread_task_runner);
} else {
(callback_thread_task_runner ? callback_thread_task_runner
: io_thread_task_runner)
->PostTask(FROM_HERE, base::Bind(callback, channel_info.release()));
}

CHECK(rv.is_valid());
// TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it
// once that's fixed.
return rv.Pass();
}

Expand Down
33 changes: 30 additions & 3 deletions third_party/mojo/src/mojo/edk/embedder/embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,42 @@ namespace mojo {
namespace embedder {

struct Configuration;
class MasterProcessDelegate;
class PlatformSupport;
class SlaveProcessDelegate;

// Returns the global configuration. In general, you should not need to change
// the configuration, but if you do you must do it before calling |Init()|.
MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();

// Must be called first, or just after setting configuration parameters, to
// initialize the (global, singleton) system.
MOJO_SYSTEM_IMPL_EXPORT void Init(scoped_ptr<PlatformSupport> platform_support);

// Returns the global configuration. In general, you should not need to change
// the configuration, but if you do you must do it before calling |Init()|.
MOJO_SYSTEM_IMPL_EXPORT Configuration* GetConfiguration();
// Initializes a master process. To be called after |Init()|.
// |master_process_delegate| should live forever (or until after
// |mojo::embedder::test::Shutdown()|); its methods will be called using
// |delegate_thread_task_runner|, which must be the task runner for the thread
// calling |InitMaster()|. |io_thread_task_runner| should be the task runner for
// some I/O thread; this should be the same as that provided to
// |CreateChannel()| (or on which |CreateChannelOnIOThread()| is called).
// TODO(vtl): Remove the |io_thread_task_runner| argument from
// |CreateChannel()| (and eventually |CreateChannel()| altogether) and require
// that either this or |InitSlave()| be called. Currently, |CreateChannel()| can
// be used with different I/O threads, but this capability will be removed.
MOJO_SYSTEM_IMPL_EXPORT void InitMaster(
scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
MasterProcessDelegate* master_process_delegate,
scoped_refptr<base::TaskRunner> io_thread_task_runner);

// Initializes a slave process. Similar to |InitMaster()| (see above).
// |platform_handle| should be connected to the handle passed to |AddSlave()|.
// TODO(vtl): |AddSlave()| doesn't exist yet.
MOJO_SYSTEM_IMPL_EXPORT void InitSlave(
scoped_refptr<base::TaskRunner> delegate_thread_task_runner,
SlaveProcessDelegate* slave_process_delegate,
scoped_refptr<base::TaskRunner> io_thread_task_runner,
ScopedPlatformHandle platform_handle);

// A "channel" is a connection on top of an OS "pipe", on top of which Mojo
// message pipes (etc.) can be multiplexed. It must "live" on some I/O thread.
Expand Down
9 changes: 9 additions & 0 deletions third_party/mojo/src/mojo/edk/embedder/embedder_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ typedef uint64_t ChannelId;
namespace embedder {

class PlatformSupport;
// TODO(vtl): Remove these (see below).
class MasterProcessDelegate;
class SlaveProcessDelegate;

// This is a type that's opaque to users of the embedder API (which only
// gives/takes |ChannelInfo*|s). We make it a struct to make it
Expand All @@ -49,6 +52,12 @@ extern system::Core* g_core;
// (|mojo::embedder::CreateChannel()|, etc.).
extern system::ChannelManager* g_channel_manager;

// TODO(vtl): Remove these: We'll eventually really want to hold on to a
// |MasterConnectionManager*| or a |SlaveConnectionManager*|. For now, keep
// these around as globals to avoid triggering leak detectors.
extern MasterProcessDelegate* g_master_process_delegate;
extern SlaveProcessDelegate* g_slave_process_delegate;

} // namespace internal

} // namepace embedder
Expand Down
18 changes: 15 additions & 3 deletions third_party/mojo/src/mojo/edk/js/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

import("../mojo_edk.gni")

# TODO(hansmuller): The organization of tests in this directory is weird:
# * Really, js_unittests tests public stuff, so that should live in public
# and be reworked as some sort of apptest.
# * Both js_unittests and js_integration_tests should auto-generate their
# tests somehow. The .cc files are just test runner stubs, including
# explicit lists of .js files.
group("tests") {
testonly = true
deps = [
"test:js_unittests",
"test:js_integration_tests",
]
}

mojo_edk_source_set("js") {
sources = [
"core.cc",
Expand Down Expand Up @@ -50,7 +64,5 @@ mojo_edk_source_set("js_unittests") {
"mojo/edk/test:test_support",
]

mojo_sdk_deps = [
"mojo/public/cpp/system",
]
mojo_sdk_deps = [ "mojo/public/cpp/system" ]
}
4 changes: 2 additions & 2 deletions third_party/mojo/src/mojo/edk/system/channel_endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ void ChannelEndpoint::AttachAndRun(Channel* channel,
remote_id_ = remote_id;

while (!channel_message_queue_.IsEmpty()) {
LOG_IF(WARNING, !WriteMessageNoLock(channel_message_queue_.GetMessage()))
<< "Failed to write enqueue message to channel";
bool ok = WriteMessageNoLock(channel_message_queue_.GetMessage());
LOG_IF(WARNING, !ok) << "Failed to write enqueue message to channel";
}

if (!client_) {
Expand Down
3 changes: 3 additions & 0 deletions third_party/mojo/src/mojo/edk/system/channel_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <algorithm>

#include "base/task_runner.h"
#include "mojo/edk/system/channel.h"

namespace mojo {
namespace system {

Expand Down
67 changes: 43 additions & 24 deletions third_party/mojo/src/mojo/edk/system/channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "base/location.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/task_runner.h"
#include "mojo/edk/system/channel.h"
#include "mojo/edk/system/channel_endpoint.h"
#include "mojo/edk/system/message_pipe_dispatcher.h"

namespace mojo {
namespace system {
Expand Down Expand Up @@ -38,46 +41,39 @@ ChannelManager::~ChannelManager() {
ShutdownChannelHelper(map_elem.second);
}

void ChannelManager::CreateChannelOnIOThread(
scoped_refptr<MessagePipeDispatcher> ChannelManager::CreateChannelOnIOThread(
ChannelId channel_id,
embedder::ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint) {
DCHECK_NE(channel_id, kInvalidChannelId);
DCHECK(platform_handle.is_valid());
DCHECK(bootstrap_channel_endpoint);

// Create and initialize a |system::Channel|.
scoped_refptr<system::Channel> channel =
new system::Channel(platform_support_);
channel->Init(system::RawChannel::Create(platform_handle.Pass()));
channel->SetBootstrapEndpoint(bootstrap_channel_endpoint);

{
base::AutoLock locker(lock_);
CHECK(channel_infos_.find(channel_id) == channel_infos_.end());
channel_infos_[channel_id] =
ChannelInfo(channel, base::MessageLoopProxy::current());
}
channel->SetChannelManager(this);
embedder::ScopedPlatformHandle platform_handle) {
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint;
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(
&bootstrap_channel_endpoint);
CreateChannelOnIOThreadHelper(channel_id, platform_handle.Pass(),
bootstrap_channel_endpoint);
return dispatcher;
}

void ChannelManager::CreateChannel(
scoped_refptr<MessagePipeDispatcher> ChannelManager::CreateChannel(
ChannelId channel_id,
embedder::ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint,
scoped_refptr<base::TaskRunner> io_thread_task_runner,
base::Closure callback,
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
DCHECK(io_thread_task_runner);
DCHECK(!callback.is_null());
// (|callback_thread_task_runner| may be null.)

scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint;
scoped_refptr<system::MessagePipeDispatcher> dispatcher =
system::MessagePipeDispatcher::CreateRemoteMessagePipe(
&bootstrap_channel_endpoint);
io_thread_task_runner->PostTask(
FROM_HERE,
base::Bind(&ChannelManager::CreateChannelHelper, base::Unretained(this),
channel_id, base::Passed(&platform_handle),
bootstrap_channel_endpoint, callback,
callback_thread_task_runner));
return dispatcher;
}

scoped_refptr<Channel> ChannelManager::GetChannel(ChannelId channel_id) const {
Expand All @@ -103,14 +99,37 @@ void ChannelManager::ShutdownChannel(ChannelId channel_id) {
ShutdownChannelHelper(channel_info);
}

void ChannelManager::CreateChannelOnIOThreadHelper(
ChannelId channel_id,
embedder::ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint) {
DCHECK_NE(channel_id, kInvalidChannelId);
DCHECK(platform_handle.is_valid());
DCHECK(bootstrap_channel_endpoint);

// Create and initialize a |system::Channel|.
scoped_refptr<system::Channel> channel =
new system::Channel(platform_support_);
channel->Init(system::RawChannel::Create(platform_handle.Pass()));
channel->SetBootstrapEndpoint(bootstrap_channel_endpoint);

{
base::AutoLock locker(lock_);
CHECK(channel_infos_.find(channel_id) == channel_infos_.end());
channel_infos_[channel_id] =
ChannelInfo(channel, base::MessageLoopProxy::current());
}
channel->SetChannelManager(this);
}

void ChannelManager::CreateChannelHelper(
ChannelId channel_id,
embedder::ScopedPlatformHandle platform_handle,
scoped_refptr<system::ChannelEndpoint> bootstrap_channel_endpoint,
base::Closure callback,
scoped_refptr<base::TaskRunner> callback_thread_task_runner) {
CreateChannelOnIOThread(channel_id, platform_handle.Pass(),
bootstrap_channel_endpoint);
CreateChannelOnIOThreadHelper(channel_id, platform_handle.Pass(),
bootstrap_channel_endpoint);
if (callback_thread_task_runner)
callback_thread_task_runner->PostTask(FROM_HERE, callback);
else
Expand Down
Loading

0 comments on commit 17e878c

Please sign in to comment.