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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
| 13 #include "base/callback.h" |
13 #include "base/id_map.h" | 14 #include "base/id_map.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "content/browser/service_worker/service_worker_registration_status.h" | 18 #include "content/browser/service_worker/service_worker_registration_status.h" |
18 #include "content/common/service_worker/service_worker.mojom.h" | 19 #include "content/common/service_worker/service_worker.mojom.h" |
19 #include "content/common/service_worker/service_worker_types.h" | 20 #include "content/common/service_worker/service_worker_types.h" |
20 #include "content/public/browser/browser_message_filter.h" | 21 #include "content/public/browser/browser_message_filter.h" |
21 #include "mojo/public/cpp/bindings/associated_binding_set.h" | 22 #include "mojo/public/cpp/bindings/associated_binding_set.h" |
| 23 #include "mojo/public/cpp/bindings/interface_request.h" |
22 | 24 |
23 class GURL; | 25 class GURL; |
24 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params; | 26 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params; |
25 | 27 |
26 namespace url { | 28 namespace url { |
27 class Origin; | 29 class Origin; |
28 } | 30 } // namespace url |
29 | 31 |
30 namespace content { | 32 namespace content { |
31 | 33 |
| 34 namespace mojom { |
| 35 class URLLoaderFactory; |
| 36 } // namespace mojom |
| 37 |
32 class MessagePortMessageFilter; | 38 class MessagePortMessageFilter; |
33 class ResourceContext; | 39 class ResourceContext; |
34 class ServiceWorkerContextCore; | 40 class ServiceWorkerContextCore; |
35 class ServiceWorkerContextWrapper; | 41 class ServiceWorkerContextWrapper; |
36 class ServiceWorkerHandle; | 42 class ServiceWorkerHandle; |
37 class ServiceWorkerProviderHost; | 43 class ServiceWorkerProviderHost; |
38 class ServiceWorkerRegistration; | 44 class ServiceWorkerRegistration; |
39 class ServiceWorkerRegistrationHandle; | 45 class ServiceWorkerRegistrationHandle; |
40 class ServiceWorkerVersion; | 46 class ServiceWorkerVersion; |
41 struct ServiceWorkerObjectInfo; | 47 struct ServiceWorkerObjectInfo; |
42 struct ServiceWorkerRegistrationInfo; | 48 struct ServiceWorkerRegistrationInfo; |
43 struct ServiceWorkerRegistrationObjectInfo; | 49 struct ServiceWorkerRegistrationObjectInfo; |
44 struct ServiceWorkerVersionAttributes; | 50 struct ServiceWorkerVersionAttributes; |
45 | 51 |
46 class CONTENT_EXPORT ServiceWorkerDispatcherHost | 52 class CONTENT_EXPORT ServiceWorkerDispatcherHost |
47 : public mojom::ServiceWorkerDispatcherHost, | 53 : public mojom::ServiceWorkerDispatcherHost, |
48 public BrowserMessageFilter { | 54 public BrowserMessageFilter { |
49 public: | 55 public: |
| 56 using URLLoaderFactoryCallback = |
| 57 base::Callback<bool(mojo::InterfaceRequest<mojom::URLLoaderFactory>)>; |
| 58 |
50 ServiceWorkerDispatcherHost( | 59 ServiceWorkerDispatcherHost( |
51 int render_process_id, | 60 int render_process_id, |
52 MessagePortMessageFilter* message_port_message_filter, | 61 MessagePortMessageFilter* message_port_message_filter, |
53 ResourceContext* resource_context); | 62 ResourceContext* resource_context, |
| 63 const URLLoaderFactoryCallback& url_loader_factory_callback); |
54 | 64 |
55 void Init(ServiceWorkerContextWrapper* context_wrapper); | 65 void Init(ServiceWorkerContextWrapper* context_wrapper); |
56 | 66 |
57 // BrowserMessageFilter implementation | 67 // BrowserMessageFilter implementation |
58 void OnFilterAdded(IPC::Channel* channel) override; | 68 void OnFilterAdded(IPC::Channel* channel) override; |
59 void OnFilterRemoved() override; | 69 void OnFilterRemoved() override; |
60 void OnDestruct() const override; | 70 void OnDestruct() const override; |
61 bool OnMessageReceived(const IPC::Message& message) override; | 71 bool OnMessageReceived(const IPC::Message& message) override; |
62 | 72 |
63 // IPC::Sender implementation | 73 // IPC::Sender implementation |
(...skipping 14 matching lines...) Expand all Loading... |
78 // Returns the existing registration handle whose reference count is | 88 // Returns the existing registration handle whose reference count is |
79 // incremented or a newly created one if it doesn't exist. | 89 // incremented or a newly created one if it doesn't exist. |
80 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( | 90 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( |
81 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 91 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
82 ServiceWorkerRegistration* registration); | 92 ServiceWorkerRegistration* registration); |
83 | 93 |
84 MessagePortMessageFilter* message_port_message_filter() { | 94 MessagePortMessageFilter* message_port_message_filter() { |
85 return message_port_message_filter_; | 95 return message_port_message_filter_; |
86 } | 96 } |
87 | 97 |
| 98 URLLoaderFactoryCallback url_loader_factory_callback() const { |
| 99 return url_loader_factory_callback_; |
| 100 } |
| 101 |
88 protected: | 102 protected: |
89 ~ServiceWorkerDispatcherHost() override; | 103 ~ServiceWorkerDispatcherHost() override; |
90 | 104 |
91 private: | 105 private: |
92 friend class BrowserThread; | 106 friend class BrowserThread; |
93 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; | 107 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; |
94 friend class ServiceWorkerDispatcherHostTest; | 108 friend class ServiceWorkerDispatcherHostTest; |
95 friend class TestingServiceWorkerDispatcherHost; | 109 friend class TestingServiceWorkerDispatcherHost; |
96 | 110 |
97 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; | 111 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 int thread_id, | 249 int thread_id, |
236 int request_id, | 250 int request_id, |
237 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 251 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
238 ServiceWorkerRegistration* registration); | 252 ServiceWorkerRegistration* registration); |
239 | 253 |
240 ServiceWorkerContextCore* GetContext(); | 254 ServiceWorkerContextCore* GetContext(); |
241 | 255 |
242 const int render_process_id_; | 256 const int render_process_id_; |
243 MessagePortMessageFilter* const message_port_message_filter_; | 257 MessagePortMessageFilter* const message_port_message_filter_; |
244 ResourceContext* resource_context_; | 258 ResourceContext* resource_context_; |
| 259 const URLLoaderFactoryCallback url_loader_factory_callback_; |
245 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; | 260 scoped_refptr<ServiceWorkerContextWrapper> context_wrapper_; |
246 | 261 |
247 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_; | 262 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_; |
248 | 263 |
249 using RegistrationHandleMap = | 264 using RegistrationHandleMap = |
250 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>; | 265 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>; |
251 RegistrationHandleMap registration_handles_; | 266 RegistrationHandleMap registration_handles_; |
252 | 267 |
253 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL. | 268 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL. |
254 std::vector<std::unique_ptr<IPC::Message>> pending_messages_; | 269 std::vector<std::unique_ptr<IPC::Message>> pending_messages_; |
255 | 270 |
256 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; | 271 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; |
257 | 272 |
258 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; | 273 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; |
259 | 274 |
260 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); | 275 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); |
261 }; | 276 }; |
262 | 277 |
263 } // namespace content | 278 } // namespace content |
264 | 279 |
265 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ | 280 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ |
OLD | NEW |