Rename isSystemLocationEnabled to isLocationEnabled, as per internal review (185995).
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_dispatcher_host.h
blob0cf478fdaaaf05eb783175c5d39760b1191fa78c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
8 #include <vector>
10 #include "base/id_map.h"
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "content/browser/service_worker/service_worker_registration_status.h"
14 #include "content/public/browser/browser_message_filter.h"
16 class GURL;
17 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
19 namespace content {
21 class MessagePortMessageFilter;
22 class ResourceContext;
23 class ServiceWorkerContextCore;
24 class ServiceWorkerContextWrapper;
25 class ServiceWorkerHandle;
26 class ServiceWorkerProviderHost;
27 class ServiceWorkerRegistration;
28 class ServiceWorkerRegistrationHandle;
29 struct ServiceWorkerRegistrationObjectInfo;
30 struct ServiceWorkerVersionAttributes;
32 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter {
33 public:
34 ServiceWorkerDispatcherHost(
35 int render_process_id,
36 MessagePortMessageFilter* message_port_message_filter,
37 ResourceContext* resource_context);
39 void Init(ServiceWorkerContextWrapper* context_wrapper);
41 // BrowserMessageFilter implementation
42 void OnFilterAdded(IPC::Sender* sender) override;
43 void OnFilterRemoved() override;
44 void OnDestruct() const override;
45 bool OnMessageReceived(const IPC::Message& message) override;
47 // IPC::Sender implementation
49 // Send() queues the message until the underlying sender is ready. This
50 // class assumes that Send() can only fail after that when the renderer
51 // process has terminated, at which point the whole instance will eventually
52 // be destroyed.
53 bool Send(IPC::Message* message) override;
55 // Returns the existing registration handle whose reference count is
56 // incremented or newly created one if it doesn't exist.
57 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
58 int provider_id,
59 ServiceWorkerRegistration* registration);
61 void RegisterServiceWorkerHandle(scoped_ptr<ServiceWorkerHandle> handle);
62 void RegisterServiceWorkerRegistrationHandle(
63 scoped_ptr<ServiceWorkerRegistrationHandle> handle);
65 MessagePortMessageFilter* message_port_message_filter() {
66 return message_port_message_filter_;
69 protected:
70 ~ServiceWorkerDispatcherHost() override;
72 private:
73 friend class BrowserThread;
74 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
75 friend class TestingServiceWorkerDispatcherHost;
77 // IPC Message handlers
78 void OnRegisterServiceWorker(int thread_id,
79 int request_id,
80 int provider_id,
81 const GURL& pattern,
82 const GURL& script_url);
83 void OnUnregisterServiceWorker(int thread_id,
84 int request_id,
85 int provider_id,
86 const GURL& pattern);
87 void OnGetRegistration(int thread_id,
88 int request_id,
89 int provider_id,
90 const GURL& document_url);
91 void OnProviderCreated(int provider_id, int render_frame_id);
92 void OnProviderDestroyed(int provider_id);
93 void OnSetHostedVersionId(int provider_id, int64 version_id);
94 void OnWorkerReadyForInspection(int embedded_worker_id);
95 void OnWorkerScriptLoaded(int embedded_worker_id, int thread_id);
96 void OnWorkerScriptLoadFailed(int embedded_worker_id);
97 void OnWorkerScriptEvaluated(int embedded_worker_id, bool success);
98 void OnWorkerStarted(int embedded_worker_id);
99 void OnWorkerStopped(int embedded_worker_id);
100 void OnPausedAfterDownload(int embedded_worker_id);
101 void OnReportException(int embedded_worker_id,
102 const base::string16& error_message,
103 int line_number,
104 int column_number,
105 const GURL& source_url);
106 void OnReportConsoleMessage(
107 int embedded_worker_id,
108 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params);
109 void OnPostMessage(int handle_id,
110 const base::string16& message,
111 const std::vector<int>& sent_message_port_ids);
112 void OnIncrementServiceWorkerRefCount(int handle_id);
113 void OnDecrementServiceWorkerRefCount(int handle_id);
114 void OnIncrementRegistrationRefCount(int registration_handle_id);
115 void OnDecrementRegistrationRefCount(int registration_handle_id);
116 void OnPostMessageToWorker(int handle_id,
117 const base::string16& message,
118 const std::vector<int>& sent_message_port_ids);
119 void OnServiceWorkerObjectDestroyed(int handle_id);
120 void OnTerminateWorker(int handle_id);
122 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
123 int provider_id,
124 int64 registration_id);
126 void GetRegistrationObjectInfoAndVersionAttributes(
127 int provider_id,
128 ServiceWorkerRegistration* registration,
129 ServiceWorkerRegistrationObjectInfo* info,
130 ServiceWorkerVersionAttributes* attrs);
132 // Callbacks from ServiceWorkerContextCore
133 void RegistrationComplete(int thread_id,
134 int provider_id,
135 int request_id,
136 ServiceWorkerStatusCode status,
137 int64 registration_id);
139 void UnregistrationComplete(int thread_id,
140 int request_id,
141 ServiceWorkerStatusCode status);
143 void GetRegistrationComplete(
144 int thread_id,
145 int provider_id,
146 int request_id,
147 ServiceWorkerStatusCode status,
148 const scoped_refptr<ServiceWorkerRegistration>& registration);
150 void SendRegistrationError(int thread_id,
151 int request_id,
152 ServiceWorkerStatusCode status);
154 void SendUnregistrationError(int thread_id,
155 int request_id,
156 ServiceWorkerStatusCode status);
158 void SendGetRegistrationError(int thread_id,
159 int request_id,
160 ServiceWorkerStatusCode status);
162 ServiceWorkerContextCore* GetContext();
164 int render_process_id_;
165 MessagePortMessageFilter* const message_port_message_filter_;
166 ResourceContext* resource_context_;
167 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_;
169 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
170 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer> registration_handles_;
172 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
173 ScopedVector<IPC::Message> pending_messages_;
175 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
178 } // namespace content
180 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_