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 <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "content/browser/storage_partition_impl.h" | 32 #include "content/browser/storage_partition_impl.h" |
33 #include "content/common/service_worker/service_worker_messages.h" | 33 #include "content/common/service_worker/service_worker_messages.h" |
34 #include "content/common/service_worker/service_worker_type_converters.h" | 34 #include "content/common/service_worker/service_worker_type_converters.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/content_browser_client.h" | 36 #include "content/public/browser/content_browser_client.h" |
37 #include "content/public/browser/page_navigator.h" | 37 #include "content/public/browser/page_navigator.h" |
38 #include "content/public/browser/render_frame_host.h" | 38 #include "content/public/browser/render_frame_host.h" |
39 #include "content/public/browser/render_process_host.h" | 39 #include "content/public/browser/render_process_host.h" |
40 #include "content/public/browser/web_contents.h" | 40 #include "content/public/browser/web_contents.h" |
41 #include "content/public/browser/web_contents_observer.h" | 41 #include "content/public/browser/web_contents_observer.h" |
| 42 #include "content/public/common/background_sync.mojom.h" |
42 #include "content/public/common/child_process_host.h" | 43 #include "content/public/common/child_process_host.h" |
43 #include "content/public/common/content_client.h" | 44 #include "content/public/common/content_client.h" |
44 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
45 #include "content/public/common/result_codes.h" | 46 #include "content/public/common/result_codes.h" |
46 #include "content/public/common/service_registry.h" | 47 #include "content/public/common/service_registry.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 |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 783 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
783 ServiceWorkerMsg_FetchEvent(request_id, request)); | 784 ServiceWorkerMsg_FetchEvent(request_id, request)); |
784 if (status != SERVICE_WORKER_OK) { | 785 if (status != SERVICE_WORKER_OK) { |
785 fetch_requests_.Remove(request_id); | 786 fetch_requests_.Remove(request_id); |
786 RunSoon(base::Bind(&RunErrorFetchCallback, | 787 RunSoon(base::Bind(&RunErrorFetchCallback, |
787 fetch_callback, | 788 fetch_callback, |
788 SERVICE_WORKER_ERROR_FAILED)); | 789 SERVICE_WORKER_ERROR_FAILED)); |
789 } | 790 } |
790 } | 791 } |
791 | 792 |
792 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { | 793 void ServiceWorkerVersion::DispatchSyncEvent(SyncRegistrationPtr registration, |
| 794 const StatusCallback& callback) { |
793 DCHECK_EQ(ACTIVATED, status()) << status(); | 795 DCHECK_EQ(ACTIVATED, status()) << status(); |
794 if (running_status() != RUNNING) { | 796 if (running_status() != RUNNING) { |
795 // Schedule calling this method after starting the worker. | 797 // Schedule calling this method after starting the worker. |
796 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 798 StartWorker(base::Bind( |
797 weak_factory_.GetWeakPtr(), callback, | 799 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
798 base::Bind(&self::DispatchSyncEvent, | 800 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), |
799 weak_factory_.GetWeakPtr(), | 801 base::Passed(registration.Pass()), callback))); |
800 callback))); | |
801 return; | 802 return; |
802 } | 803 } |
803 | 804 |
804 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); | 805 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); |
805 if (!background_sync_dispatcher_) { | 806 if (!background_sync_dispatcher_) { |
806 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | 807 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
807 mojo::GetProxy(&background_sync_dispatcher_)); | 808 mojo::GetProxy(&background_sync_dispatcher_)); |
808 // TODO(iclelland): Register an appropriate mojo error handler with | 809 // TODO(iclelland): Register an appropriate mojo error handler with |
809 // set_connection_error_handler. This will be straightforward once | 810 // set_connection_error_handler. This will be straightforward once |
810 // https://codereview.chromium.org/1210643002 lands. | 811 // https://codereview.chromium.org/1210643002 lands. |
811 } | 812 } |
812 | 813 |
813 // TODO(iclelland): Replace this with the real event registration details | |
814 // crbug.com/482066 | |
815 content::SyncRegistrationPtr null_event(content::SyncRegistration::New()); | |
816 | |
817 background_sync_dispatcher_->Sync( | 814 background_sync_dispatcher_->Sync( |
818 null_event.Pass(), base::Bind(&self::OnSyncEventFinished, | 815 registration.Pass(), base::Bind(&self::OnSyncEventFinished, |
819 weak_factory_.GetWeakPtr(), request_id)); | 816 weak_factory_.GetWeakPtr(), request_id)); |
820 } | 817 } |
821 | 818 |
822 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 819 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
823 const StatusCallback& callback, | 820 const StatusCallback& callback, |
824 int64_t persistent_notification_id, | 821 int64_t persistent_notification_id, |
825 const PlatformNotificationData& notification_data) { | 822 const PlatformNotificationData& notification_data) { |
826 DCHECK_EQ(ACTIVATED, status()) << status(); | 823 DCHECK_EQ(ACTIVATED, status()) << status(); |
827 if (running_status() != RUNNING) { | 824 if (running_status() != RUNNING) { |
828 // Schedule calling this method after starting the worker. | 825 // Schedule calling this method after starting the worker. |
829 StartWorker(base::Bind( | 826 StartWorker(base::Bind( |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2200 | 2197 |
2201 streaming_url_request_jobs_.clear(); | 2198 streaming_url_request_jobs_.clear(); |
2202 | 2199 |
2203 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); | 2200 FOR_EACH_OBSERVER(Listener, listeners_, OnRunningStateChanged(this)); |
2204 | 2201 |
2205 if (should_restart) | 2202 if (should_restart) |
2206 StartWorkerInternal(); | 2203 StartWorkerInternal(); |
2207 } | 2204 } |
2208 | 2205 |
2209 } // namespace content | 2206 } // namespace content |
OLD | NEW |