| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 819 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
| 820 ServiceWorkerMsg_FetchEvent(request_id, request)); | 820 ServiceWorkerMsg_FetchEvent(request_id, request)); |
| 821 if (status != SERVICE_WORKER_OK) { | 821 if (status != SERVICE_WORKER_OK) { |
| 822 fetch_requests_.Remove(request_id); | 822 fetch_requests_.Remove(request_id); |
| 823 RunSoon(base::Bind(&RunErrorFetchCallback, | 823 RunSoon(base::Bind(&RunErrorFetchCallback, |
| 824 fetch_callback, | 824 fetch_callback, |
| 825 SERVICE_WORKER_ERROR_FAILED)); | 825 SERVICE_WORKER_ERROR_FAILED)); |
| 826 } | 826 } |
| 827 } | 827 } |
| 828 | 828 |
| 829 void ServiceWorkerVersion::DispatchSyncEvent(SyncRegistrationPtr registration, | 829 void ServiceWorkerVersion::DispatchSyncEvent( |
| 830 const StatusCallback& callback) { | 830 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 831 const StatusCallback& callback) { |
| 831 OnBeginEvent(); | 832 OnBeginEvent(); |
| 832 DCHECK_EQ(ACTIVATED, status()) << status(); | 833 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 833 if (running_status() != RUNNING) { | 834 if (running_status() != RUNNING) { |
| 834 // Schedule calling this method after starting the worker. | 835 // Schedule calling this method after starting the worker. |
| 835 StartWorker(base::Bind( | 836 StartWorker(base::Bind( |
| 836 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, | 837 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
| 837 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), | 838 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), |
| 838 base::Passed(registration.Pass()), callback))); | 839 handle_id, callback))); |
| 839 return; | 840 return; |
| 840 } | 841 } |
| 841 | 842 |
| 842 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); | 843 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); |
| 843 if (!background_sync_dispatcher_) { | 844 if (!background_sync_dispatcher_) { |
| 844 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | 845 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
| 845 mojo::GetProxy(&background_sync_dispatcher_)); | 846 mojo::GetProxy(&background_sync_dispatcher_)); |
| 846 background_sync_dispatcher_.set_connection_error_handler(base::Bind( | 847 background_sync_dispatcher_.set_connection_error_handler(base::Bind( |
| 847 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, | 848 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, |
| 848 weak_factory_.GetWeakPtr())); | 849 weak_factory_.GetWeakPtr())); |
| 849 } | 850 } |
| 850 | 851 |
| 851 background_sync_dispatcher_->Sync( | 852 background_sync_dispatcher_->Sync( |
| 852 registration.Pass(), base::Bind(&self::OnSyncEventFinished, | 853 handle_id, base::Bind(&self::OnSyncEventFinished, |
| 853 weak_factory_.GetWeakPtr(), request_id)); | 854 weak_factory_.GetWeakPtr(), request_id)); |
| 854 } | 855 } |
| 855 | 856 |
| 856 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 857 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| 857 const StatusCallback& callback, | 858 const StatusCallback& callback, |
| 858 int64_t persistent_notification_id, | 859 int64_t persistent_notification_id, |
| 859 const PlatformNotificationData& notification_data, | 860 const PlatformNotificationData& notification_data, |
| 860 int action_index) { | 861 int action_index) { |
| 861 OnBeginEvent(); | 862 OnBeginEvent(); |
| 862 DCHECK_EQ(ACTIVATED, status()) << status(); | 863 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 863 if (running_status() != RUNNING) { | 864 if (running_status() != RUNNING) { |
| (...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2353 void ServiceWorkerVersion::OnBeginEvent() { | 2354 void ServiceWorkerVersion::OnBeginEvent() { |
| 2354 if (should_exclude_from_uma_ || running_status() != RUNNING || | 2355 if (should_exclude_from_uma_ || running_status() != RUNNING || |
| 2355 idle_time_.is_null()) { | 2356 idle_time_.is_null()) { |
| 2356 return; | 2357 return; |
| 2357 } | 2358 } |
| 2358 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 2359 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 2359 idle_time_); | 2360 idle_time_); |
| 2360 } | 2361 } |
| 2361 | 2362 |
| 2362 } // namespace content | 2363 } // namespace content |
| OLD | NEW |