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

Side by Side Diff: content/browser/service_worker/embedded_worker_registry.cc

Issue 2228403003: content: Use stl utilities from the base namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/service_worker/embedded_worker_registry.h" 5 #include "content/browser/service_worker/embedded_worker_registry.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/browser/renderer_host/render_widget_helper.h" 10 #include "content/browser/renderer_host/render_widget_helper.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 worker->OnScriptEvaluated(success); 127 worker->OnScriptEvaluated(success);
128 } 128 }
129 129
130 void EmbeddedWorkerRegistry::OnWorkerStarted( 130 void EmbeddedWorkerRegistry::OnWorkerStarted(
131 int process_id, int embedded_worker_id) { 131 int process_id, int embedded_worker_id) {
132 EmbeddedWorkerInstance* worker = 132 EmbeddedWorkerInstance* worker =
133 GetWorkerForMessage(process_id, embedded_worker_id); 133 GetWorkerForMessage(process_id, embedded_worker_id);
134 if (!worker) 134 if (!worker)
135 return; 135 return;
136 136
137 if (!ContainsKey(worker_process_map_, process_id) || 137 if (!base::ContainsKey(worker_process_map_, process_id) ||
138 !ContainsKey(worker_process_map_[process_id], embedded_worker_id)) { 138 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id)) {
139 return; 139 return;
140 } 140 }
141 141
142 worker->OnStarted(); 142 worker->OnStarted();
143 } 143 }
144 144
145 void EmbeddedWorkerRegistry::OnWorkerStopped( 145 void EmbeddedWorkerRegistry::OnWorkerStopped(
146 int process_id, int embedded_worker_id) { 146 int process_id, int embedded_worker_id) {
147 EmbeddedWorkerInstance* worker = 147 EmbeddedWorkerInstance* worker =
148 GetWorkerForMessage(process_id, embedded_worker_id); 148 GetWorkerForMessage(process_id, embedded_worker_id);
(...skipping 30 matching lines...) Expand all
179 line_number, source_url); 179 line_number, source_url);
180 } 180 }
181 181
182 void EmbeddedWorkerRegistry::AddChildProcessSender( 182 void EmbeddedWorkerRegistry::AddChildProcessSender(
183 int process_id, 183 int process_id,
184 IPC::Sender* sender, 184 IPC::Sender* sender,
185 MessagePortMessageFilter* message_port_message_filter) { 185 MessagePortMessageFilter* message_port_message_filter) {
186 process_sender_map_[process_id] = sender; 186 process_sender_map_[process_id] = sender;
187 process_message_port_message_filter_map_[process_id] = 187 process_message_port_message_filter_map_[process_id] =
188 message_port_message_filter; 188 message_port_message_filter;
189 DCHECK(!ContainsKey(worker_process_map_, process_id)); 189 DCHECK(!base::ContainsKey(worker_process_map_, process_id));
190 } 190 }
191 191
192 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) { 192 void EmbeddedWorkerRegistry::RemoveChildProcessSender(int process_id) {
193 process_sender_map_.erase(process_id); 193 process_sender_map_.erase(process_id);
194 process_message_port_message_filter_map_.erase(process_id); 194 process_message_port_message_filter_map_.erase(process_id);
195 std::map<int, std::set<int> >::iterator found = 195 std::map<int, std::set<int> >::iterator found =
196 worker_process_map_.find(process_id); 196 worker_process_map_.find(process_id);
197 if (found != worker_process_map_.end()) { 197 if (found != worker_process_map_.end()) {
198 const std::set<int>& worker_set = worker_process_map_[process_id]; 198 const std::set<int>& worker_set = worker_process_map_[process_id];
199 for (std::set<int>::const_iterator it = worker_set.begin(); 199 for (std::set<int>::const_iterator it = worker_set.begin();
200 it != worker_set.end(); 200 it != worker_set.end();
201 ++it) { 201 ++it) {
202 int embedded_worker_id = *it; 202 int embedded_worker_id = *it;
203 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 203 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id));
204 // Somehow the worker thread has lost contact with the browser process. 204 // Somehow the worker thread has lost contact with the browser process.
205 // The renderer may have been killed. Set the worker's status to STOPPED 205 // The renderer may have been killed. Set the worker's status to STOPPED
206 // so a new thread can be created for this version. Use OnDetached rather 206 // so a new thread can be created for this version. Use OnDetached rather
207 // than OnStopped so UMA doesn't record it as a normal stoppage. 207 // than OnStopped so UMA doesn't record it as a normal stoppage.
208 worker_map_[embedded_worker_id]->OnDetached(); 208 worker_map_[embedded_worker_id]->OnDetached();
209 } 209 }
210 worker_process_map_.erase(found); 210 worker_process_map_.erase(found);
211 } 211 }
212 } 212 }
213 213
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker( 247 ServiceWorkerStatusCode EmbeddedWorkerRegistry::SendStartWorker(
248 std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 248 std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
249 int process_id) { 249 int process_id) {
250 if (!context_) 250 if (!context_)
251 return SERVICE_WORKER_ERROR_ABORT; 251 return SERVICE_WORKER_ERROR_ABORT;
252 252
253 // The ServiceWorkerDispatcherHost is supposed to be created when the process 253 // The ServiceWorkerDispatcherHost is supposed to be created when the process
254 // is created, and keep an entry in process_sender_map_ for its whole 254 // is created, and keep an entry in process_sender_map_ for its whole
255 // lifetime. 255 // lifetime.
256 DCHECK(ContainsKey(process_sender_map_, process_id)); 256 DCHECK(base::ContainsKey(process_sender_map_, process_id));
257 257
258 int embedded_worker_id = params->embedded_worker_id; 258 int embedded_worker_id = params->embedded_worker_id;
259 DCHECK(GetWorker(embedded_worker_id)); 259 DCHECK(GetWorker(embedded_worker_id));
260 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id); 260 DCHECK_EQ(GetWorker(embedded_worker_id)->process_id(), process_id);
261 DCHECK(!ContainsKey(worker_process_map_, process_id) || 261 DCHECK(
262 !ContainsKey(worker_process_map_[process_id], embedded_worker_id)); 262 !base::ContainsKey(worker_process_map_, process_id) ||
263 !base::ContainsKey(worker_process_map_[process_id], embedded_worker_id));
263 264
264 ServiceWorkerStatusCode status = 265 ServiceWorkerStatusCode status =
265 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params)); 266 Send(process_id, new EmbeddedWorkerMsg_StartWorker(*params));
266 if (status == SERVICE_WORKER_OK) 267 if (status == SERVICE_WORKER_OK)
267 worker_process_map_[process_id].insert(embedded_worker_id); 268 worker_process_map_[process_id].insert(embedded_worker_id);
268 return status; 269 return status;
269 } 270 }
270 271
271 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send( 272 ServiceWorkerStatusCode EmbeddedWorkerRegistry::Send(
272 int process_id, IPC::Message* message_ptr) { 273 int process_id, IPC::Message* message_ptr) {
273 std::unique_ptr<IPC::Message> message(message_ptr); 274 std::unique_ptr<IPC::Message> message(message_ptr);
274 if (!context_) 275 if (!context_)
275 return SERVICE_WORKER_ERROR_ABORT; 276 return SERVICE_WORKER_ERROR_ABORT;
276 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id); 277 ProcessToSenderMap::iterator found = process_sender_map_.find(process_id);
277 if (found == process_sender_map_.end()) 278 if (found == process_sender_map_.end())
278 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND; 279 return SERVICE_WORKER_ERROR_PROCESS_NOT_FOUND;
279 if (!found->second->Send(message.release())) 280 if (!found->second->Send(message.release()))
280 return SERVICE_WORKER_ERROR_IPC_FAILED; 281 return SERVICE_WORKER_ERROR_IPC_FAILED;
281 return SERVICE_WORKER_OK; 282 return SERVICE_WORKER_OK;
282 } 283 }
283 284
284 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 285 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
285 int embedded_worker_id) { 286 int embedded_worker_id) {
286 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 287 DCHECK(base::ContainsKey(worker_map_, embedded_worker_id));
287 worker_map_.erase(embedded_worker_id); 288 worker_map_.erase(embedded_worker_id);
288 if (!ContainsKey(worker_process_map_, process_id)) 289 if (!base::ContainsKey(worker_process_map_, process_id))
289 return; 290 return;
290 worker_process_map_[process_id].erase(embedded_worker_id); 291 worker_process_map_[process_id].erase(embedded_worker_id);
291 if (worker_process_map_[process_id].empty()) 292 if (worker_process_map_[process_id].empty())
292 worker_process_map_.erase(process_id); 293 worker_process_map_.erase(process_id);
293 } 294 }
294 295
295 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorkerForMessage( 296 EmbeddedWorkerInstance* EmbeddedWorkerRegistry::GetWorkerForMessage(
296 int process_id, 297 int process_id,
297 int embedded_worker_id) { 298 int embedded_worker_id) {
298 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id); 299 EmbeddedWorkerInstance* worker = GetWorker(embedded_worker_id);
299 if (!worker || worker->process_id() != process_id) { 300 if (!worker || worker->process_id() != process_id) {
300 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false); 301 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", false);
301 return nullptr; 302 return nullptr;
302 } 303 }
303 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true); 304 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.WorkerForMessageFound", true);
304 return worker; 305 return worker;
305 } 306 }
306 307
307 } // namespace content 308 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698