| 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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 807 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
| 808 ServiceWorkerMsg_FetchEvent(request_id, request)); | 808 ServiceWorkerMsg_FetchEvent(request_id, request)); |
| 809 if (status != SERVICE_WORKER_OK) { | 809 if (status != SERVICE_WORKER_OK) { |
| 810 fetch_requests_.Remove(request_id); | 810 fetch_requests_.Remove(request_id); |
| 811 RunSoon(base::Bind(&RunErrorFetchCallback, | 811 RunSoon(base::Bind(&RunErrorFetchCallback, |
| 812 fetch_callback, | 812 fetch_callback, |
| 813 SERVICE_WORKER_ERROR_FAILED)); | 813 SERVICE_WORKER_ERROR_FAILED)); |
| 814 } | 814 } |
| 815 } | 815 } |
| 816 | 816 |
| 817 void ServiceWorkerVersion::DispatchSyncEvent(SyncRegistrationPtr registration, | 817 void ServiceWorkerVersion::DispatchSyncEvent( |
| 818 const StatusCallback& callback) { | 818 BackgroundSyncRegistrationHandle::HandleId handle_id, |
| 819 const StatusCallback& callback) { |
| 819 OnBeginEvent(); | 820 OnBeginEvent(); |
| 820 DCHECK_EQ(ACTIVATED, status()) << status(); | 821 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 821 if (running_status() != RUNNING) { | 822 if (running_status() != RUNNING) { |
| 822 // Schedule calling this method after starting the worker. | 823 // Schedule calling this method after starting the worker. |
| 823 StartWorker(base::Bind( | 824 StartWorker(base::Bind( |
| 824 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, | 825 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
| 825 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), | 826 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), |
| 826 base::Passed(registration.Pass()), callback))); | 827 handle_id, callback))); |
| 827 return; | 828 return; |
| 828 } | 829 } |
| 829 | 830 |
| 830 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); | 831 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); |
| 831 if (!background_sync_dispatcher_) { | 832 if (!background_sync_dispatcher_) { |
| 832 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | 833 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
| 833 mojo::GetProxy(&background_sync_dispatcher_)); | 834 mojo::GetProxy(&background_sync_dispatcher_)); |
| 834 background_sync_dispatcher_.set_connection_error_handler(base::Bind( | 835 background_sync_dispatcher_.set_connection_error_handler(base::Bind( |
| 835 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, | 836 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, |
| 836 weak_factory_.GetWeakPtr())); | 837 weak_factory_.GetWeakPtr())); |
| 837 } | 838 } |
| 838 | 839 |
| 839 background_sync_dispatcher_->Sync( | 840 background_sync_dispatcher_->Sync( |
| 840 registration.Pass(), base::Bind(&self::OnSyncEventFinished, | 841 handle_id, base::Bind(&self::OnSyncEventFinished, |
| 841 weak_factory_.GetWeakPtr(), request_id)); | 842 weak_factory_.GetWeakPtr(), request_id)); |
| 842 } | 843 } |
| 843 | 844 |
| 844 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 845 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
| 845 const StatusCallback& callback, | 846 const StatusCallback& callback, |
| 846 int64_t persistent_notification_id, | 847 int64_t persistent_notification_id, |
| 847 const PlatformNotificationData& notification_data, | 848 const PlatformNotificationData& notification_data, |
| 848 int action_index) { | 849 int action_index) { |
| 849 OnBeginEvent(); | 850 OnBeginEvent(); |
| 850 DCHECK_EQ(ACTIVATED, status()) << status(); | 851 DCHECK_EQ(ACTIVATED, status()) << status(); |
| 851 if (running_status() != RUNNING) { | 852 if (running_status() != RUNNING) { |
| (...skipping 1487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 void ServiceWorkerVersion::OnBeginEvent() { | 2340 void ServiceWorkerVersion::OnBeginEvent() { |
| 2340 if (should_exclude_from_uma_ || running_status() != RUNNING || | 2341 if (should_exclude_from_uma_ || running_status() != RUNNING || |
| 2341 idle_time_.is_null()) { | 2342 idle_time_.is_null()) { |
| 2342 return; | 2343 return; |
| 2343 } | 2344 } |
| 2344 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 2345 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 2345 idle_time_); | 2346 idle_time_); |
| 2346 } | 2347 } |
| 2347 | 2348 |
| 2348 } // namespace content | 2349 } // namespace content |
| OLD | NEW |