| OLD | NEW |
| 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/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "content/browser/browser_thread_impl.h" | 15 #include "content/browser/browser_thread_impl.h" |
| 16 #include "content/browser/message_port_service.h" | 16 #include "content/browser/message_port_service.h" |
| 17 #include "content/browser/service_worker/embedded_worker_instance.h" | 17 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 18 #include "content/browser/service_worker/embedded_worker_registry.h" | 18 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 19 #include "content/browser/service_worker/embedded_worker_status.h" |
| 19 #include "content/browser/service_worker/embedded_worker_test_helper.h" | 20 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
| 20 #include "content/browser/service_worker/service_worker_context_core.h" | 21 #include "content/browser/service_worker/service_worker_context_core.h" |
| 21 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 22 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 22 #include "content/browser/service_worker/service_worker_handle.h" | 23 #include "content/browser/service_worker/service_worker_handle.h" |
| 23 #include "content/common/service_worker/embedded_worker_messages.h" | 24 #include "content/common/service_worker/embedded_worker_messages.h" |
| 24 #include "content/common/service_worker/service_worker_messages.h" | 25 #include "content/common/service_worker/service_worker_messages.h" |
| 25 #include "content/public/common/content_switches.h" | 26 #include "content/public/common/content_switches.h" |
| 26 #include "content/public/test/mock_resource_context.h" | 27 #include "content/public/test/mock_resource_context.h" |
| 27 #include "content/public/test/test_browser_thread_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
| 28 #include "content/test/test_content_browser_client.h" | 29 #include "content/test/test_content_browser_client.h" |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 bool called = false; | 631 bool called = false; |
| 631 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_ABORT; | 632 ServiceWorkerStatusCode status = SERVICE_WORKER_ERROR_ABORT; |
| 632 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, | 633 version_->StartWorker(ServiceWorkerMetrics::EventType::UNKNOWN, |
| 633 base::Bind(&SaveStatusCallback, &called, &status)); | 634 base::Bind(&SaveStatusCallback, &called, &status)); |
| 634 base::RunLoop().RunUntilIdle(); | 635 base::RunLoop().RunUntilIdle(); |
| 635 | 636 |
| 636 EXPECT_TRUE(called); | 637 EXPECT_TRUE(called); |
| 637 EXPECT_EQ(SERVICE_WORKER_OK, status); | 638 EXPECT_EQ(SERVICE_WORKER_OK, status); |
| 638 | 639 |
| 639 EXPECT_TRUE(context()->GetProviderHost(process_id, provider_id)); | 640 EXPECT_TRUE(context()->GetProviderHost(process_id, provider_id)); |
| 640 EXPECT_EQ(ServiceWorkerVersion::RUNNING, version_->running_status()); | 641 EXPECT_EQ(EmbeddedWorkerStatus::RUNNING, version_->running_status()); |
| 641 | 642 |
| 642 // Simulate the render process crashing. | 643 // Simulate the render process crashing. |
| 643 dispatcher_host_->OnFilterRemoved(); | 644 dispatcher_host_->OnFilterRemoved(); |
| 644 | 645 |
| 645 // The dispatcher host should clean up the state from the process. | 646 // The dispatcher host should clean up the state from the process. |
| 646 EXPECT_FALSE(context()->GetProviderHost(process_id, provider_id)); | 647 EXPECT_FALSE(context()->GetProviderHost(process_id, provider_id)); |
| 647 EXPECT_EQ(ServiceWorkerVersion::STOPPED, version_->running_status()); | 648 EXPECT_EQ(EmbeddedWorkerStatus::STOPPED, version_->running_status()); |
| 648 | 649 |
| 649 // We should be able to hook up a new dispatcher host although the old object | 650 // We should be able to hook up a new dispatcher host although the old object |
| 650 // is not yet destroyed. This is what the browser does when reusing a crashed | 651 // is not yet destroyed. This is what the browser does when reusing a crashed |
| 651 // render process. | 652 // render process. |
| 652 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host( | 653 scoped_refptr<TestingServiceWorkerDispatcherHost> new_dispatcher_host( |
| 653 new TestingServiceWorkerDispatcherHost( | 654 new TestingServiceWorkerDispatcherHost( |
| 654 process_id, context_wrapper(), &resource_context_, helper_.get())); | 655 process_id, context_wrapper(), &resource_context_, helper_.get())); |
| 655 | 656 |
| 656 // To show the new dispatcher can operate, simulate provider creation. Since | 657 // To show the new dispatcher can operate, simulate provider creation. Since |
| 657 // the old dispatcher cleaned up the old provider host, the new one won't | 658 // the old dispatcher cleaned up the old provider host, the new one won't |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 provider_host_->process_id()); | 763 provider_host_->process_id()); |
| 763 // SendSetHostedVersionId should reject because the provider host process id | 764 // SendSetHostedVersionId should reject because the provider host process id |
| 764 // is different. | 765 // is different. |
| 765 SendSetHostedVersionId(kProviderId, version_->version_id()); | 766 SendSetHostedVersionId(kProviderId, version_->version_id()); |
| 766 base::RunLoop().RunUntilIdle(); | 767 base::RunLoop().RunUntilIdle(); |
| 767 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( | 768 EXPECT_FALSE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( |
| 768 ServiceWorkerMsg_AssociateRegistration::ID)); | 769 ServiceWorkerMsg_AssociateRegistration::ID)); |
| 769 } | 770 } |
| 770 | 771 |
| 771 } // namespace content | 772 } // namespace content |
| OLD | NEW |