| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 |
| 8 #include <algorithm> | 9 #include <algorithm> |
| 9 #include <iterator> | 10 #include <iterator> |
| 10 #include <set> | 11 #include <set> |
| 11 #include <utility> | 12 #include <utility> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/callback.h" | 15 #include "base/callback.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" |
| 16 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 17 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 19 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
| 18 #include "content/browser/renderer_host/render_process_host_impl.h" | 20 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 19 #include "content/browser/shared_worker/shared_worker_host.h" | 21 #include "content/browser/shared_worker/shared_worker_host.h" |
| 20 #include "content/browser/shared_worker/shared_worker_instance.h" | 22 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 21 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 23 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 22 #include "content/browser/shared_worker/worker_document_set.h" | 24 #include "content/browser/shared_worker/worker_document_set.h" |
| 23 #include "content/common/view_messages.h" | 25 #include "content/common/view_messages.h" |
| 24 #include "content/common/worker_messages.h" | 26 #include "content/common/worker_messages.h" |
| 25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 SharedWorkerMessageFilter* const filter; | 124 SharedWorkerMessageFilter* const filter; |
| 123 const int route_id; | 125 const int route_id; |
| 124 const unsigned long long document_id; | 126 const unsigned long long document_id; |
| 125 const int render_process_id; | 127 const int render_process_id; |
| 126 const int render_frame_route_id; | 128 const int render_frame_route_id; |
| 127 }; | 129 }; |
| 128 | 130 |
| 129 typedef ScopedVector<SharedWorkerPendingRequest> SharedWorkerPendingRequests; | 131 typedef ScopedVector<SharedWorkerPendingRequest> SharedWorkerPendingRequests; |
| 130 | 132 |
| 131 explicit SharedWorkerPendingInstance( | 133 explicit SharedWorkerPendingInstance( |
| 132 scoped_ptr<SharedWorkerInstance> instance) | 134 std::unique_ptr<SharedWorkerInstance> instance) |
| 133 : instance_(std::move(instance)) {} | 135 : instance_(std::move(instance)) {} |
| 134 ~SharedWorkerPendingInstance() {} | 136 ~SharedWorkerPendingInstance() {} |
| 135 SharedWorkerInstance* instance() { return instance_.get(); } | 137 SharedWorkerInstance* instance() { return instance_.get(); } |
| 136 SharedWorkerInstance* release_instance() { return instance_.release(); } | 138 SharedWorkerInstance* release_instance() { return instance_.release(); } |
| 137 SharedWorkerPendingRequests* requests() { return &requests_; } | 139 SharedWorkerPendingRequests* requests() { return &requests_; } |
| 138 SharedWorkerMessageFilter* FindFilter(int process_id) { | 140 SharedWorkerMessageFilter* FindFilter(int process_id) { |
| 139 for (size_t i = 0; i < requests_.size(); ++i) { | 141 for (size_t i = 0; i < requests_.size(); ++i) { |
| 140 if (requests_[i]->render_process_id == process_id) | 142 if (requests_[i]->render_process_id == process_id) |
| 141 return requests_[i]->filter; | 143 return requests_[i]->filter; |
| 142 } | 144 } |
| 143 return NULL; | 145 return NULL; |
| 144 } | 146 } |
| 145 void AddRequest(scoped_ptr<SharedWorkerPendingRequest> request_info) { | 147 void AddRequest(std::unique_ptr<SharedWorkerPendingRequest> request_info) { |
| 146 requests_.push_back(request_info.release()); | 148 requests_.push_back(request_info.release()); |
| 147 } | 149 } |
| 148 void RemoveRequest(int process_id) { | 150 void RemoveRequest(int process_id) { |
| 149 for (SharedWorkerPendingRequests::iterator request_itr = requests_.begin(); | 151 for (SharedWorkerPendingRequests::iterator request_itr = requests_.begin(); |
| 150 request_itr != requests_.end();) { | 152 request_itr != requests_.end();) { |
| 151 if ((*request_itr)->render_process_id == process_id) | 153 if ((*request_itr)->render_process_id == process_id) |
| 152 request_itr = requests_.erase(request_itr); | 154 request_itr = requests_.erase(request_itr); |
| 153 else | 155 else |
| 154 ++request_itr; | 156 ++request_itr; |
| 155 } | 157 } |
| 156 } | 158 } |
| 157 void RegisterToSharedWorkerHost(SharedWorkerHost* host) { | 159 void RegisterToSharedWorkerHost(SharedWorkerHost* host) { |
| 158 for (size_t i = 0; i < requests_.size(); ++i) { | 160 for (size_t i = 0; i < requests_.size(); ++i) { |
| 159 SharedWorkerPendingRequest* request = requests_[i]; | 161 SharedWorkerPendingRequest* request = requests_[i]; |
| 160 host->AddFilter(request->filter, request->route_id); | 162 host->AddFilter(request->filter, request->route_id); |
| 161 host->worker_document_set()->Add(request->filter, | 163 host->worker_document_set()->Add(request->filter, |
| 162 request->document_id, | 164 request->document_id, |
| 163 request->render_process_id, | 165 request->render_process_id, |
| 164 request->render_frame_route_id); | 166 request->render_frame_route_id); |
| 165 } | 167 } |
| 166 } | 168 } |
| 167 void SendWorkerCreatedMessages() { | 169 void SendWorkerCreatedMessages() { |
| 168 for (size_t i = 0; i < requests_.size(); ++i) { | 170 for (size_t i = 0; i < requests_.size(); ++i) { |
| 169 SharedWorkerPendingRequest* request = requests_[i]; | 171 SharedWorkerPendingRequest* request = requests_[i]; |
| 170 request->filter->Send(new ViewMsg_WorkerCreated(request->route_id)); | 172 request->filter->Send(new ViewMsg_WorkerCreated(request->route_id)); |
| 171 } | 173 } |
| 172 } | 174 } |
| 173 | 175 |
| 174 private: | 176 private: |
| 175 scoped_ptr<SharedWorkerInstance> instance_; | 177 std::unique_ptr<SharedWorkerInstance> instance_; |
| 176 SharedWorkerPendingRequests requests_; | 178 SharedWorkerPendingRequests requests_; |
| 177 DISALLOW_COPY_AND_ASSIGN(SharedWorkerPendingInstance); | 179 DISALLOW_COPY_AND_ASSIGN(SharedWorkerPendingInstance); |
| 178 }; | 180 }; |
| 179 | 181 |
| 180 class SharedWorkerServiceImpl::SharedWorkerReserver | 182 class SharedWorkerServiceImpl::SharedWorkerReserver |
| 181 : public base::RefCountedThreadSafe<SharedWorkerReserver> { | 183 : public base::RefCountedThreadSafe<SharedWorkerReserver> { |
| 182 public: | 184 public: |
| 183 SharedWorkerReserver(int pending_instance_id, | 185 SharedWorkerReserver(int pending_instance_id, |
| 184 int worker_process_id, | 186 int worker_process_id, |
| 185 int worker_route_id, | 187 int worker_route_id, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 285 |
| 284 void SharedWorkerServiceImpl::CreateWorker( | 286 void SharedWorkerServiceImpl::CreateWorker( |
| 285 const ViewHostMsg_CreateWorker_Params& params, | 287 const ViewHostMsg_CreateWorker_Params& params, |
| 286 int route_id, | 288 int route_id, |
| 287 SharedWorkerMessageFilter* filter, | 289 SharedWorkerMessageFilter* filter, |
| 288 ResourceContext* resource_context, | 290 ResourceContext* resource_context, |
| 289 const WorkerStoragePartitionId& partition_id, | 291 const WorkerStoragePartitionId& partition_id, |
| 290 blink::WebWorkerCreationError* creation_error) { | 292 blink::WebWorkerCreationError* creation_error) { |
| 291 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 293 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 292 *creation_error = blink::WebWorkerCreationErrorNone; | 294 *creation_error = blink::WebWorkerCreationErrorNone; |
| 293 scoped_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( | 295 std::unique_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( |
| 294 params.url, params.name, params.content_security_policy, | 296 params.url, params.name, params.content_security_policy, |
| 295 params.security_policy_type, params.creation_address_space, | 297 params.security_policy_type, params.creation_address_space, |
| 296 resource_context, partition_id, params.creation_context_type)); | 298 resource_context, partition_id, params.creation_context_type)); |
| 297 scoped_ptr<SharedWorkerPendingInstance::SharedWorkerPendingRequest> request( | 299 std::unique_ptr<SharedWorkerPendingInstance::SharedWorkerPendingRequest> |
| 298 new SharedWorkerPendingInstance::SharedWorkerPendingRequest( | 300 request(new SharedWorkerPendingInstance::SharedWorkerPendingRequest( |
| 299 filter, | 301 filter, route_id, params.document_id, filter->render_process_id(), |
| 300 route_id, | |
| 301 params.document_id, | |
| 302 filter->render_process_id(), | |
| 303 params.render_frame_route_id)); | 302 params.render_frame_route_id)); |
| 304 if (SharedWorkerPendingInstance* pending = FindPendingInstance(*instance)) { | 303 if (SharedWorkerPendingInstance* pending = FindPendingInstance(*instance)) { |
| 305 if (params.url != pending->instance()->url()) { | 304 if (params.url != pending->instance()->url()) { |
| 306 *creation_error = blink::WebWorkerCreationErrorURLMismatch; | 305 *creation_error = blink::WebWorkerCreationErrorURLMismatch; |
| 307 return; | 306 return; |
| 308 } | 307 } |
| 309 if (params.creation_context_type != | 308 if (params.creation_context_type != |
| 310 pending->instance()->creation_context_type()) { | 309 pending->instance()->creation_context_type()) { |
| 311 *creation_error = blink::WebWorkerCreationErrorSecureContextMismatch; | 310 *creation_error = blink::WebWorkerCreationErrorSecureContextMismatch; |
| 312 } | 311 } |
| 313 pending->AddRequest(std::move(request)); | 312 pending->AddRequest(std::move(request)); |
| 314 return; | 313 return; |
| 315 } | 314 } |
| 316 scoped_ptr<SharedWorkerPendingInstance> pending_instance( | 315 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( |
| 317 new SharedWorkerPendingInstance(std::move(instance))); | 316 new SharedWorkerPendingInstance(std::move(instance))); |
| 318 pending_instance->AddRequest(std::move(request)); | 317 pending_instance->AddRequest(std::move(request)); |
| 319 ReserveRenderProcessToCreateWorker(std::move(pending_instance), | 318 ReserveRenderProcessToCreateWorker(std::move(pending_instance), |
| 320 creation_error); | 319 creation_error); |
| 321 } | 320 } |
| 322 | 321 |
| 323 void SharedWorkerServiceImpl::ForwardToWorker( | 322 void SharedWorkerServiceImpl::ForwardToWorker( |
| 324 const IPC::Message& message, | 323 const IPC::Message& message, |
| 325 SharedWorkerMessageFilter* filter) { | 324 SharedWorkerMessageFilter* filter) { |
| 326 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); | 325 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 347 SharedWorkerMessageFilter* filter) { | 346 SharedWorkerMessageFilter* filter) { |
| 348 ScopedWorkerDependencyChecker checker(this); | 347 ScopedWorkerDependencyChecker checker(this); |
| 349 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) | 348 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
| 350 host->WorkerContextClosed(); | 349 host->WorkerContextClosed(); |
| 351 } | 350 } |
| 352 | 351 |
| 353 void SharedWorkerServiceImpl::WorkerContextDestroyed( | 352 void SharedWorkerServiceImpl::WorkerContextDestroyed( |
| 354 int worker_route_id, | 353 int worker_route_id, |
| 355 SharedWorkerMessageFilter* filter) { | 354 SharedWorkerMessageFilter* filter) { |
| 356 ScopedWorkerDependencyChecker checker(this); | 355 ScopedWorkerDependencyChecker checker(this); |
| 357 scoped_ptr<SharedWorkerHost> host = | 356 std::unique_ptr<SharedWorkerHost> host = worker_hosts_.take_and_erase( |
| 358 worker_hosts_.take_and_erase(std::make_pair(filter->render_process_id(), | 357 std::make_pair(filter->render_process_id(), worker_route_id)); |
| 359 worker_route_id)); | |
| 360 if (!host) | 358 if (!host) |
| 361 return; | 359 return; |
| 362 host->WorkerContextDestroyed(); | 360 host->WorkerContextDestroyed(); |
| 363 } | 361 } |
| 364 | 362 |
| 365 void SharedWorkerServiceImpl::WorkerReadyForInspection( | 363 void SharedWorkerServiceImpl::WorkerReadyForInspection( |
| 366 int worker_route_id, | 364 int worker_route_id, |
| 367 SharedWorkerMessageFilter* filter) { | 365 SharedWorkerMessageFilter* filter) { |
| 368 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) | 366 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
| 369 host->WorkerReadyForInspection(); | 367 host->WorkerReadyForInspection(); |
| 370 } | 368 } |
| 371 | 369 |
| 372 void SharedWorkerServiceImpl::WorkerScriptLoaded( | 370 void SharedWorkerServiceImpl::WorkerScriptLoaded( |
| 373 int worker_route_id, | 371 int worker_route_id, |
| 374 SharedWorkerMessageFilter* filter) { | 372 SharedWorkerMessageFilter* filter) { |
| 375 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) | 373 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
| 376 host->WorkerScriptLoaded(); | 374 host->WorkerScriptLoaded(); |
| 377 } | 375 } |
| 378 | 376 |
| 379 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( | 377 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
| 380 int worker_route_id, | 378 int worker_route_id, |
| 381 SharedWorkerMessageFilter* filter) { | 379 SharedWorkerMessageFilter* filter) { |
| 382 ScopedWorkerDependencyChecker checker(this); | 380 ScopedWorkerDependencyChecker checker(this); |
| 383 scoped_ptr<SharedWorkerHost> host = | 381 std::unique_ptr<SharedWorkerHost> host = worker_hosts_.take_and_erase( |
| 384 worker_hosts_.take_and_erase(std::make_pair(filter->render_process_id(), | 382 std::make_pair(filter->render_process_id(), worker_route_id)); |
| 385 worker_route_id)); | |
| 386 if (!host) | 383 if (!host) |
| 387 return; | 384 return; |
| 388 host->WorkerScriptLoadFailed(); | 385 host->WorkerScriptLoadFailed(); |
| 389 } | 386 } |
| 390 | 387 |
| 391 void SharedWorkerServiceImpl::WorkerConnected( | 388 void SharedWorkerServiceImpl::WorkerConnected( |
| 392 int message_port_id, | 389 int message_port_id, |
| 393 int worker_route_id, | 390 int worker_route_id, |
| 394 SharedWorkerMessageFilter* filter) { | 391 SharedWorkerMessageFilter* filter) { |
| 395 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) | 392 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
| 396 host->WorkerConnected(message_port_id); | 393 host->WorkerConnected(message_port_id); |
| 397 } | 394 } |
| 398 | 395 |
| 399 void SharedWorkerServiceImpl::AllowFileSystem( | 396 void SharedWorkerServiceImpl::AllowFileSystem( |
| 400 int worker_route_id, | 397 int worker_route_id, |
| 401 const GURL& url, | 398 const GURL& url, |
| 402 IPC::Message* reply_msg, | 399 IPC::Message* reply_msg, |
| 403 SharedWorkerMessageFilter* filter) { | 400 SharedWorkerMessageFilter* filter) { |
| 404 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { | 401 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
| 405 host->AllowFileSystem(url, make_scoped_ptr(reply_msg)); | 402 host->AllowFileSystem(url, base::WrapUnique(reply_msg)); |
| 406 } else { | 403 } else { |
| 407 filter->Send(reply_msg); | 404 filter->Send(reply_msg); |
| 408 return; | 405 return; |
| 409 } | 406 } |
| 410 } | 407 } |
| 411 | 408 |
| 412 void SharedWorkerServiceImpl::AllowIndexedDB( | 409 void SharedWorkerServiceImpl::AllowIndexedDB( |
| 413 int worker_route_id, | 410 int worker_route_id, |
| 414 const GURL& url, | 411 const GURL& url, |
| 415 const base::string16& name, | 412 const base::string16& name, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 426 ScopedWorkerDependencyChecker checker(this); | 423 ScopedWorkerDependencyChecker checker(this); |
| 427 std::vector<ProcessRouteIdPair> remove_list; | 424 std::vector<ProcessRouteIdPair> remove_list; |
| 428 for (WorkerHostMap::iterator iter = worker_hosts_.begin(); | 425 for (WorkerHostMap::iterator iter = worker_hosts_.begin(); |
| 429 iter != worker_hosts_.end(); | 426 iter != worker_hosts_.end(); |
| 430 ++iter) { | 427 ++iter) { |
| 431 iter->second->FilterShutdown(filter); | 428 iter->second->FilterShutdown(filter); |
| 432 if (iter->first.first == filter->render_process_id()) | 429 if (iter->first.first == filter->render_process_id()) |
| 433 remove_list.push_back(iter->first); | 430 remove_list.push_back(iter->first); |
| 434 } | 431 } |
| 435 for (size_t i = 0; i < remove_list.size(); ++i) { | 432 for (size_t i = 0; i < remove_list.size(); ++i) { |
| 436 scoped_ptr<SharedWorkerHost> host = | 433 std::unique_ptr<SharedWorkerHost> host = |
| 437 worker_hosts_.take_and_erase(remove_list[i]); | 434 worker_hosts_.take_and_erase(remove_list[i]); |
| 438 } | 435 } |
| 439 | 436 |
| 440 std::vector<int> remove_pending_instance_list; | 437 std::vector<int> remove_pending_instance_list; |
| 441 for (PendingInstanceMap::iterator iter = pending_instances_.begin(); | 438 for (PendingInstanceMap::iterator iter = pending_instances_.begin(); |
| 442 iter != pending_instances_.end(); ++iter) { | 439 iter != pending_instances_.end(); ++iter) { |
| 443 iter->second->RemoveRequest(filter->render_process_id()); | 440 iter->second->RemoveRequest(filter->render_process_id()); |
| 444 if (!iter->second->requests()->size()) | 441 if (!iter->second->requests()->size()) |
| 445 remove_pending_instance_list.push_back(iter->first); | 442 remove_pending_instance_list.push_back(iter->first); |
| 446 } | 443 } |
| 447 for (size_t i = 0; i < remove_pending_instance_list.size(); ++i) | 444 for (size_t i = 0; i < remove_pending_instance_list.size(); ++i) |
| 448 pending_instances_.take_and_erase(remove_pending_instance_list[i]); | 445 pending_instances_.take_and_erase(remove_pending_instance_list[i]); |
| 449 } | 446 } |
| 450 | 447 |
| 451 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id, | 448 void SharedWorkerServiceImpl::NotifyWorkerDestroyed(int worker_process_id, |
| 452 int worker_route_id) { | 449 int worker_route_id) { |
| 453 FOR_EACH_OBSERVER(WorkerServiceObserver, | 450 FOR_EACH_OBSERVER(WorkerServiceObserver, |
| 454 observers_, | 451 observers_, |
| 455 WorkerDestroyed(worker_process_id, worker_route_id)); | 452 WorkerDestroyed(worker_process_id, worker_route_id)); |
| 456 } | 453 } |
| 457 | 454 |
| 458 void SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker( | 455 void SharedWorkerServiceImpl::ReserveRenderProcessToCreateWorker( |
| 459 scoped_ptr<SharedWorkerPendingInstance> pending_instance, | 456 std::unique_ptr<SharedWorkerPendingInstance> pending_instance, |
| 460 blink::WebWorkerCreationError* creation_error) { | 457 blink::WebWorkerCreationError* creation_error) { |
| 461 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 458 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 462 DCHECK(!FindPendingInstance(*pending_instance->instance())); | 459 DCHECK(!FindPendingInstance(*pending_instance->instance())); |
| 463 if (creation_error) | 460 if (creation_error) |
| 464 *creation_error = blink::WebWorkerCreationErrorNone; | 461 *creation_error = blink::WebWorkerCreationErrorNone; |
| 465 if (!pending_instance->requests()->size()) | 462 if (!pending_instance->requests()->size()) |
| 466 return; | 463 return; |
| 467 int worker_process_id = -1; | 464 int worker_process_id = -1; |
| 468 int worker_route_id = MSG_ROUTING_NONE; | 465 int worker_route_id = MSG_ROUTING_NONE; |
| 469 bool is_new_worker = true; | 466 bool is_new_worker = true; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 int worker_process_id, | 520 int worker_process_id, |
| 524 int worker_route_id, | 521 int worker_route_id, |
| 525 bool is_new_worker, | 522 bool is_new_worker, |
| 526 bool pause_on_start) { | 523 bool pause_on_start) { |
| 527 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 524 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 528 // To offset the TryIncrementWorkerRefCount called for the reservation, | 525 // To offset the TryIncrementWorkerRefCount called for the reservation, |
| 529 // calls DecrementWorkerRefCount after CheckWorkerDependency in | 526 // calls DecrementWorkerRefCount after CheckWorkerDependency in |
| 530 // ScopeWorkerDependencyChecker's destructor. | 527 // ScopeWorkerDependencyChecker's destructor. |
| 531 ScopedWorkerDependencyChecker checker( | 528 ScopedWorkerDependencyChecker checker( |
| 532 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); | 529 this, base::Bind(&DecrementWorkerRefCount, worker_process_id)); |
| 533 scoped_ptr<SharedWorkerPendingInstance> pending_instance = | 530 std::unique_ptr<SharedWorkerPendingInstance> pending_instance = |
| 534 pending_instances_.take_and_erase(pending_instance_id); | 531 pending_instances_.take_and_erase(pending_instance_id); |
| 535 if (!pending_instance) | 532 if (!pending_instance) |
| 536 return; | 533 return; |
| 537 if (!is_new_worker) { | 534 if (!is_new_worker) { |
| 538 SharedWorkerHost* existing_host = | 535 SharedWorkerHost* existing_host = |
| 539 worker_hosts_.get(std::make_pair(worker_process_id, worker_route_id)); | 536 worker_hosts_.get(std::make_pair(worker_process_id, worker_route_id)); |
| 540 if (!existing_host) { | 537 if (!existing_host) { |
| 541 // Retry reserving a renderer process if the existed Shared Worker was | 538 // Retry reserving a renderer process if the existed Shared Worker was |
| 542 // destroyed on IO thread while reserving the renderer process on UI | 539 // destroyed on IO thread while reserving the renderer process on UI |
| 543 // thread. | 540 // thread. |
| 544 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); | 541 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); |
| 545 return; | 542 return; |
| 546 } | 543 } |
| 547 pending_instance->RegisterToSharedWorkerHost(existing_host); | 544 pending_instance->RegisterToSharedWorkerHost(existing_host); |
| 548 pending_instance->SendWorkerCreatedMessages(); | 545 pending_instance->SendWorkerCreatedMessages(); |
| 549 return; | 546 return; |
| 550 } | 547 } |
| 551 SharedWorkerMessageFilter* filter = | 548 SharedWorkerMessageFilter* filter = |
| 552 pending_instance->FindFilter(worker_process_id); | 549 pending_instance->FindFilter(worker_process_id); |
| 553 if (!filter) { | 550 if (!filter) { |
| 554 pending_instance->RemoveRequest(worker_process_id); | 551 pending_instance->RemoveRequest(worker_process_id); |
| 555 // Retry reserving a renderer process if the requested renderer process was | 552 // Retry reserving a renderer process if the requested renderer process was |
| 556 // destroyed on IO thread while reserving the renderer process on UI thread. | 553 // destroyed on IO thread while reserving the renderer process on UI thread. |
| 557 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); | 554 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); |
| 558 return; | 555 return; |
| 559 } | 556 } |
| 560 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost( | 557 std::unique_ptr<SharedWorkerHost> host(new SharedWorkerHost( |
| 561 pending_instance->release_instance(), filter, worker_route_id)); | 558 pending_instance->release_instance(), filter, worker_route_id)); |
| 562 pending_instance->RegisterToSharedWorkerHost(host.get()); | 559 pending_instance->RegisterToSharedWorkerHost(host.get()); |
| 563 const GURL url = host->instance()->url(); | 560 const GURL url = host->instance()->url(); |
| 564 const base::string16 name = host->instance()->name(); | 561 const base::string16 name = host->instance()->name(); |
| 565 host->Start(pause_on_start); | 562 host->Start(pause_on_start); |
| 566 worker_hosts_.set(std::make_pair(worker_process_id, worker_route_id), | 563 worker_hosts_.set(std::make_pair(worker_process_id, worker_route_id), |
| 567 std::move(host)); | 564 std::move(host)); |
| 568 FOR_EACH_OBSERVER( | 565 FOR_EACH_OBSERVER( |
| 569 WorkerServiceObserver, | 566 WorkerServiceObserver, |
| 570 observers_, | 567 observers_, |
| 571 WorkerCreated(url, name, worker_process_id, worker_route_id)); | 568 WorkerCreated(url, name, worker_process_id, worker_route_id)); |
| 572 } | 569 } |
| 573 | 570 |
| 574 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback( | 571 void SharedWorkerServiceImpl::RenderProcessReserveFailedCallback( |
| 575 int pending_instance_id, | 572 int pending_instance_id, |
| 576 int worker_process_id, | 573 int worker_process_id, |
| 577 int worker_route_id, | 574 int worker_route_id, |
| 578 bool is_new_worker) { | 575 bool is_new_worker) { |
| 579 worker_hosts_.take_and_erase( | 576 worker_hosts_.take_and_erase( |
| 580 std::make_pair(worker_process_id, worker_route_id)); | 577 std::make_pair(worker_process_id, worker_route_id)); |
| 581 scoped_ptr<SharedWorkerPendingInstance> pending_instance = | 578 std::unique_ptr<SharedWorkerPendingInstance> pending_instance = |
| 582 pending_instances_.take_and_erase(pending_instance_id); | 579 pending_instances_.take_and_erase(pending_instance_id); |
| 583 if (!pending_instance) | 580 if (!pending_instance) |
| 584 return; | 581 return; |
| 585 pending_instance->RemoveRequest(worker_process_id); | 582 pending_instance->RemoveRequest(worker_process_id); |
| 586 // Retry reserving a renderer process. | 583 // Retry reserving a renderer process. |
| 587 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); | 584 ReserveRenderProcessToCreateWorker(std::move(pending_instance), NULL); |
| 588 } | 585 } |
| 589 | 586 |
| 590 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | 587 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( |
| 591 SharedWorkerMessageFilter* filter, | 588 SharedWorkerMessageFilter* filter, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 UpdateWorkerDependencyFunc new_func) { | 649 UpdateWorkerDependencyFunc new_func) { |
| 653 update_worker_dependency_ = new_func; | 650 update_worker_dependency_ = new_func; |
| 654 } | 651 } |
| 655 | 652 |
| 656 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( | 653 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( |
| 657 bool (*new_func)(int)) { | 654 bool (*new_func)(int)) { |
| 658 s_try_increment_worker_ref_count_ = new_func; | 655 s_try_increment_worker_ref_count_ = new_func; |
| 659 } | 656 } |
| 660 | 657 |
| 661 } // namespace content | 658 } // namespace content |
| OLD | NEW |