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

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

Issue 2420253002: Rename shell namespace to service_manager (Closed)
Patch Set: . Created 4 years, 2 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
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 <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 15 matching lines...) Expand all
26 : name_(name.as_string()), 26 : name_(name.as_string()),
27 factory_callback_(info.factory), 27 factory_callback_(info.factory),
28 use_own_thread_(!info.task_runner && info.use_own_thread), 28 use_own_thread_(!info.task_runner && info.use_own_thread),
29 quit_closure_(quit_closure), 29 quit_closure_(quit_closure),
30 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()), 30 quit_task_runner_(base::ThreadTaskRunnerHandle::Get()),
31 task_runner_(info.task_runner) { 31 task_runner_(info.task_runner) {
32 if (!use_own_thread_ && !task_runner_) 32 if (!use_own_thread_ && !task_runner_)
33 task_runner_ = base::ThreadTaskRunnerHandle::Get(); 33 task_runner_ = base::ThreadTaskRunnerHandle::Get();
34 } 34 }
35 35
36 void BindServiceRequest(shell::mojom::ServiceRequest request) { 36 void BindServiceRequest(service_manager::mojom::ServiceRequest request) {
37 DCHECK(runner_thread_checker_.CalledOnValidThread()); 37 DCHECK(runner_thread_checker_.CalledOnValidThread());
38 38
39 if (use_own_thread_ && !thread_) { 39 if (use_own_thread_ && !thread_) {
40 // Start a new thread if necessary. 40 // Start a new thread if necessary.
41 thread_.reset(new base::Thread(name_)); 41 thread_.reset(new base::Thread(name_));
42 thread_->Start(); 42 thread_->Start();
43 task_runner_ = thread_->task_runner(); 43 task_runner_ = thread_->task_runner();
44 } 44 }
45 45
46 DCHECK(task_runner_); 46 DCHECK(task_runner_);
(...skipping 19 matching lines...) Expand all
66 private: 66 private:
67 friend class base::RefCountedThreadSafe<Instance>; 67 friend class base::RefCountedThreadSafe<Instance>;
68 68
69 ~Instance() { 69 ~Instance() {
70 // If this instance had its own thread, it MUST be explicitly destroyed by 70 // If this instance had its own thread, it MUST be explicitly destroyed by
71 // QuitOnRunnerThread() by the time this destructor is run. 71 // QuitOnRunnerThread() by the time this destructor is run.
72 DCHECK(!thread_); 72 DCHECK(!thread_);
73 } 73 }
74 74
75 void BindServiceRequestOnApplicationThread( 75 void BindServiceRequestOnApplicationThread(
76 shell::mojom::ServiceRequest request) { 76 service_manager::mojom::ServiceRequest request) {
77 DCHECK(task_runner_->BelongsToCurrentThread()); 77 DCHECK(task_runner_->BelongsToCurrentThread());
78 78
79 if (!service_) { 79 if (!service_) {
80 service_ = factory_callback_.Run( 80 service_ = factory_callback_.Run(
81 base::Bind(&Instance::Quit, base::Unretained(this))); 81 base::Bind(&Instance::Quit, base::Unretained(this)));
82 } 82 }
83 83
84 shell::ServiceContext* new_connection = 84 service_manager::ServiceContext* new_connection =
85 new shell::ServiceContext(service_.get(), std::move(request)); 85 new service_manager::ServiceContext(service_.get(), std::move(request));
86 shell_connections_.push_back(base::WrapUnique(new_connection)); 86 shell_connections_.push_back(base::WrapUnique(new_connection));
87 new_connection->SetConnectionLostClosure( 87 new_connection->SetConnectionLostClosure(
88 base::Bind(&Instance::OnStop, base::Unretained(this), 88 base::Bind(&Instance::OnStop, base::Unretained(this),
89 new_connection)); 89 new_connection));
90 } 90 }
91 91
92 void OnStop(shell::ServiceContext* connection) { 92 void OnStop(service_manager::ServiceContext* connection) {
93 DCHECK(task_runner_->BelongsToCurrentThread()); 93 DCHECK(task_runner_->BelongsToCurrentThread());
94 94
95 for (auto it = shell_connections_.begin(); it != shell_connections_.end(); 95 for (auto it = shell_connections_.begin(); it != shell_connections_.end();
96 ++it) { 96 ++it) {
97 if (it->get() == connection) { 97 if (it->get() == connection) {
98 shell_connections_.erase(it); 98 shell_connections_.erase(it);
99 break; 99 break;
100 } 100 }
101 } 101 }
102 } 102 }
(...skipping 30 matching lines...) Expand all
133 // runner's (i.e. our owner's) thread. 133 // runner's (i.e. our owner's) thread.
134 base::ThreadChecker runner_thread_checker_; 134 base::ThreadChecker runner_thread_checker_;
135 135
136 // These fields must only be accessed from the runner's thread. 136 // These fields must only be accessed from the runner's thread.
137 std::unique_ptr<base::Thread> thread_; 137 std::unique_ptr<base::Thread> thread_;
138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 138 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
139 139
140 // These fields must only be accessed from the application thread, except in 140 // These fields must only be accessed from the application thread, except in
141 // the destructor which may run on either the runner thread or the application 141 // the destructor which may run on either the runner thread or the application
142 // thread. 142 // thread.
143 std::unique_ptr<shell::Service> service_; 143 std::unique_ptr<service_manager::Service> service_;
144 std::vector<std::unique_ptr<shell::ServiceContext>> shell_connections_; 144 std::vector<std::unique_ptr<service_manager::ServiceContext>>
145 shell_connections_;
145 146
146 DISALLOW_COPY_AND_ASSIGN(Instance); 147 DISALLOW_COPY_AND_ASSIGN(Instance);
147 }; 148 };
148 149
149 EmbeddedServiceRunner::EmbeddedServiceRunner(const base::StringPiece& name, 150 EmbeddedServiceRunner::EmbeddedServiceRunner(const base::StringPiece& name,
150 const ServiceInfo& info) 151 const ServiceInfo& info)
151 : weak_factory_(this) { 152 : weak_factory_(this) {
152 instance_ = new Instance(name, info, 153 instance_ = new Instance(name, info,
153 base::Bind(&EmbeddedServiceRunner::OnQuit, 154 base::Bind(&EmbeddedServiceRunner::OnQuit,
154 weak_factory_.GetWeakPtr())); 155 weak_factory_.GetWeakPtr()));
155 } 156 }
156 157
157 EmbeddedServiceRunner::~EmbeddedServiceRunner() { 158 EmbeddedServiceRunner::~EmbeddedServiceRunner() {
158 instance_->ShutDown(); 159 instance_->ShutDown();
159 } 160 }
160 161
161 void EmbeddedServiceRunner::BindServiceRequest( 162 void EmbeddedServiceRunner::BindServiceRequest(
162 shell::mojom::ServiceRequest request) { 163 service_manager::mojom::ServiceRequest request) {
163 instance_->BindServiceRequest(std::move(request)); 164 instance_->BindServiceRequest(std::move(request));
164 } 165 }
165 166
166 void EmbeddedServiceRunner::SetQuitClosure( 167 void EmbeddedServiceRunner::SetQuitClosure(
167 const base::Closure& quit_closure) { 168 const base::Closure& quit_closure) {
168 quit_closure_ = quit_closure; 169 quit_closure_ = quit_closure;
169 } 170 }
170 171
171 void EmbeddedServiceRunner::OnQuit() { 172 void EmbeddedServiceRunner::OnQuit() {
172 if (!quit_closure_.is_null()) 173 if (!quit_closure_.is_null())
173 quit_closure_.Run(); 174 quit_closure_.Run();
174 } 175 }
175 176
176 } // namespace content 177 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698