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

Unified Diff: content/browser/service_worker/service_worker_version.h

Issue 2490623005: Remove InterfaceRegistry/Provider from service workers (Closed)
Patch Set: review Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_version.h
diff --git a/content/browser/service_worker/service_worker_version.h b/content/browser/service_worker/service_worker_version.h
index 8e08831ea13e2913b6ad6edf95019677315db566..2d1b9f3a9f4ee2f6e0798b1eacd428cea7121cde 100644
--- a/content/browser/service_worker/service_worker_version.h
+++ b/content/browser/service_worker/service_worker_version.h
@@ -34,6 +34,7 @@
#include "content/browser/service_worker/service_worker_script_cache_map.h"
#include "content/common/content_export.h"
#include "content/common/origin_trials/trial_token_validator.h"
+#include "content/common/service_worker/service_worker_event_dispatcher.mojom.h"
#include "content/common/service_worker/service_worker_status_code.h"
#include "content/common/service_worker/service_worker_types.h"
#include "ipc/ipc_message.h"
@@ -267,15 +268,12 @@ class CONTENT_EXPORT ServiceWorkerVersion
// was not found or the worker already terminated.
bool FinishExternalRequest(const std::string& request_uuid);
- // Connects to a specific mojo service exposed by the (running) service
- // worker. If a connection to a service for the same Interface already exists
- // this will return that existing connection. The |request_id| must be a value
- // previously returned by StartRequest. If the connection to the service
- // fails or closes before the request finished, the error callback associated
- // with |request_id| is called.
- // Only call GetMojoServiceForRequest once for a specific |request_id|.
- template <typename Interface>
- base::WeakPtr<Interface> GetMojoServiceForRequest(int request_id);
+ // The dispatcher should be valid after the worker is started and invalid
+ // after StopWorker or OnDetached is called.
falken 2016/11/23 14:32:31 nit: the "should be" makes it unclear whether this
shimazu 2016/11/24 06:47:32 Thanks, that's right. Updated.
+ mojom::ServiceWorkerEventDispatcher* event_dispatcher() {
+ DCHECK(event_dispatcher_.is_bound());
+ return event_dispatcher_.get();
+ }
// Dispatches an event. If dispatching the event fails, all of the error
// callbacks that were associated with |request_ids| via StartRequest are
@@ -755,13 +753,8 @@ class CONTENT_EXPORT ServiceWorkerVersion
using RequestUUIDToRequestIDMap = std::map<std::string, int>;
RequestUUIDToRequestIDMap external_request_uuid_to_request_id_;
- // Stores all open connections to mojo services. Maps the service name to
- // the actual interface pointer. When a connection is closed it is removed
- // from this map.
- // mojo_services_[Interface::Name_] is assumed to always contain a
- // MojoServiceWrapper<Interface> instance.
- base::ScopedPtrHashMap<const char*, std::unique_ptr<BaseMojoServiceWrapper>>
- mojo_services_;
+ // Connected to ServiceWorkerContextClient while the worker is running.
+ mojom::ServiceWorkerEventDispatcherPtr event_dispatcher_;
std::set<const ServiceWorkerURLRequestJob*> streaming_url_request_jobs_;
@@ -824,31 +817,6 @@ class CONTENT_EXPORT ServiceWorkerVersion
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
};
-template <typename Interface>
-base::WeakPtr<Interface> ServiceWorkerVersion::GetMojoServiceForRequest(
- int request_id) {
- DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status());
- PendingRequest* request = pending_requests_.Lookup(request_id);
- DCHECK(request) << "Invalid request id";
- DCHECK(!request->mojo_service)
- << "Request is already associated with a mojo service";
-
- MojoServiceWrapper<Interface>* service =
- static_cast<MojoServiceWrapper<Interface>*>(
- mojo_services_.get(Interface::Name_));
- if (!service) {
- mojo::InterfacePtr<Interface> interface_ptr;
- embedded_worker_->GetRemoteInterfaces()->GetInterface(&interface_ptr);
- interface_ptr.set_connection_error_handler(
- base::Bind(&ServiceWorkerVersion::OnMojoConnectionError,
- weak_factory_.GetWeakPtr(), Interface::Name_));
- service = new MojoServiceWrapper<Interface>(this, std::move(interface_ptr));
- mojo_services_.add(Interface::Name_, base::WrapUnique(service));
- }
- request->mojo_service = Interface::Name_;
- return service->GetWeakPtr();
-}
-
template <typename ResponseMessage>
void ServiceWorkerVersion::DispatchSimpleEvent(int request_id,
const IPC::Message& message) {

Powered by Google App Engine
This is Rietveld 408576698