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

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

Issue 2767093004: Implement the BackgroundFetch{Fail,ed} Service Worker events (Closed)
Patch Set: forward declare the data view Created 3 years, 9 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 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/atomic_sequence_num.h" 13 #include "base/atomic_sequence_num.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "content/browser/service_worker/embedded_worker_instance.h" 18 #include "content/browser/service_worker/embedded_worker_instance.h"
19 #include "content/browser/service_worker/embedded_worker_registry.h" 19 #include "content/browser/service_worker/embedded_worker_registry.h"
20 #include "content/browser/service_worker/embedded_worker_status.h" 20 #include "content/browser/service_worker/embedded_worker_status.h"
21 #include "content/browser/service_worker/service_worker_context_core.h" 21 #include "content/browser/service_worker/service_worker_context_core.h"
22 #include "content/browser/service_worker/service_worker_context_wrapper.h" 22 #include "content/browser/service_worker/service_worker_context_wrapper.h"
23 #include "content/browser/service_worker/service_worker_dispatcher_host.h" 23 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
24 #include "content/common/background_fetch/background_fetch_types.h"
24 #include "content/common/service_worker/embedded_worker_messages.h" 25 #include "content/common/service_worker/embedded_worker_messages.h"
25 #include "content/common/service_worker/embedded_worker_start_params.h" 26 #include "content/common/service_worker/embedded_worker_start_params.h"
26 #include "content/common/service_worker/service_worker_messages.h" 27 #include "content/common/service_worker/service_worker_messages.h"
27 #include "content/common/service_worker/service_worker_utils.h" 28 #include "content/common/service_worker/service_worker_utils.h"
28 #include "content/public/common/push_event_payload.h" 29 #include "content/public/common/push_event_payload.h"
29 #include "content/public/test/mock_render_process_host.h" 30 #include "content/public/test/mock_render_process_host.h"
30 #include "content/public/test/test_browser_context.h" 31 #include "content/public/test/test_browser_context.h"
31 #include "mojo/public/cpp/bindings/interface_request.h" 32 #include "mojo/public/cpp/bindings/interface_request.h"
32 #include "mojo/public/cpp/bindings/strong_binding.h" 33 #include "mojo/public/cpp/bindings/strong_binding.h"
33 #include "services/service_manager/public/cpp/interface_provider.h" 34 #include "services/service_manager/public/cpp/interface_provider.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 168
168 void DispatchBackgroundFetchClickEvent( 169 void DispatchBackgroundFetchClickEvent(
169 const std::string& tag, 170 const std::string& tag,
170 mojom::BackgroundFetchState state, 171 mojom::BackgroundFetchState state,
171 const DispatchBackgroundFetchClickEventCallback& callback) override { 172 const DispatchBackgroundFetchClickEventCallback& callback) override {
172 if (!helper_) 173 if (!helper_)
173 return; 174 return;
174 helper_->OnBackgroundFetchClickEventStub(tag, state, callback); 175 helper_->OnBackgroundFetchClickEventStub(tag, state, callback);
175 } 176 }
176 177
178 void DispatchBackgroundFetchFailEvent(
179 const std::string& tag,
180 const std::vector<BackgroundFetchSettledFetch>& fetches,
181 const DispatchBackgroundFetchFailEventCallback& callback) override {
182 if (!helper_)
183 return;
184 helper_->OnBackgroundFetchFailEventStub(tag, fetches, callback);
185 }
186
187 void DispatchBackgroundFetchedEvent(
188 const std::string& tag,
189 const std::vector<BackgroundFetchSettledFetch>& fetches,
190 const DispatchBackgroundFetchedEventCallback& callback) override {
191 if (!helper_)
192 return;
193 helper_->OnBackgroundFetchedEventStub(tag, fetches, callback);
194 }
195
177 void DispatchFetchEvent(int fetch_event_id, 196 void DispatchFetchEvent(int fetch_event_id,
178 const ServiceWorkerFetchRequest& request, 197 const ServiceWorkerFetchRequest& request,
179 mojom::FetchEventPreloadHandlePtr preload_handle, 198 mojom::FetchEventPreloadHandlePtr preload_handle,
180 const DispatchFetchEventCallback& callback) override { 199 const DispatchFetchEventCallback& callback) override {
181 if (!helper_) 200 if (!helper_)
182 return; 201 return;
183 helper_->OnFetchEventStub(thread_id_, fetch_event_id, request, 202 helper_->OnFetchEventStub(thread_id_, fetch_event_id, request,
184 std::move(preload_handle), callback); 203 std::move(preload_handle), callback);
185 } 204 }
186 205
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 424 }
406 425
407 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent( 426 void EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent(
408 const std::string& tag, 427 const std::string& tag,
409 mojom::BackgroundFetchState state, 428 mojom::BackgroundFetchState state,
410 const mojom::ServiceWorkerEventDispatcher:: 429 const mojom::ServiceWorkerEventDispatcher::
411 DispatchBackgroundFetchClickEventCallback& callback) { 430 DispatchBackgroundFetchClickEventCallback& callback) {
412 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); 431 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
413 } 432 }
414 433
434 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent(
435 const std::string& tag,
436 const std::vector<BackgroundFetchSettledFetch>& fetches,
437 const mojom::ServiceWorkerEventDispatcher::
438 DispatchBackgroundFetchFailEventCallback& callback) {
439 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
440 }
441
442 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent(
443 const std::string& tag,
444 const std::vector<BackgroundFetchSettledFetch>& fetches,
445 const mojom::ServiceWorkerEventDispatcher::
446 DispatchBackgroundFetchedEventCallback& callback) {
447 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
448 }
449
415 void EmbeddedWorkerTestHelper::OnExtendableMessageEvent( 450 void EmbeddedWorkerTestHelper::OnExtendableMessageEvent(
416 mojom::ExtendableMessageEventPtr event, 451 mojom::ExtendableMessageEventPtr event,
417 const mojom::ServiceWorkerEventDispatcher:: 452 const mojom::ServiceWorkerEventDispatcher::
418 DispatchExtendableMessageEventCallback& callback) { 453 DispatchExtendableMessageEventCallback& callback) {
419 callback.Run(SERVICE_WORKER_OK, base::Time::Now()); 454 callback.Run(SERVICE_WORKER_OK, base::Time::Now());
420 } 455 }
421 456
422 void EmbeddedWorkerTestHelper::OnInstallEvent(int embedded_worker_id, 457 void EmbeddedWorkerTestHelper::OnInstallEvent(int embedded_worker_id,
423 int request_id) { 458 int request_id) {
424 // The installing worker may have been doomed and terminated. 459 // The installing worker may have been doomed and terminated.
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 const std::string& tag, 656 const std::string& tag,
622 mojom::BackgroundFetchState state, 657 mojom::BackgroundFetchState state,
623 const mojom::ServiceWorkerEventDispatcher:: 658 const mojom::ServiceWorkerEventDispatcher::
624 DispatchBackgroundFetchClickEventCallback& callback) { 659 DispatchBackgroundFetchClickEventCallback& callback) {
625 base::ThreadTaskRunnerHandle::Get()->PostTask( 660 base::ThreadTaskRunnerHandle::Get()->PostTask(
626 FROM_HERE, 661 FROM_HERE,
627 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent, 662 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchClickEvent,
628 AsWeakPtr(), tag, state, callback)); 663 AsWeakPtr(), tag, state, callback));
629 } 664 }
630 665
666 void EmbeddedWorkerTestHelper::OnBackgroundFetchFailEventStub(
667 const std::string& tag,
668 const std::vector<BackgroundFetchSettledFetch>& fetches,
669 const mojom::ServiceWorkerEventDispatcher::
670 DispatchBackgroundFetchFailEventCallback& callback) {
671 base::ThreadTaskRunnerHandle::Get()->PostTask(
672 FROM_HERE,
673 base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchFailEvent,
674 AsWeakPtr(), tag, fetches, callback));
675 }
676
677 void EmbeddedWorkerTestHelper::OnBackgroundFetchedEventStub(
678 const std::string& tag,
679 const std::vector<BackgroundFetchSettledFetch>& fetches,
680 const mojom::ServiceWorkerEventDispatcher::
681 DispatchBackgroundFetchedEventCallback& callback) {
682 base::ThreadTaskRunnerHandle::Get()->PostTask(
683 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnBackgroundFetchedEvent,
684 AsWeakPtr(), tag, fetches, callback));
685 }
686
631 void EmbeddedWorkerTestHelper::OnExtendableMessageEventStub( 687 void EmbeddedWorkerTestHelper::OnExtendableMessageEventStub(
632 mojom::ExtendableMessageEventPtr event, 688 mojom::ExtendableMessageEventPtr event,
633 const mojom::ServiceWorkerEventDispatcher:: 689 const mojom::ServiceWorkerEventDispatcher::
634 DispatchExtendableMessageEventCallback& callback) { 690 DispatchExtendableMessageEventCallback& callback) {
635 base::ThreadTaskRunnerHandle::Get()->PostTask( 691 base::ThreadTaskRunnerHandle::Get()->PostTask(
636 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnExtendableMessageEvent, 692 FROM_HERE, base::Bind(&EmbeddedWorkerTestHelper::OnExtendableMessageEvent,
637 AsWeakPtr(), base::Passed(&event), callback)); 693 AsWeakPtr(), base::Passed(&event), callback));
638 } 694 }
639 695
640 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) { 696 void EmbeddedWorkerTestHelper::OnInstallEventStub(int request_id) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 service_manager::InterfaceProviderSpec()); 775 service_manager::InterfaceProviderSpec());
720 776
721 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces( 777 std::unique_ptr<service_manager::InterfaceProvider> remote_interfaces(
722 new service_manager::InterfaceProvider); 778 new service_manager::InterfaceProvider);
723 remote_interfaces->Bind(std::move(interfaces)); 779 remote_interfaces->Bind(std::move(interfaces));
724 rph->SetRemoteInterfaces(std::move(remote_interfaces)); 780 rph->SetRemoteInterfaces(std::move(remote_interfaces));
725 return registry; 781 return registry;
726 } 782 }
727 783
728 } // namespace content 784 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/embedded_worker_test_helper.h ('k') | content/browser/service_worker/service_worker_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698