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 "mojo/common/common_type_converters.h" | 48 #include "mojo/common/common_type_converters.h" |
48 #include "mojo/common/url_type_converters.h" | 49 #include "mojo/common/url_type_converters.h" |
49 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
50 #include "net/http/http_response_info.h" | 51 #include "net/http/http_response_info.h" |
51 | 52 |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 786 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
786 ServiceWorkerMsg_FetchEvent(request_id, request)); | 787 ServiceWorkerMsg_FetchEvent(request_id, request)); |
787 if (status != SERVICE_WORKER_OK) { | 788 if (status != SERVICE_WORKER_OK) { |
788 fetch_requests_.Remove(request_id); | 789 fetch_requests_.Remove(request_id); |
789 RunSoon(base::Bind(&RunErrorFetchCallback, | 790 RunSoon(base::Bind(&RunErrorFetchCallback, |
790 fetch_callback, | 791 fetch_callback, |
791 SERVICE_WORKER_ERROR_FAILED)); | 792 SERVICE_WORKER_ERROR_FAILED)); |
792 } | 793 } |
793 } | 794 } |
794 | 795 |
795 void ServiceWorkerVersion::DispatchSyncEvent(const StatusCallback& callback) { | 796 void ServiceWorkerVersion::DispatchSyncEvent(SyncRegistrationPtr registration, |
| 797 const StatusCallback& callback) { |
796 DCHECK_EQ(ACTIVATED, status()) << status(); | 798 DCHECK_EQ(ACTIVATED, status()) << status(); |
797 if (running_status() != RUNNING) { | 799 if (running_status() != RUNNING) { |
798 // Schedule calling this method after starting the worker. | 800 // Schedule calling this method after starting the worker. |
799 StartWorker(base::Bind(&RunTaskAfterStartWorker, | 801 StartWorker(base::Bind( |
800 weak_factory_.GetWeakPtr(), callback, | 802 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
801 base::Bind(&self::DispatchSyncEvent, | 803 base::Bind(&self::DispatchSyncEvent, weak_factory_.GetWeakPtr(), |
802 weak_factory_.GetWeakPtr(), | 804 base::Passed(registration.Pass()), callback))); |
803 callback))); | |
804 return; | 805 return; |
805 } | 806 } |
806 | 807 |
807 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); | 808 int request_id = AddRequest(callback, &sync_requests_, REQUEST_SYNC); |
808 if (!background_sync_dispatcher_) { | 809 if (!background_sync_dispatcher_) { |
809 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( | 810 embedded_worker_->GetServiceRegistry()->ConnectToRemoteService( |
810 mojo::GetProxy(&background_sync_dispatcher_)); | 811 mojo::GetProxy(&background_sync_dispatcher_)); |
811 background_sync_dispatcher_.set_connection_error_handler(base::Bind( | 812 background_sync_dispatcher_.set_connection_error_handler(base::Bind( |
812 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, | 813 &ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError, |
813 weak_factory_.GetWeakPtr())); | 814 weak_factory_.GetWeakPtr())); |
814 } | 815 } |
815 | 816 |
816 // TODO(iclelland): Replace this with the real event registration details | |
817 // crbug.com/482066 | |
818 content::SyncRegistrationPtr null_event(content::SyncRegistration::New()); | |
819 | |
820 background_sync_dispatcher_->Sync( | 817 background_sync_dispatcher_->Sync( |
821 null_event.Pass(), base::Bind(&self::OnSyncEventFinished, | 818 registration.Pass(), base::Bind(&self::OnSyncEventFinished, |
822 weak_factory_.GetWeakPtr(), request_id)); | 819 weak_factory_.GetWeakPtr(), request_id)); |
823 } | 820 } |
824 | 821 |
825 void ServiceWorkerVersion::DispatchNotificationClickEvent( | 822 void ServiceWorkerVersion::DispatchNotificationClickEvent( |
826 const StatusCallback& callback, | 823 const StatusCallback& callback, |
827 int64_t persistent_notification_id, | 824 int64_t persistent_notification_id, |
828 const PlatformNotificationData& notification_data) { | 825 const PlatformNotificationData& notification_data) { |
829 DCHECK_EQ(ACTIVATED, status()) << status(); | 826 DCHECK_EQ(ACTIVATED, status()) << status(); |
830 if (running_status() != RUNNING) { | 827 if (running_status() != RUNNING) { |
831 // Schedule calling this method after starting the worker. | 828 // Schedule calling this method after starting the worker. |
832 StartWorker(base::Bind( | 829 StartWorker(base::Bind( |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2231 base::string16()); | 2228 base::string16()); |
2232 service_port_dispatcher_.reset(); | 2229 service_port_dispatcher_.reset(); |
2233 } | 2230 } |
2234 | 2231 |
2235 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { | 2232 void ServiceWorkerVersion::OnBackgroundSyncDispatcherConnectionError() { |
2236 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); | 2233 RunIDMapCallbacks(&sync_requests_, SERVICE_WORKER_ERROR_FAILED); |
2237 background_sync_dispatcher_.reset(); | 2234 background_sync_dispatcher_.reset(); |
2238 } | 2235 } |
2239 | 2236 |
2240 } // namespace content | 2237 } // namespace content |
OLD | NEW |