1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
#define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
#include <vector>
#include "base/id_map.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "content/browser/service_worker/service_worker_registration_status.h"
#include "content/public/browser/browser_message_filter.h"
class GURL;
struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
namespace content {
class MessagePortMessageFilter;
class ResourceContext;
class ServiceWorkerContextCore;
class ServiceWorkerContextWrapper;
class ServiceWorkerHandle;
class ServiceWorkerProviderHost;
class ServiceWorkerRegistration;
class ServiceWorkerRegistrationHandle;
class ServiceWorkerVersion;
struct ServiceWorkerObjectInfo;
struct ServiceWorkerRegistrationObjectInfo;
struct ServiceWorkerVersionAttributes;
class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
public:
ServiceWorkerDispatcherHost(
int render_process_id,
MessagePortMessageFilter* message_port_message_filter,
ResourceContext* resource_context);
void Init(ServiceWorkerContextWrapper* context_wrapper);
// BrowserMessageFilter implementation
void OnFilterAdded(IPC::Sender* sender) override;
void OnFilterRemoved() override;
void OnDestruct() const override;
bool OnMessageReceived(const IPC::Message& message) override;
// IPC::Sender implementation
// Send() queues the message until the underlying sender is ready. This
// class assumes that Send() can only fail after that when the renderer
// process has terminated, at which point the whole instance will eventually
// be destroyed.
bool Send(IPC::Message* message) override;
// Returns the existing registration handle whose reference count is
// incremented or newly created one if it doesn't exist.
ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
int provider_id,
ServiceWorkerRegistration* registration);
// Creates a ServiceWorkerHandle to retain |version| and returns a
// ServiceWorkerInfo with a newly created handle ID. The handle is held in
// the dispatcher host until its ref-count becomes zero via
// OnDecrementServiceWorkerRefCount.
ServiceWorkerObjectInfo CreateAndRegisterServiceWorkerHandle(
ServiceWorkerVersion* version);
MessagePortMessageFilter* message_port_message_filter() {
return message_port_message_filter_;
}
protected:
~ServiceWorkerDispatcherHost() override;
private:
friend class BrowserThread;
friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
friend class TestingServiceWorkerDispatcherHost;
// IPC Message handlers
void OnRegisterServiceWorker(int thread_id,
int request_id,
int provider_id,
const GURL& pattern,
const GURL& script_url);
void OnUnregisterServiceWorker(int thread_id,
int request_id,
int provider_id,
const GURL& pattern);
void OnGetRegistration(int thread_id,
int request_id,
int provider_id,
const GURL& document_url);
void OnProviderCreated(int provider_id, int render_frame_id);
void OnProviderDestroyed(int provider_id);
void OnSetHostedVersionId(int provider_id, int64 version_id);
void OnWorkerReadyForInspection(int embedded_worker_id);
void OnWorkerScriptLoaded(int embedded_worker_id, int thread_id);
void OnWorkerScriptLoadFailed(int embedded_worker_id);
void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
void OnWorkerStarted(int embedded_worker_id);
void OnWorkerStopped(int embedded_worker_id);
void OnPausedAfterDownload(int embedded_worker_id);
void OnReportException(int embedded_worker_id,
const base::string16& error_message,
int line_number,
int column_number,
const GURL& source_url);
void OnReportConsoleMessage(
int embedded_worker_id,
const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
void OnPostMessage(int handle_id,
const base::string16& message,
const std::vector<int>& sent_message_port_ids);
void OnIncrementServiceWorkerRefCount(int handle_id);
void OnDecrementServiceWorkerRefCount(int handle_id);
void OnIncrementRegistrationRefCount(int registration_handle_id);
void OnDecrementRegistrationRefCount(int registration_handle_id);
void OnPostMessageToWorker(int handle_id,
const base::string16& message,
const std::vector<int>& sent_message_port_ids);
void OnServiceWorkerObjectDestroyed(int handle_id);
void OnTerminateWorker(int handle_id);
void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
void RegisterServiceWorkerRegistrationHandle(
scoped_ptr<ServiceWorkerRegistrationHandle> handle);
ServiceWorkerRegistrationHandle* FindRegistrationHandle(
int provider_id,
int64 registration_id);
void GetRegistrationObjectInfoAndVersionAttributes(
int provider_id,
ServiceWorkerRegistration* registration,
ServiceWorkerRegistrationObjectInfo* info,
ServiceWorkerVersionAttributes* attrs);
// Callbacks from ServiceWorkerContextCore
void RegistrationComplete(int thread_id,
int provider_id,
int request_id,
ServiceWorkerStatusCode status,
int64 registration_id);
void UnregistrationComplete(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
void GetRegistrationComplete(
int thread_id,
int provider_id,
int request_id,
ServiceWorkerStatusCode status,
const scoped_refptr<ServiceWorkerRegistration>& registration);
void SendRegistrationError(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
void SendUnregistrationError(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
void SendGetRegistrationError(int thread_id,
int request_id,
ServiceWorkerStatusCode status);
ServiceWorkerContextCore* GetContext();
int render_process_id_;
MessagePortMessageFilter* const message_port_message_filter_;
ResourceContext* resource_context_;
scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
ScopedVector<IPC::Message> pending_messages_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
};
} // namespace content
#endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
|