OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/worker_host/worker_service_impl.h" | 5 #include "content/browser/worker_host/worker_service_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // the queued workers, or a renderer has shut down, in which case it doesn't | 78 // the queued workers, or a renderer has shut down, in which case it doesn't |
79 // affect anything. We call this function in both scenarios because then we | 79 // affect anything. We call this function in both scenarios because then we |
80 // don't have to keep track which filters are from worker processes. | 80 // don't have to keep track which filters are from worker processes. |
81 TryStartingQueuedWorker(); | 81 TryStartingQueuedWorker(); |
82 } | 82 } |
83 | 83 |
84 void WorkerServiceImpl::CreateWorker( | 84 void WorkerServiceImpl::CreateWorker( |
85 const ViewHostMsg_CreateWorker_Params& params, | 85 const ViewHostMsg_CreateWorker_Params& params, |
86 int route_id, | 86 int route_id, |
87 WorkerMessageFilter* filter, | 87 WorkerMessageFilter* filter, |
88 const ResourceContext& resource_context) { | 88 ResourceContext* resource_context) { |
89 // Generate a unique route id for the browser-worker communication that's | 89 // Generate a unique route id for the browser-worker communication that's |
90 // unique among all worker processes. That way when the worker process sends | 90 // unique among all worker processes. That way when the worker process sends |
91 // a wrapped IPC message through us, we know which WorkerProcessHost to give | 91 // a wrapped IPC message through us, we know which WorkerProcessHost to give |
92 // it to. | 92 // it to. |
93 WorkerProcessHost::WorkerInstance instance( | 93 WorkerProcessHost::WorkerInstance instance( |
94 params.url, | 94 params.url, |
95 params.name, | 95 params.name, |
96 next_worker_route_id(), | 96 next_worker_route_id(), |
97 0, | 97 0, |
98 params.script_resource_appcache_id, | 98 params.script_resource_appcache_id, |
99 &resource_context); | 99 resource_context); |
100 instance.AddFilter(filter, route_id); | 100 instance.AddFilter(filter, route_id); |
101 instance.worker_document_set()->Add( | 101 instance.worker_document_set()->Add( |
102 filter, params.document_id, filter->render_process_id(), | 102 filter, params.document_id, filter->render_process_id(), |
103 params.render_view_route_id); | 103 params.render_view_route_id); |
104 | 104 |
105 CreateWorkerFromInstance(instance); | 105 CreateWorkerFromInstance(instance); |
106 } | 106 } |
107 | 107 |
108 void WorkerServiceImpl::LookupSharedWorker( | 108 void WorkerServiceImpl::LookupSharedWorker( |
109 const ViewHostMsg_CreateWorker_Params& params, | 109 const ViewHostMsg_CreateWorker_Params& params, |
110 int route_id, | 110 int route_id, |
111 WorkerMessageFilter* filter, | 111 WorkerMessageFilter* filter, |
112 const ResourceContext* resource_context, | 112 ResourceContext* resource_context, |
113 bool* exists, | 113 bool* exists, |
114 bool* url_mismatch) { | 114 bool* url_mismatch) { |
115 *exists = true; | 115 *exists = true; |
116 WorkerProcessHost::WorkerInstance* instance = FindSharedWorkerInstance( | 116 WorkerProcessHost::WorkerInstance* instance = FindSharedWorkerInstance( |
117 params.url, params.name, resource_context); | 117 params.url, params.name, resource_context); |
118 | 118 |
119 if (!instance) { | 119 if (!instance) { |
120 // If no worker instance currently exists, we need to create a pending | 120 // If no worker instance currently exists, we need to create a pending |
121 // instance - this is to make sure that any subsequent lookups passing a | 121 // instance - this is to make sure that any subsequent lookups passing a |
122 // mismatched URL get the appropriate url_mismatch error at lookup time. | 122 // mismatched URL get the appropriate url_mismatch error at lookup time. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // renderers) but when we do, we'll need to add code to pass in the current | 285 // renderers) but when we do, we'll need to add code to pass in the current |
286 // worker's document set for nested workers. | 286 // worker's document set for nested workers. |
287 if (!worker->Init(first_filter->render_process_id())) { | 287 if (!worker->Init(first_filter->render_process_id())) { |
288 delete worker; | 288 delete worker; |
289 return false; | 289 return false; |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 // TODO(michaeln): As written, test can fail per my earlier comment in | 293 // TODO(michaeln): As written, test can fail per my earlier comment in |
294 // this method, but that's a bug. | 294 // this method, but that's a bug. |
295 // DCHECK(worker->request_context() == instance.request_context()); | 295 // DCHECK(worker->request_context() == instance.GetRequestContext()); |
296 | 296 |
297 worker->CreateWorker(instance); | 297 worker->CreateWorker(instance); |
298 FOR_EACH_OBSERVER( | 298 FOR_EACH_OBSERVER( |
299 WorkerServiceObserver, observers_, | 299 WorkerServiceObserver, observers_, |
300 WorkerCreated(instance.url(), instance.name(), worker->GetData().id, | 300 WorkerCreated(instance.url(), instance.name(), worker->GetData().id, |
301 instance.worker_route_id())); | 301 instance.worker_route_id())); |
302 WorkerDevToolsManager::GetInstance()->WorkerCreated(worker, instance); | 302 WorkerDevToolsManager::GetInstance()->WorkerCreated(worker, instance); |
303 return true; | 303 return true; |
304 } | 304 } |
305 | 305 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 int worker_route_id) { | 499 int worker_route_id) { |
500 WorkerDevToolsManager::GetInstance()->WorkerDestroyed( | 500 WorkerDevToolsManager::GetInstance()->WorkerDestroyed( |
501 process, worker_route_id); | 501 process, worker_route_id); |
502 FOR_EACH_OBSERVER(WorkerServiceObserver, observers_, | 502 FOR_EACH_OBSERVER(WorkerServiceObserver, observers_, |
503 WorkerDestroyed(process->GetData().id, worker_route_id)); | 503 WorkerDestroyed(process->GetData().id, worker_route_id)); |
504 } | 504 } |
505 | 505 |
506 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindSharedWorkerInstance( | 506 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindSharedWorkerInstance( |
507 const GURL& url, | 507 const GURL& url, |
508 const string16& name, | 508 const string16& name, |
509 const ResourceContext* resource_context) { | 509 ResourceContext* resource_context) { |
510 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { | 510 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) { |
511 for (WorkerProcessHost::Instances::iterator instance_iter = | 511 for (WorkerProcessHost::Instances::iterator instance_iter = |
512 iter->mutable_instances().begin(); | 512 iter->mutable_instances().begin(); |
513 instance_iter != iter->mutable_instances().end(); | 513 instance_iter != iter->mutable_instances().end(); |
514 ++instance_iter) { | 514 ++instance_iter) { |
515 if (instance_iter->Matches(url, name, resource_context)) | 515 if (instance_iter->Matches(url, name, resource_context)) |
516 return &(*instance_iter); | 516 return &(*instance_iter); |
517 } | 517 } |
518 } | 518 } |
519 return NULL; | 519 return NULL; |
520 } | 520 } |
521 | 521 |
522 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindPendingInstance( | 522 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::FindPendingInstance( |
523 const GURL& url, | 523 const GURL& url, |
524 const string16& name, | 524 const string16& name, |
525 const ResourceContext* resource_context) { | 525 ResourceContext* resource_context) { |
526 // Walk the pending instances looking for a matching pending worker. | 526 // Walk the pending instances looking for a matching pending worker. |
527 for (WorkerProcessHost::Instances::iterator iter = | 527 for (WorkerProcessHost::Instances::iterator iter = |
528 pending_shared_workers_.begin(); | 528 pending_shared_workers_.begin(); |
529 iter != pending_shared_workers_.end(); | 529 iter != pending_shared_workers_.end(); |
530 ++iter) { | 530 ++iter) { |
531 if (iter->Matches(url, name, resource_context)) { | 531 if (iter->Matches(url, name, resource_context)) { |
532 return &(*iter); | 532 return &(*iter); |
533 } | 533 } |
534 } | 534 } |
535 return NULL; | 535 return NULL; |
536 } | 536 } |
537 | 537 |
538 | 538 |
539 void WorkerServiceImpl::RemovePendingInstances( | 539 void WorkerServiceImpl::RemovePendingInstances( |
540 const GURL& url, | 540 const GURL& url, |
541 const string16& name, | 541 const string16& name, |
542 const ResourceContext* resource_context) { | 542 ResourceContext* resource_context) { |
543 // Walk the pending instances looking for a matching pending worker. | 543 // Walk the pending instances looking for a matching pending worker. |
544 for (WorkerProcessHost::Instances::iterator iter = | 544 for (WorkerProcessHost::Instances::iterator iter = |
545 pending_shared_workers_.begin(); | 545 pending_shared_workers_.begin(); |
546 iter != pending_shared_workers_.end(); ) { | 546 iter != pending_shared_workers_.end(); ) { |
547 if (iter->Matches(url, name, resource_context)) { | 547 if (iter->Matches(url, name, resource_context)) { |
548 iter = pending_shared_workers_.erase(iter); | 548 iter = pending_shared_workers_.erase(iter); |
549 } else { | 549 } else { |
550 ++iter; | 550 ++iter; |
551 } | 551 } |
552 } | 552 } |
553 } | 553 } |
554 | 554 |
555 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::CreatePendingInstance( | 555 WorkerProcessHost::WorkerInstance* WorkerServiceImpl::CreatePendingInstance( |
556 const GURL& url, | 556 const GURL& url, |
557 const string16& name, | 557 const string16& name, |
558 const ResourceContext* resource_context) { | 558 ResourceContext* resource_context) { |
559 // Look for an existing pending shared worker. | 559 // Look for an existing pending shared worker. |
560 WorkerProcessHost::WorkerInstance* instance = | 560 WorkerProcessHost::WorkerInstance* instance = |
561 FindPendingInstance(url, name, resource_context); | 561 FindPendingInstance(url, name, resource_context); |
562 if (instance) | 562 if (instance) |
563 return instance; | 563 return instance; |
564 | 564 |
565 // No existing pending worker - create a new one. | 565 // No existing pending worker - create a new one. |
566 WorkerProcessHost::WorkerInstance pending(url, true, name, resource_context); | 566 WorkerProcessHost::WorkerInstance pending(url, true, name, resource_context); |
567 pending_shared_workers_.push_back(pending); | 567 pending_shared_workers_.push_back(pending); |
568 return &pending_shared_workers_.back(); | 568 return &pending_shared_workers_.back(); |
569 } | 569 } |
570 | 570 |
571 } // namespace content | 571 } // namespace content |
OLD | NEW |