Commit 035f4552 authored by mfomitchev's avatar mfomitchev Committed by Commit Bot

Add support for specifying message loop type and thread priority for content mojo services

BUG=722527

Review-Url: https://codereview.chromium.org/2952603002
Cr-Commit-Position: refs/heads/master@{#480876}
parent 1aea7837
...@@ -30,6 +30,8 @@ class EmbeddedServiceRunner::InstanceManager ...@@ -30,6 +30,8 @@ class EmbeddedServiceRunner::InstanceManager
: name_(name.as_string()), : name_(name.as_string()),
factory_callback_(info.factory), factory_callback_(info.factory),
use_own_thread_(!info.task_runner && info.use_own_thread), use_own_thread_(!info.task_runner && info.use_own_thread),
message_loop_type_(info.message_loop_type),
thread_priority_(info.thread_priority),
quit_closure_(quit_closure), quit_closure_(quit_closure),
quit_task_runner_(base::ThreadTaskRunnerHandle::Get()), quit_task_runner_(base::ThreadTaskRunnerHandle::Get()),
service_task_runner_(info.task_runner) { service_task_runner_(info.task_runner) {
...@@ -43,7 +45,10 @@ class EmbeddedServiceRunner::InstanceManager ...@@ -43,7 +45,10 @@ class EmbeddedServiceRunner::InstanceManager
if (use_own_thread_ && !thread_) { if (use_own_thread_ && !thread_) {
// Start a new thread if necessary. // Start a new thread if necessary.
thread_.reset(new base::Thread(name_)); thread_.reset(new base::Thread(name_));
thread_->Start(); base::Thread::Options options;
options.message_loop_type = message_loop_type_;
options.priority = thread_priority_;
thread_->StartWithOptions(options);
service_task_runner_ = thread_->task_runner(); service_task_runner_ = thread_->task_runner();
} }
...@@ -133,6 +138,8 @@ class EmbeddedServiceRunner::InstanceManager ...@@ -133,6 +138,8 @@ class EmbeddedServiceRunner::InstanceManager
const std::string name_; const std::string name_;
const ServiceInfo::ServiceFactory factory_callback_; const ServiceInfo::ServiceFactory factory_callback_;
const bool use_own_thread_; const bool use_own_thread_;
base::MessageLoop::Type message_loop_type_;
base::ThreadPriority thread_priority_;
const base::Closure quit_closure_; const base::Closure quit_closure_;
const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_;
......
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
namespace service_manager { namespace service_manager {
...@@ -43,6 +45,14 @@ struct CONTENT_EXPORT ServiceInfo { ...@@ -43,6 +45,14 @@ struct CONTENT_EXPORT ServiceInfo {
// //
// If |task_runner| is not null, this value is ignored. // If |task_runner| is not null, this value is ignored.
bool use_own_thread = false; bool use_own_thread = false;
// If the service uses its own thread, this determines the type of the message
// loop used by the thread.
base::MessageLoop::Type message_loop_type = base::MessageLoop::TYPE_DEFAULT;
// If the service uses its own thread, this determines the priority of the
// thread.
base::ThreadPriority thread_priority = base::ThreadPriority::NORMAL;
}; };
} // namespace content } // namespace content
......
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