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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/browser/service_worker/service_worker_metrics.h" | 33 #include "content/browser/service_worker/service_worker_metrics.h" |
34 #include "content/browser/service_worker/service_worker_registration.h" | 34 #include "content/browser/service_worker/service_worker_registration.h" |
35 #include "content/common/service_worker/service_worker_messages.h" | 35 #include "content/common/service_worker/service_worker_messages.h" |
36 #include "content/common/service_worker/service_worker_type_converters.h" | 36 #include "content/common/service_worker/service_worker_type_converters.h" |
37 #include "content/common/service_worker/service_worker_utils.h" | 37 #include "content/common/service_worker/service_worker_utils.h" |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/content_browser_client.h" | 39 #include "content/public/browser/content_browser_client.h" |
40 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
41 #include "content/public/common/content_client.h" | 41 #include "content/public/common/content_client.h" |
42 #include "content/public/common/content_switches.h" | 42 #include "content/public/common/content_switches.h" |
| 43 #include "content/public/common/push_event_payload.h" |
43 #include "content/public/common/result_codes.h" | 44 #include "content/public/common/result_codes.h" |
44 #include "content/public/common/service_registry.h" | 45 #include "content/public/common/service_registry.h" |
45 #include "mojo/common/common_type_converters.h" | 46 #include "mojo/common/common_type_converters.h" |
46 #include "mojo/common/url_type_converters.h" | 47 #include "mojo/common/url_type_converters.h" |
47 #include "net/http/http_response_headers.h" | 48 #include "net/http/http_response_headers.h" |
48 #include "net/http/http_response_info.h" | 49 #include "net/http/http_response_info.h" |
49 | 50 |
50 namespace content { | 51 namespace content { |
51 | 52 |
52 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 53 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( | 651 embedded_worker_->SendMessage(ServiceWorkerMsg_NotificationClickEvent( |
651 request_id, persistent_notification_id, notification_data, | 652 request_id, persistent_notification_id, notification_data, |
652 action_index)); | 653 action_index)); |
653 if (status != SERVICE_WORKER_OK) { | 654 if (status != SERVICE_WORKER_OK) { |
654 notification_click_requests_.Remove(request_id); | 655 notification_click_requests_.Remove(request_id); |
655 RunSoon(base::Bind(callback, status)); | 656 RunSoon(base::Bind(callback, status)); |
656 } | 657 } |
657 } | 658 } |
658 | 659 |
659 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, | 660 void ServiceWorkerVersion::DispatchPushEvent(const StatusCallback& callback, |
660 const std::string& data) { | 661 const PushEventPayload& payload) { |
661 OnBeginEvent(); | 662 OnBeginEvent(); |
662 DCHECK_EQ(ACTIVATED, status()) << status(); | 663 DCHECK_EQ(ACTIVATED, status()) << status(); |
663 if (running_status() != RUNNING) { | 664 if (running_status() != RUNNING) { |
664 // Schedule calling this method after starting the worker. | 665 // Schedule calling this method after starting the worker. |
665 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 666 StartWorker(base::Bind( |
666 weak_factory_.GetWeakPtr(), callback, | 667 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
667 base::Bind(&self::DispatchPushEvent, | 668 base::Bind(&self::DispatchPushEvent, weak_factory_.GetWeakPtr(), |
668 weak_factory_.GetWeakPtr(), | 669 callback, payload))); |
669 callback, data))); | |
670 return; | 670 return; |
671 } | 671 } |
672 | 672 |
673 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH, | 673 int request_id = AddRequest(callback, &push_requests_, REQUEST_PUSH, |
674 ServiceWorkerMetrics::EventType::PUSH); | 674 ServiceWorkerMetrics::EventType::PUSH); |
675 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 675 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
676 ServiceWorkerMsg_PushEvent(request_id, data)); | 676 ServiceWorkerMsg_PushEvent(request_id, payload)); |
677 if (status != SERVICE_WORKER_OK) { | 677 if (status != SERVICE_WORKER_OK) { |
678 push_requests_.Remove(request_id); | 678 push_requests_.Remove(request_id); |
679 RunSoon(base::Bind(callback, status)); | 679 RunSoon(base::Bind(callback, status)); |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( | 683 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
684 const NavigatorConnectClient& client, | 684 const NavigatorConnectClient& client, |
685 const base::string16& message, | 685 const base::string16& message, |
686 const std::vector<TransferredMessagePort>& sent_message_ports, | 686 const std::vector<TransferredMessagePort>& sent_message_ports, |
(...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 void ServiceWorkerVersion::OnBeginEvent() { | 1978 void ServiceWorkerVersion::OnBeginEvent() { |
1979 if (should_exclude_from_uma_ || running_status() != RUNNING || | 1979 if (should_exclude_from_uma_ || running_status() != RUNNING || |
1980 idle_time_.is_null()) { | 1980 idle_time_.is_null()) { |
1981 return; | 1981 return; |
1982 } | 1982 } |
1983 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1983 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
1984 idle_time_); | 1984 idle_time_); |
1985 } | 1985 } |
1986 | 1986 |
1987 } // namespace content | 1987 } // namespace content |
OLD | NEW |