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

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

Issue 2427443002: Replace remaining shell references with 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 service_manager::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 service_manager::ServiceContext* new_connection = 84 service_manager::ServiceContext* new_connection =
85 new service_manager::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 service_manager_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(service_manager::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 = service_manager_connections_.begin();
96 ++it) { 96 it != service_manager_connections_.end(); ++it) {
97 if (it->get() == connection) { 97 if (it->get() == connection) {
98 shell_connections_.erase(it); 98 service_manager_connections_.erase(it);
99 break; 99 break;
100 } 100 }
101 } 101 }
102 } 102 }
103 103
104 void Quit() { 104 void Quit() {
105 DCHECK(task_runner_->BelongsToCurrentThread()); 105 DCHECK(task_runner_->BelongsToCurrentThread());
106 106
107 shell_connections_.clear(); 107 service_manager_connections_.clear();
108 service_.reset(); 108 service_.reset();
109 if (quit_task_runner_->BelongsToCurrentThread()) { 109 if (quit_task_runner_->BelongsToCurrentThread()) {
110 QuitOnRunnerThread(); 110 QuitOnRunnerThread();
111 } else { 111 } else {
112 quit_task_runner_->PostTask( 112 quit_task_runner_->PostTask(
113 FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this)); 113 FROM_HERE, base::Bind(&Instance::QuitOnRunnerThread, this));
114 } 114 }
115 } 115 }
116 116
117 void QuitOnRunnerThread() { 117 void QuitOnRunnerThread() {
(...skipping 17 matching lines...) Expand all
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<service_manager::Service> service_; 143 std::unique_ptr<service_manager::Service> service_;
144 std::vector<std::unique_ptr<service_manager::ServiceContext>> 144 std::vector<std::unique_ptr<service_manager::ServiceContext>>
145 shell_connections_; 145 service_manager_connections_;
146 146
147 DISALLOW_COPY_AND_ASSIGN(Instance); 147 DISALLOW_COPY_AND_ASSIGN(Instance);
148 }; 148 };
149 149
150 EmbeddedServiceRunner::EmbeddedServiceRunner(const base::StringPiece& name, 150 EmbeddedServiceRunner::EmbeddedServiceRunner(const base::StringPiece& name,
151 const ServiceInfo& info) 151 const ServiceInfo& info)
152 : weak_factory_(this) { 152 : weak_factory_(this) {
153 instance_ = new Instance(name, info, 153 instance_ = new Instance(name, info,
154 base::Bind(&EmbeddedServiceRunner::OnQuit, 154 base::Bind(&EmbeddedServiceRunner::OnQuit,
155 weak_factory_.GetWeakPtr())); 155 weak_factory_.GetWeakPtr()));
(...skipping 12 matching lines...) Expand all
168 const base::Closure& quit_closure) { 168 const base::Closure& quit_closure) {
169 quit_closure_ = quit_closure; 169 quit_closure_ = quit_closure;
170 } 170 }
171 171
172 void EmbeddedServiceRunner::OnQuit() { 172 void EmbeddedServiceRunner::OnQuit() {
173 if (!quit_closure_.is_null()) 173 if (!quit_closure_.is_null())
174 quit_closure_.Run(); 174 quit_closure_.Run();
175 } 175 }
176 176
177 } // namespace content 177 } // namespace content
OLDNEW
« no previous file with comments | « content/common/service_manager/child_connection.h ('k') | content/common/service_manager/service_manager_connection_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698