| OLD | NEW |
| 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 Loading... |
| 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 |
| 45 LOG(ERROR) << "EmbeddedServiceRunner::InstanceManager::BindServiceRequest: " |
| 46 << "name_=" << name_; |
| 43 if (use_own_thread_ && !thread_) { | 47 if (use_own_thread_ && !thread_) { |
| 48 LOG(ERROR) << 1; |
| 44 // Start a new thread if necessary. | 49 // Start a new thread if necessary. |
| 45 thread_.reset(new base::Thread(name_)); | 50 thread_.reset(new base::Thread(name_)); |
| 46 thread_->Start(); | 51 base::Thread::Options options; |
| 52 options.message_loop_type = message_loop_type_; |
| 53 options.priority = thread_priority_; |
| 54 thread_->StartWithOptions(options); |
| 47 service_task_runner_ = thread_->task_runner(); | 55 service_task_runner_ = thread_->task_runner(); |
| 48 } | 56 } |
| 49 | 57 |
| 50 DCHECK(service_task_runner_); | 58 DCHECK(service_task_runner_); |
| 51 service_task_runner_->PostTask( | 59 service_task_runner_->PostTask( |
| 52 FROM_HERE, | 60 FROM_HERE, |
| 53 base::Bind(&InstanceManager::BindServiceRequestOnServiceThread, | 61 base::Bind(&InstanceManager::BindServiceRequestOnServiceThread, |
| 54 this, base::Passed(&request))); | 62 this, base::Passed(&request))); |
| 55 } | 63 } |
| 56 | 64 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 if (thread_) { | 134 if (thread_) { |
| 127 thread_.reset(); | 135 thread_.reset(); |
| 128 service_task_runner_ = nullptr; | 136 service_task_runner_ = nullptr; |
| 129 } | 137 } |
| 130 quit_closure_.Run(); | 138 quit_closure_.Run(); |
| 131 } | 139 } |
| 132 | 140 |
| 133 const std::string name_; | 141 const std::string name_; |
| 134 const ServiceInfo::ServiceFactory factory_callback_; | 142 const ServiceInfo::ServiceFactory factory_callback_; |
| 135 const bool use_own_thread_; | 143 const bool use_own_thread_; |
| 144 base::MessageLoop::Type message_loop_type_; |
| 145 base::ThreadPriority thread_priority_; |
| 136 const base::Closure quit_closure_; | 146 const base::Closure quit_closure_; |
| 137 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; | 147 const scoped_refptr<base::SingleThreadTaskRunner> quit_task_runner_; |
| 138 | 148 |
| 139 // Thread checker used to ensure certain operations happen only on the | 149 // Thread checker used to ensure certain operations happen only on the |
| 140 // runner's (i.e. our owner's) thread. | 150 // runner's (i.e. our owner's) thread. |
| 141 base::ThreadChecker runner_thread_checker_; | 151 base::ThreadChecker runner_thread_checker_; |
| 142 | 152 |
| 143 // These fields must only be accessed from the runner's thread. | 153 // These fields must only be accessed from the runner's thread. |
| 144 std::unique_ptr<base::Thread> thread_; | 154 std::unique_ptr<base::Thread> thread_; |
| 145 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_; | 155 scoped_refptr<base::SingleThreadTaskRunner> service_task_runner_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 const base::Closure& quit_closure) { | 196 const base::Closure& quit_closure) { |
| 187 quit_closure_ = quit_closure; | 197 quit_closure_ = quit_closure; |
| 188 } | 198 } |
| 189 | 199 |
| 190 void EmbeddedServiceRunner::OnQuit() { | 200 void EmbeddedServiceRunner::OnQuit() { |
| 191 if (!quit_closure_.is_null()) | 201 if (!quit_closure_.is_null()) |
| 192 quit_closure_.Run(); | 202 quit_closure_.Run(); |
| 193 } | 203 } |
| 194 | 204 |
| 195 } // namespace content | 205 } // namespace content |
| OLD | NEW |