diff options
Diffstat (limited to 'mojo/shell/background')
-rw-r--r-- | mojo/shell/background/background_shell.cc | 26 | ||||
-rw-r--r-- | mojo/shell/background/background_shell.h | 8 | ||||
-rw-r--r-- | mojo/shell/background/tests/test_catalog_store.cc | 16 |
3 files changed, 39 insertions, 11 deletions
diff --git a/mojo/shell/background/background_shell.cc b/mojo/shell/background/background_shell.cc index ed1d5c5..a21bbe4 100644 --- a/mojo/shell/background/background_shell.cc +++ b/mojo/shell/background/background_shell.cc @@ -102,6 +102,11 @@ class BackgroundShell::MojoThread : public base::SimpleThread { Join(); } + void RunShellCallback(const BackgroundShell::ShellThreadCallback& callback) { + DCHECK_EQ(message_loop_, base::MessageLoop::current()); + callback.Run(context_->shell()); + } + // base::SimpleThread: void Start() override { DCHECK(!message_loop_); @@ -113,12 +118,6 @@ class BackgroundShell::MojoThread : public base::SimpleThread { // in the order here. scoped_ptr<base::MessageLoop> message_loop(message_loop_); - Context::EnsureEmbedderIsInitialized(); - - message_loop_->BindToCurrentThread(); - - scoped_ptr<Context> context(new Context); - context_ = context.get(); scoped_ptr<mojo::shell::Context::InitParams> context_init_params( new mojo::shell::Context::InitParams); if (init_params_) { @@ -126,7 +125,15 @@ class BackgroundShell::MojoThread : public base::SimpleThread { std::move(init_params_->catalog_store); context_init_params->native_runner_delegate = init_params_->native_runner_delegate; + context_init_params->init_edk = init_params_->init_edk; } + if (context_init_params->init_edk) + Context::EnsureEmbedderIsInitialized(); + + message_loop_->BindToCurrentThread(); + + scoped_ptr<Context> context(new Context); + context_ = context.get(); context_->Init(std::move(context_init_params)); message_loop_->Run(); @@ -191,5 +198,12 @@ mojom::ShellClientRequest BackgroundShell::CreateShellClientRequest( return request; } +void BackgroundShell::ExecuteOnShellThread( + const ShellThreadCallback& callback) { + thread_->message_loop()->task_runner()->PostTask( + FROM_HERE, base::Bind(&MojoThread::RunShellCallback, + base::Unretained(thread_.get()), callback)); +} + } // namespace shell } // namespace mojo diff --git a/mojo/shell/background/background_shell.h b/mojo/shell/background/background_shell.h index 7af3714..070b5b1 100644 --- a/mojo/shell/background/background_shell.h +++ b/mojo/shell/background/background_shell.h @@ -21,6 +21,7 @@ namespace mojo { namespace shell { class NativeRunnerDelegate; +class Shell; // BackgroundShell starts up the mojo shell on a background thread, and // destroys the thread in the destructor. Once created use CreateApplication() @@ -34,6 +35,8 @@ class BackgroundShell { NativeRunnerDelegate* native_runner_delegate = nullptr; scoped_ptr<catalog::Store> catalog_store; + // If true the edk is initialized. + bool init_edk = true; }; BackgroundShell(); @@ -47,6 +50,11 @@ class BackgroundShell { mojom::ShellClientRequest CreateShellClientRequest( const std::string& name); + // Use to do processing on the thread running the shell. The callback is + // supplied a pointer to the Shell. The callback does *not* own the Shell. + using ShellThreadCallback = base::Callback<void(Shell*)>; + void ExecuteOnShellThread(const ShellThreadCallback& callback); + private: class MojoThread; diff --git a/mojo/shell/background/tests/test_catalog_store.cc b/mojo/shell/background/tests/test_catalog_store.cc index 32a1aa4..41daf82 100644 --- a/mojo/shell/background/tests/test_catalog_store.cc +++ b/mojo/shell/background/tests/test_catalog_store.cc @@ -28,14 +28,20 @@ scoped_ptr<base::DictionaryValue> BuildPermissiveSerializedAppInfo( scoped_ptr<base::DictionaryValue> app(new base::DictionaryValue); app->SetString(Store::kNameKey, name); app->SetString(Store::kDisplayNameKey, display_name); + app->SetInteger(Store::kManifestVersionKey, 1); scoped_ptr<base::DictionaryValue> capabilities(new base::DictionaryValue); - scoped_ptr<base::ListValue> interfaces(new base::ListValue); - interfaces->AppendString("*"); - capabilities->Set("*", std::move(interfaces)); - + scoped_ptr<base::DictionaryValue> required_capabilities( + new base::DictionaryValue); + scoped_ptr<base::DictionaryValue> interfaces_dictionary( + new base::DictionaryValue); + scoped_ptr<base::ListValue> interfaces_list(new base::ListValue); + interfaces_list->AppendString("*"); + interfaces_dictionary->Set("interfaces", std::move(interfaces_list)); + required_capabilities->Set("*", std::move(interfaces_dictionary)); + capabilities->Set(Store::kCapabilities_RequiredKey, + std::move(required_capabilities)); app->Set(Store::kCapabilitiesKey, std::move(capabilities)); - return app; } |