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/service_worker/embedded_worker_test_helper.h" | 5 #include "content/browser/service_worker/embedded_worker_test_helper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 : public mojom::EmbeddedWorkerSetup { | 54 : public mojom::EmbeddedWorkerSetup { |
55 public: | 55 public: |
56 static void Create( | 56 static void Create( |
57 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 57 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
58 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request) { | 58 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request) { |
59 new MockEmbeddedWorkerSetup(helper, std::move(request)); | 59 new MockEmbeddedWorkerSetup(helper, std::move(request)); |
60 } | 60 } |
61 | 61 |
62 void ExchangeInterfaceProviders( | 62 void ExchangeInterfaceProviders( |
63 int32_t thread_id, | 63 int32_t thread_id, |
64 mojo::shell::mojom::InterfaceProviderRequest services, | 64 shell::mojom::InterfaceProviderRequest services, |
65 mojo::shell::mojom::InterfaceProviderPtr exposed_services) override { | 65 shell::mojom::InterfaceProviderPtr exposed_services) override { |
66 if (!helper_) | 66 if (!helper_) |
67 return; | 67 return; |
68 helper_->OnSetupMojoStub(thread_id, std::move(services), | 68 helper_->OnSetupMojoStub(thread_id, std::move(services), |
69 std::move(exposed_services)); | 69 std::move(exposed_services)); |
70 } | 70 } |
71 | 71 |
72 private: | 72 private: |
73 MockEmbeddedWorkerSetup( | 73 MockEmbeddedWorkerSetup( |
74 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, | 74 const base::WeakPtr<EmbeddedWorkerTestHelper>& helper, |
75 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request) | 75 mojo::InterfaceRequest<mojom::EmbeddedWorkerSetup> request) |
(...skipping 19 matching lines...) Expand all Loading... |
95 wrapper_->process_manager()->SetProcessIdForTest(mock_render_process_id()); | 95 wrapper_->process_manager()->SetProcessIdForTest(mock_render_process_id()); |
96 wrapper_->process_manager()->SetNewProcessIdForTest(new_render_process_id()); | 96 wrapper_->process_manager()->SetNewProcessIdForTest(new_render_process_id()); |
97 registry()->AddChildProcessSender(mock_render_process_id_, this, | 97 registry()->AddChildProcessSender(mock_render_process_id_, this, |
98 NewMessagePortMessageFilter()); | 98 NewMessagePortMessageFilter()); |
99 | 99 |
100 // Setup process level mojo service registry pair. | 100 // Setup process level mojo service registry pair. |
101 std::unique_ptr<ServiceRegistryImpl> host_service_registry( | 101 std::unique_ptr<ServiceRegistryImpl> host_service_registry( |
102 new ServiceRegistryImpl); | 102 new ServiceRegistryImpl); |
103 render_process_service_registry_.ServiceRegistry::AddService( | 103 render_process_service_registry_.ServiceRegistry::AddService( |
104 base::Bind(&MockEmbeddedWorkerSetup::Create, weak_factory_.GetWeakPtr())); | 104 base::Bind(&MockEmbeddedWorkerSetup::Create, weak_factory_.GetWeakPtr())); |
105 mojo::shell::mojom::InterfaceProviderPtr services; | 105 shell::mojom::InterfaceProviderPtr services; |
106 render_process_service_registry_.Bind(mojo::GetProxy(&services)); | 106 render_process_service_registry_.Bind(mojo::GetProxy(&services)); |
107 host_service_registry->BindRemoteServiceProvider(std::move(services)); | 107 host_service_registry->BindRemoteServiceProvider(std::move(services)); |
108 render_process_host_->SetServiceRegistry(std::move(host_service_registry)); | 108 render_process_host_->SetServiceRegistry(std::move(host_service_registry)); |
109 } | 109 } |
110 | 110 |
111 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { | 111 EmbeddedWorkerTestHelper::~EmbeddedWorkerTestHelper() { |
112 if (wrapper_.get()) | 112 if (wrapper_.get()) |
113 wrapper_->Shutdown(); | 113 wrapper_->Shutdown(); |
114 } | 114 } |
115 | 115 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 int request_id, | 414 int request_id, |
415 const PushEventPayload& payload) { | 415 const PushEventPayload& payload) { |
416 base::ThreadTaskRunnerHandle::Get()->PostTask( | 416 base::ThreadTaskRunnerHandle::Get()->PostTask( |
417 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, | 417 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnPushEvent, |
418 weak_factory_.GetWeakPtr(), | 418 weak_factory_.GetWeakPtr(), |
419 current_embedded_worker_id_, request_id, payload)); | 419 current_embedded_worker_id_, request_id, payload)); |
420 } | 420 } |
421 | 421 |
422 void EmbeddedWorkerTestHelper::OnSetupMojoStub( | 422 void EmbeddedWorkerTestHelper::OnSetupMojoStub( |
423 int thread_id, | 423 int thread_id, |
424 mojo::shell::mojom::InterfaceProviderRequest services, | 424 shell::mojom::InterfaceProviderRequest services, |
425 mojo::shell::mojom::InterfaceProviderPtr exposed_services) { | 425 shell::mojom::InterfaceProviderPtr exposed_services) { |
426 std::unique_ptr<ServiceRegistryImpl> new_registry(new ServiceRegistryImpl); | 426 std::unique_ptr<ServiceRegistryImpl> new_registry(new ServiceRegistryImpl); |
427 new_registry->Bind(std::move(services)); | 427 new_registry->Bind(std::move(services)); |
428 new_registry->BindRemoteServiceProvider(std::move(exposed_services)); | 428 new_registry->BindRemoteServiceProvider(std::move(exposed_services)); |
429 OnSetupMojo(new_registry.get()); | 429 OnSetupMojo(new_registry.get()); |
430 thread_id_service_registry_map_.add(thread_id, std::move(new_registry)); | 430 thread_id_service_registry_map_.add(thread_id, std::move(new_registry)); |
431 } | 431 } |
432 | 432 |
433 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { | 433 EmbeddedWorkerRegistry* EmbeddedWorkerTestHelper::registry() { |
434 DCHECK(context()); | 434 DCHECK(context()); |
435 return context()->embedded_worker_registry(); | 435 return context()->embedded_worker_registry(); |
436 } | 436 } |
437 | 437 |
438 MessagePortMessageFilter* | 438 MessagePortMessageFilter* |
439 EmbeddedWorkerTestHelper::NewMessagePortMessageFilter() { | 439 EmbeddedWorkerTestHelper::NewMessagePortMessageFilter() { |
440 scoped_refptr<MessagePortMessageFilter> filter( | 440 scoped_refptr<MessagePortMessageFilter> filter( |
441 new MockMessagePortMessageFilter); | 441 new MockMessagePortMessageFilter); |
442 message_port_message_filters_.push_back(filter); | 442 message_port_message_filters_.push_back(filter); |
443 return filter.get(); | 443 return filter.get(); |
444 } | 444 } |
445 | 445 |
446 } // namespace content | 446 } // namespace content |
OLD | NEW |