Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: content/common/service_manager/embedded_service_runner.cc

Issue 2952603002: Add support for specifying message loop type and thread priority for content mojo services (Closed)
Patch Set: Fixing includes Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/public/common/service_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/service_manager/embedded_service_runner.h" 5 #include "content/common/service_manager/embedded_service_runner.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 23
24 class EmbeddedServiceRunner::InstanceManager 24 class EmbeddedServiceRunner::InstanceManager
25 : public base::RefCountedThreadSafe<InstanceManager> { 25 : public base::RefCountedThreadSafe<InstanceManager> {
26 public: 26 public:
27 InstanceManager(const base::StringPiece& name, 27 InstanceManager(const base::StringPiece& name,
28 const ServiceInfo& info, 28 const ServiceInfo& info,
29 const base::Closure& quit_closure) 29 const base::Closure& quit_closure)
30 : name_(name.as_string()), 30 : name_(name.as_string()),
31 factory_callback_(info.factory), 31 factory_callback_(info.factory),
32 use_own_thread_(!info.task_runner && info.use_own_thread), 32 use_own_thread_(!info.task_runner && info.use_own_thread),
33 message_loop_type_(info.message_loop_type),
34 thread_priority_(info.thread_priority),
33 quit_closure_(quit_closure), 35 quit_closure_(quit_closure),
34 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()), 36 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()),
35 service_task_runner_(info.task_runner) { 37 service_task_runner_(info.task_runner) {
36 if (!use_own_thread_ && !service_task_runner_) 38 if (!use_own_thread_ && !service_task_runner_)
37 service_task_runner_ = base::ThreadTaskRunnerHandle::Get(); 39 service_task_runner_ = base::ThreadTaskRunnerHandle::Get();
38 } 40 }
39 41
40 void BindServiceRequest(service_manager::mojom::ServiceRequest request) { 42 void BindServiceRequest(service_manager::mojom::ServiceRequest request) {
41 DCHECK(runner_thread_checker_.CalledOnValidThread()); 43 DCHECK(runner_thread_checker_.CalledOnValidThread());
42 44
43 if (use_own_thread_ && !thread_) { 45 if (use_own_thread_ && !thread_) {
44 // Start a new thread if necessary. 46 // Start a new thread if necessary.
45 thread_.reset(new base::Thread(name_)); 47 thread_.reset(new base::Thread(name_));
46 thread_->Start(); 48 base::Thread::Options options;
49 options.message_loop_type = message_loop_type_;
50 options.priority = thread_priority_;
51 thread_->StartWithOptions(options);
47 service_task_runner_ = thread_->task_runner(); 52 service_task_runner_ = thread_->task_runner();
48 } 53 }
49 54
50 DCHECK(service_task_runner_); 55 DCHECK(service_task_runner_);
51 service_task_runner_->PostTask( 56 service_task_runner_->PostTask(
52 FROM_HERE, 57 FROM_HERE,
53 base::Bind(&InstanceManager::BindServiceRequestOnServiceThread, 58 base::Bind(&InstanceManager::BindServiceRequestOnServiceThread,
54 this, base::Passed(&request))); 59 this, base::Passed(&request)));
55 } 60 }
56 61
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 if (thread_) { 131 if (thread_) {
127 thread_.reset(); 132 thread_.reset();
128 service_task_runner_ = nullptr; 133 service_task_runner_ = nullptr;
129 } 134 }
130 quit_closure_.Run(); 135 quit_closure_.Run();
131 } 136 }
132 137
133 const std::string name_; 138 const std::string name_;
134 const ServiceInfo::ServiceFactory factory_callback_; 139 const ServiceInfo::ServiceFactory factory_callback_;
135 const bool use_own_thread_; 140 const bool use_own_thread_;
141 base::MessageLoop::Type message_loop_type_;
142 base::ThreadPriority thread_priority_;
136 const base::Closure quit_closure_; 143 const base::Closure quit_closure_;
137 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; 144 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_;
138 145
139 // Thread checker used to ensure certain operations happen only on the 146 // Thread checker used to ensure certain operations happen only on the
140 // runner's (i.e. our owner's) thread. 147 // runner's (i.e. our owner's) thread.
141 base::ThreadChecker runner_thread_checker_; 148 base::ThreadChecker runner_thread_checker_;
142 149
143 // These fields must only be accessed from the runner's thread. 150 // These fields must only be accessed from the runner's thread.
144 std::unique_ptr<base::Thread> thread_; 151 std::unique_ptr<base::Thread> thread_;
145 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_; 152 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 const base::Closure& quit_closure) { 193 const base::Closure& quit_closure) {
187 quit_closure_ = quit_closure; 194 quit_closure_ = quit_closure;
188 } 195 }
189 196
190 void EmbeddedServiceRunner::OnQuit() { 197 void EmbeddedServiceRunner::OnQuit() {
191 if (!quit_closure_.is_null()) 198 if (!quit_closure_.is_null())
192 quit_closure_.Run(); 199 quit_closure_.Run();
193 } 200 }
194 201
195 } // namespace content 202 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/common/service_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698