OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 5 #ifndef CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 6 #define CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/id_map.h" | 17 #include "base/id_map.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
22 #include "content/child/webmessageportchannel_impl.h" | 22 #include "content/child/webmessageportchannel_impl.h" |
23 #include "content/common/service_worker/embedded_worker.mojom.h" | 23 #include "content/common/service_worker/embedded_worker.mojom.h" |
24 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 24 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
25 #include "content/common/service_worker/service_worker_provider.mojom.h" | |
26 #include "content/common/service_worker/service_worker_status_code.h" | 25 #include "content/common/service_worker/service_worker_status_code.h" |
27 #include "content/common/service_worker/service_worker_types.h" | 26 #include "content/common/service_worker/service_worker_types.h" |
28 #include "ipc/ipc_listener.h" | 27 #include "ipc/ipc_listener.h" |
29 #include "mojo/public/cpp/bindings/binding.h" | 28 #include "mojo/public/cpp/bindings/binding.h" |
30 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 29 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
31 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.
h" | 30 #include "third_party/WebKit/public/platform/modules/payments/payment_app.mojom.
h" |
32 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 31 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
33 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke
r_event_status.mojom.h" | 32 #include "third_party/WebKit/public/platform/modules/serviceworker/service_worke
r_event_status.mojom.h" |
34 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" | 33 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
35 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 34 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
(...skipping 15 matching lines...) Expand all Loading... |
51 | 50 |
52 namespace IPC { | 51 namespace IPC { |
53 class Message; | 52 class Message; |
54 } | 53 } |
55 | 54 |
56 namespace content { | 55 namespace content { |
57 | 56 |
58 struct PlatformNotificationData; | 57 struct PlatformNotificationData; |
59 struct PushEventPayload; | 58 struct PushEventPayload; |
60 struct ServiceWorkerClientInfo; | 59 struct ServiceWorkerClientInfo; |
61 class ServiceWorkerNetworkProvider; | |
62 class ServiceWorkerProviderContext; | 60 class ServiceWorkerProviderContext; |
| 61 class ServiceWorkerContextClient; |
63 class ThreadSafeSender; | 62 class ThreadSafeSender; |
64 class EmbeddedWorkerInstanceClientImpl; | 63 class EmbeddedWorkerInstanceClientImpl; |
65 class WebWorkerFetchContext; | 64 class WebWorkerFetchContext; |
66 | 65 |
67 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. | 66 // This class provides access to/from an ServiceWorker's WorkerGlobalScope. |
68 // Unless otherwise noted, all methods are called on the worker thread. | 67 // Unless otherwise noted, all methods are called on the worker thread. |
69 class ServiceWorkerContextClient : public blink::WebServiceWorkerContextClient, | 68 class ServiceWorkerContextClient : public blink::WebServiceWorkerContextClient, |
70 public mojom::ServiceWorkerEventDispatcher { | 69 public mojom::ServiceWorkerEventDispatcher { |
71 public: | 70 public: |
72 using SyncCallback = | 71 using SyncCallback = |
73 base::OnceCallback<void(ServiceWorkerStatusCode, | 72 base::OnceCallback<void(ServiceWorkerStatusCode, |
74 base::Time /* dispatch_event_time */)>; | 73 base::Time /* dispatch_event_time */)>; |
75 using FetchCallback = | 74 using FetchCallback = |
76 base::OnceCallback<void(ServiceWorkerStatusCode, | 75 base::OnceCallback<void(ServiceWorkerStatusCode, |
77 base::Time /* dispatch_event_time */)>; | 76 base::Time /* dispatch_event_time */)>; |
78 | 77 |
79 // Returns a thread-specific client instance. This does NOT create a | 78 // Returns a thread-specific client instance. This does NOT create a |
80 // new instance. | 79 // new instance. |
81 static ServiceWorkerContextClient* ThreadSpecificInstance(); | 80 static ServiceWorkerContextClient* ThreadSpecificInstance(); |
82 | 81 |
83 // Called on the main thread. | 82 // Called on the main thread. |
84 ServiceWorkerContextClient( | 83 ServiceWorkerContextClient( |
85 int embedded_worker_id, | 84 int embedded_worker_id, |
86 int64_t service_worker_version_id, | 85 int64_t service_worker_version_id, |
87 const GURL& service_worker_scope, | 86 const GURL& service_worker_scope, |
88 const GURL& script_url, | 87 const GURL& script_url, |
89 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | 88 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, |
90 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, | 89 mojom::EmbeddedWorkerInstanceHostAssociatedPtrInfo instance_host, |
91 mojom::ServiceWorkerProviderInfoForStartWorkerPtr provider_info, | |
92 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client); | 90 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client); |
93 ~ServiceWorkerContextClient() override; | 91 ~ServiceWorkerContextClient() override; |
94 | 92 |
95 void OnMessageReceived(int thread_id, | 93 void OnMessageReceived(int thread_id, |
96 int embedded_worker_id, | 94 int embedded_worker_id, |
97 const IPC::Message& message); | 95 const IPC::Message& message); |
98 | 96 |
99 // WebServiceWorkerContextClient overrides. | 97 // WebServiceWorkerContextClient overrides. |
100 blink::WebURL Scope() const override; | 98 blink::WebURL Scope() const override; |
101 void GetClient( | 99 void GetClient( |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 void OnNavigationPreloadError( | 335 void OnNavigationPreloadError( |
338 int fetch_event_id, | 336 int fetch_event_id, |
339 std::unique_ptr<blink::WebServiceWorkerError> error); | 337 std::unique_ptr<blink::WebServiceWorkerError> error); |
340 | 338 |
341 base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr(); | 339 base::WeakPtr<ServiceWorkerContextClient> GetWeakPtr(); |
342 | 340 |
343 const int embedded_worker_id_; | 341 const int embedded_worker_id_; |
344 const int64_t service_worker_version_id_; | 342 const int64_t service_worker_version_id_; |
345 const GURL service_worker_scope_; | 343 const GURL service_worker_scope_; |
346 const GURL script_url_; | 344 const GURL script_url_; |
| 345 int network_provider_id_ = kInvalidServiceWorkerProviderId; |
347 scoped_refptr<ThreadSafeSender> sender_; | 346 scoped_refptr<ThreadSafeSender> sender_; |
348 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 347 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
349 scoped_refptr<base::TaskRunner> worker_task_runner_; | 348 scoped_refptr<base::TaskRunner> worker_task_runner_; |
350 | 349 |
351 scoped_refptr<ServiceWorkerProviderContext> provider_context_; | 350 scoped_refptr<ServiceWorkerProviderContext> provider_context_; |
352 | 351 |
353 // Not owned; this object is destroyed when proxy_ becomes invalid. | 352 // Not owned; this object is destroyed when proxy_ becomes invalid. |
354 blink::WebServiceWorkerContextProxy* proxy_; | 353 blink::WebServiceWorkerContextProxy* proxy_; |
355 | 354 |
356 // This is bound on the worker thread. | 355 // This is bound on the worker thread. |
357 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; | 356 mojom::ServiceWorkerEventDispatcherRequest pending_dispatcher_request_; |
358 | 357 |
359 // This is bound on the main thread. | 358 // This is bound on the main thread. |
360 scoped_refptr<mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr> | 359 scoped_refptr<mojom::ThreadSafeEmbeddedWorkerInstanceHostAssociatedPtr> |
361 instance_host_; | 360 instance_host_; |
362 | 361 |
363 // This is passed to ServiceWorkerNetworkProvider when | |
364 // createServiceWorkerNetworkProvider is called. | |
365 std::unique_ptr<ServiceWorkerNetworkProvider> pending_network_provider_; | |
366 | |
367 // Renderer-side object corresponding to WebEmbeddedWorkerInstance. | 362 // Renderer-side object corresponding to WebEmbeddedWorkerInstance. |
368 // This is valid from the ctor to workerContextDestroyed. | 363 // This is valid from the ctor to workerContextDestroyed. |
369 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; | 364 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client_; |
370 | 365 |
371 // Initialized on the worker thread in workerContextStarted and | 366 // Initialized on the worker thread in workerContextStarted and |
372 // destructed on the worker thread in willDestroyWorkerContext. | 367 // destructed on the worker thread in willDestroyWorkerContext. |
373 std::unique_ptr<WorkerContextData> context_; | 368 std::unique_ptr<WorkerContextData> context_; |
374 | 369 |
375 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); | 370 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerContextClient); |
376 }; | 371 }; |
377 | 372 |
378 } // namespace content | 373 } // namespace content |
379 | 374 |
380 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ | 375 #endif // CONTENT_RENDERER_SERVICE_WORKER_SERVICE_WORKER_CONTEXT_CLIENT_H_ |
OLD | NEW |