Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: content/browser/service_worker/service_worker_version.h

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: rebase/fix comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <functional> 10 #include <functional>
(...skipping 16 matching lines...) Expand all
27 #include "base/optional.h" 27 #include "base/optional.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
29 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "base/timer/timer.h" 30 #include "base/timer/timer.h"
31 #include "content/browser/service_worker/embedded_worker_instance.h" 31 #include "content/browser/service_worker/embedded_worker_instance.h"
32 #include "content/browser/service_worker/embedded_worker_status.h" 32 #include "content/browser/service_worker/embedded_worker_status.h"
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_script_cache_map.h" 34 #include "content/browser/service_worker/service_worker_script_cache_map.h"
35 #include "content/common/content_export.h" 35 #include "content/common/content_export.h"
36 #include "content/common/origin_trials/trial_token_validator.h" 36 #include "content/common/origin_trials/trial_token_validator.h"
37 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
37 #include "content/common/service_worker/service_worker_status_code.h" 38 #include "content/common/service_worker/service_worker_status_code.h"
38 #include "content/common/service_worker/service_worker_types.h" 39 #include "content/common/service_worker/service_worker_types.h"
39 #include "ipc/ipc_message.h" 40 #include "ipc/ipc_message.h"
40 #include "mojo/public/cpp/bindings/interface_ptr.h" 41 #include "mojo/public/cpp/bindings/interface_ptr.h"
41 #include "services/service_manager/public/cpp/interface_provider.h" 42 #include "services/service_manager/public/cpp/interface_provider.h"
42 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h" 43 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerEventResult.h"
43 #include "url/gurl.h" 44 #include "url/gurl.h"
44 #include "url/origin.h" 45 #include "url/origin.h"
45 46
46 // Windows headers will redefine SendMessage. 47 // Windows headers will redefine SendMessage.
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // TODO(mek): Use something other than a bool for event status. 261 // TODO(mek): Use something other than a bool for event status.
261 bool FinishRequest(int request_id, 262 bool FinishRequest(int request_id,
262 bool was_handled, 263 bool was_handled,
263 base::Time dispatch_event_time); 264 base::Time dispatch_event_time);
264 265
265 // Finishes an external request that was started by StartExternalRequest(). 266 // Finishes an external request that was started by StartExternalRequest().
266 // Returns false if there was an error finishing the request: e.g. the request 267 // Returns false if there was an error finishing the request: e.g. the request
267 // was not found or the worker already terminated. 268 // was not found or the worker already terminated.
268 bool FinishExternalRequest(const std::string& request_uuid); 269 bool FinishExternalRequest(const std::string& request_uuid);
269 270
270 // Connects to a specific mojo service exposed by the (running) service 271 // This must be called when the worker is running.
271 // worker. If a connection to a service for the same Interface already exists 272 mojom::ServiceWorkerEventDispatcher* event_dispatcher() {
272 // this will return that existing connection. The |request_id| must be a value 273 DCHECK(event_dispatcher_.is_bound());
273 // previously returned by StartRequest. If the connection to the service 274 return event_dispatcher_.get();
274 // fails or closes before the request finished, the error callback associated 275 }
275 // with |request_id| is called.
276 // Only call GetMojoServiceForRequest once for a specific |request_id|.
277 template <typename Interface>
278 base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id);
279 276
280 // Dispatches an event. If dispatching the event fails, all of the error 277 // Dispatches an event. If dispatching the event fails, all of the error
281 // callbacks that were associated with |request_ids| via StartRequest are 278 // callbacks that were associated with |request_ids| via StartRequest are
282 // called. 279 // called.
283 // Use RegisterRequestCallback or RegisterSimpleRequest to register a callback 280 // Use RegisterRequestCallback or RegisterSimpleRequest to register a callback
284 // to receive messages sent back in response to this event before calling this 281 // to receive messages sent back in response to this event before calling this
285 // method. 282 // method.
286 // This must be called when the worker is running. 283 // This must be called when the worker is running.
287 void DispatchEvent(const std::vector<int>& request_ids, 284 void DispatchEvent(const std::vector<int>& request_ids,
288 const IPC::Message& message); 285 const IPC::Message& message);
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 745
749 // Holds in-flight requests, including requests due to outstanding push, 746 // Holds in-flight requests, including requests due to outstanding push,
750 // fetch, sync, etc. events. 747 // fetch, sync, etc. events.
751 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_; 748 IDMap<PendingRequest, IDMapOwnPointer> pending_requests_;
752 749
753 // Container for pending external requests for this service worker. 750 // Container for pending external requests for this service worker.
754 // (key, value): (request uuid, request id). 751 // (key, value): (request uuid, request id).
755 using RequestUUIDToRequestIDMap = std::map<std::string, int>; 752 using RequestUUIDToRequestIDMap = std::map<std::string, int>;
756 RequestUUIDToRequestIDMap external_request_uuid_to_request_id_; 753 RequestUUIDToRequestIDMap external_request_uuid_to_request_id_;
757 754
758 // Stores all open connections to mojo services. Maps the service name to 755 // Connected to ServiceWorkerContextClient while the worker is running.
759 // the actual interface pointer. When a connection is closed it is removed 756 mojom::ServiceWorkerEventDispatcherPtr event_dispatcher_;
760 // from this map.
761 // mojo_services_[Interface::Name_] is assumed to always contain a
762 // MojoServiceWrapper<Interface> instance.
763 base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>>
764 mojo_services_;
765 757
766 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_; 758 std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
767 759
768 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_; 760 std::map<std::string, ServiceWorkerProviderHost*> controllee_map_;
769 // Will be null while shutting down. 761 // Will be null while shutting down.
770 base::WeakPtr<ServiceWorkerContextCore> context_; 762 base::WeakPtr<ServiceWorkerContextCore> context_;
771 base::ObserverList<Listener> listeners_; 763 base::ObserverList<Listener> listeners_;
772 ServiceWorkerScriptCacheMap script_cache_map_; 764 ServiceWorkerScriptCacheMap script_cache_map_;
773 base::OneShotTimer update_timer_; 765 base::OneShotTimer update_timer_;
774 766
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 809
818 // Keeps the first purpose of starting the worker for UMA. Cleared in 810 // Keeps the first purpose of starting the worker for UMA. Cleared in
819 // FinishStartWorker(). 811 // FinishStartWorker().
820 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_; 812 base::Optional<ServiceWorkerMetrics::EventType> start_worker_first_purpose_;
821 813
822 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_; 814 base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_;
823 815
824 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion); 816 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
825 }; 817 };
826 818
827 template <typename Interface>
828 base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest(
829 int request_id) {
830 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status());
831 PendingRequest* request = pending_requests_.Lookup(request_id);
832 DCHECK(request) << "Invalid request id";
833 DCHECK(!request->mojo_service)
834 << "Request is already associated with a mojo service";
835
836 MojoServiceWrapper<Interface>* service =
837 static_cast<MojoServiceWrapper<Interface>*>(
838 mojo_services_.get(Interface::Name_));
839 if (!service) {
840 mojo::InterfacePtr<Interface> interface_ptr;
841 embedded_worker_->GetRemoteInterfaces()->GetInterface(&interface_ptr);
842 interface_ptr.set_connection_error_handler(
843 base::Bind(&ServiceWorkerVersion::OnMojoConnectionError,
844 weak_factory_.GetWeakPtr(), Interface::Name_));
845 service = new MojoServiceWrapper<Interface>(this, std::move(interface_ptr));
846 mojo_services_.add(Interface::Name_, base::WrapUnique(service));
847 }
848 request->mojo_service = Interface::Name_;
849 return service->GetWeakPtr();
850 }
851
852 template <typename ResponseMessage> 819 template <typename ResponseMessage>
853 void ServiceWorkerVersion::DispatchSimpleEvent(int request_id, 820 void ServiceWorkerVersion::DispatchSimpleEvent(int request_id,
854 const IPC::Message& message) { 821 const IPC::Message& message) {
855 RegisterSimpleRequest<ResponseMessage>(request_id); 822 RegisterSimpleRequest<ResponseMessage>(request_id);
856 DispatchEvent({request_id}, message); 823 DispatchEvent({request_id}, message);
857 } 824 }
858 825
859 template <typename ResponseMessage, typename ResponseCallbackType> 826 template <typename ResponseMessage, typename ResponseCallbackType>
860 void ServiceWorkerVersion::RegisterRequestCallback( 827 void ServiceWorkerVersion::RegisterRequestCallback(
861 int request_id, 828 int request_id,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 862
896 // At this point |this| can have been deleted, so don't do anything other 863 // At this point |this| can have been deleted, so don't do anything other
897 // than returning. 864 // than returning.
898 865
899 return true; 866 return true;
900 } 867 }
901 868
902 } // namespace content 869 } // namespace content
903 870
904 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_ 871 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_VERSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698