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

Side by Side Diff: content/browser/service_worker/service_worker_dispatcher_host.h

Issue 2779763004: Create ServiceWorkerProviderHost before starting worker (Closed)
Patch Set: Pass the param of BindWithProviderInfo by value instead of pointer Created 3 years, 6 months 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 unified diff | Download patch
OLDNEW
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>
(...skipping 26 matching lines...) Expand all
37 class ServiceWorkerProviderHost; 37 class ServiceWorkerProviderHost;
38 class ServiceWorkerRegistration; 38 class ServiceWorkerRegistration;
39 class ServiceWorkerRegistrationHandle; 39 class ServiceWorkerRegistrationHandle;
40 class ServiceWorkerVersion; 40 class ServiceWorkerVersion;
41 struct ServiceWorkerObjectInfo; 41 struct ServiceWorkerObjectInfo;
42 struct ServiceWorkerRegistrationObjectInfo; 42 struct ServiceWorkerRegistrationObjectInfo;
43 struct ServiceWorkerVersionAttributes; 43 struct ServiceWorkerVersionAttributes;
44 44
45 // This class is bound with mojom::ServiceWorkerDispatcherHost. All 45 // This class is bound with mojom::ServiceWorkerDispatcherHost. All
46 // InterfacePtrs on the same render process are bound to the same 46 // InterfacePtrs on the same render process are bound to the same
47 // content::ServiceWorkerDispatcherHost. 47 // content::ServiceWorkerDispatcherHost. This can be overridden only for
48 // testing.
48 class CONTENT_EXPORT ServiceWorkerDispatcherHost 49 class CONTENT_EXPORT ServiceWorkerDispatcherHost
49 : public mojom::ServiceWorkerDispatcherHost, 50 : public mojom::ServiceWorkerDispatcherHost,
50 public BrowserMessageFilter { 51 public BrowserMessageFilter {
51 public: 52 public:
52 ServiceWorkerDispatcherHost( 53 ServiceWorkerDispatcherHost(
53 int render_process_id, 54 int render_process_id,
54 ResourceContext* resource_context); 55 ResourceContext* resource_context);
55 56
56 void Init(ServiceWorkerContextWrapper* context_wrapper); 57 void Init(ServiceWorkerContextWrapper* context_wrapper);
57 58
58 // BrowserMessageFilter implementation 59 // BrowserMessageFilter implementation
59 void OnFilterAdded(IPC::Channel* channel) override; 60 void OnFilterAdded(IPC::Channel* channel) override;
60 void OnFilterRemoved() override; 61 void OnFilterRemoved() override;
61 void OnDestruct() const override; 62 void OnDestruct() const override;
62 bool OnMessageReceived(const IPC::Message& message) override; 63 bool OnMessageReceived(const IPC::Message& message) override;
63 64
64 // IPC::Sender implementation 65 // IPC::Sender implementation
65 66
66 // Send() queues the message until the underlying sender is ready. This 67 // Send() queues the message until the underlying sender is ready. This
67 // class assumes that Send() can only fail after that when the renderer 68 // class assumes that Send() can only fail after that when the renderer
68 // process has terminated, at which point the whole instance will eventually 69 // process has terminated, at which point the whole instance will eventually
69 // be destroyed. 70 // be destroyed.
70 bool Send(IPC::Message* message) override; 71 bool Send(IPC::Message* message) override;
71 72
72 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle); 73 // Virtual for testing.
73 void RegisterServiceWorkerRegistrationHandle( 74 virtual void RegisterServiceWorkerHandle(
75 std::unique_ptr<ServiceWorkerHandle> handle);
76 // Virtual for testing.
77 virtual void RegisterServiceWorkerRegistrationHandle(
74 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); 78 std::unique_ptr<ServiceWorkerRegistrationHandle> handle);
75 79
76 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, 80 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id,
77 int64_t version_id); 81 int64_t version_id);
78 82
83 // Gets or creates the registration and version handles appropriate for
84 // representing |registration| inside of |provider_host|. Sets |out_info| and
85 // |out_attrs| accordingly for these handles.
86 void GetRegistrationObjectInfoAndVersionAttributes(
87 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
88 ServiceWorkerRegistration* registration,
89 ServiceWorkerRegistrationObjectInfo* out_info,
90 ServiceWorkerVersionAttributes* out_attrs);
91
79 // Returns the existing registration handle whose reference count is 92 // Returns the existing registration handle whose reference count is
80 // incremented or a newly created one if it doesn't exist. 93 // incremented or a newly created one if it doesn't exist.
81 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( 94 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
82 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 95 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
83 ServiceWorkerRegistration* registration); 96 ServiceWorkerRegistration* registration);
84 97
85 protected: 98 protected:
86 ~ServiceWorkerDispatcherHost() override; 99 ~ServiceWorkerDispatcherHost() override;
87 100
88 private: 101 private:
89 friend class BrowserThread; 102 friend class BrowserThread;
90 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; 103 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
91 friend class ServiceWorkerDispatcherHostTest; 104 friend class ServiceWorkerDispatcherHostTest;
92 friend class TestingServiceWorkerDispatcherHost; 105 friend class TestingServiceWorkerDispatcherHost;
93 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, 106 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest,
94 ProviderCreatedAndDestroyed); 107 ProviderCreatedAndDestroyed);
95 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest, 108 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDispatcherHostTest,
96 CleanupOnRendererCrash); 109 CleanupOnRendererCrash);
110 FRIEND_TEST_ALL_PREFIXES(BackgroundSyncManagerTest,
111 RegisterWithoutLiveSWRegistration);
97 112
98 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; 113 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>;
99 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL }; 114 enum class ProviderStatus { OK, NO_CONTEXT, DEAD_HOST, NO_HOST, NO_URL };
100 115
101 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the 116 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the
102 // renderer-side. 117 // renderer-side.
103 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle); 118 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle);
104 119
105 // mojom::ServiceWorkerDispatcherHost implementation 120 // mojom::ServiceWorkerDispatcherHost implementation
106 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override; 121 void OnProviderCreated(ServiceWorkerProviderHostInfo info) override;
107 void OnSetHostedVersionId(int provider_id,
108 int64_t version_id,
109 int embedded_worker_id) override;
110 122
111 // IPC Message handlers 123 // IPC Message handlers
112 void OnRegisterServiceWorker(int thread_id, 124 void OnRegisterServiceWorker(int thread_id,
113 int request_id, 125 int request_id,
114 int provider_id, 126 int provider_id,
115 const GURL& pattern, 127 const GURL& pattern,
116 const GURL& script_url); 128 const GURL& script_url);
117 void OnUpdateServiceWorker(int thread_id, 129 void OnUpdateServiceWorker(int thread_id,
118 int request_id, 130 int request_id,
119 int provider_id, 131 int provider_id,
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 const SourceInfo& source_info, 200 const SourceInfo& source_info,
189 const StatusCallback& callback, 201 const StatusCallback& callback,
190 ServiceWorkerStatusCode status); 202 ServiceWorkerStatusCode status);
191 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info); 203 void ReleaseSourceInfo(const ServiceWorkerClientInfo& source_info);
192 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info); 204 void ReleaseSourceInfo(const ServiceWorkerObjectInfo& source_info);
193 205
194 ServiceWorkerRegistrationHandle* FindRegistrationHandle( 206 ServiceWorkerRegistrationHandle* FindRegistrationHandle(
195 int provider_id, 207 int provider_id,
196 int64_t registration_handle_id); 208 int64_t registration_handle_id);
197 209
198 void GetRegistrationObjectInfoAndVersionAttributes(
199 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
200 ServiceWorkerRegistration* registration,
201 ServiceWorkerRegistrationObjectInfo* info,
202 ServiceWorkerVersionAttributes* attrs);
203
204 // Callbacks from ServiceWorkerContextCore 210 // Callbacks from ServiceWorkerContextCore
205 void RegistrationComplete(int thread_id, 211 void RegistrationComplete(int thread_id,
206 int provider_id, 212 int provider_id,
207 int request_id, 213 int request_id,
208 ServiceWorkerStatusCode status, 214 ServiceWorkerStatusCode status,
209 const std::string& status_message, 215 const std::string& status_message,
210 int64_t registration_id); 216 int64_t registration_id);
211 void UpdateComplete(int thread_id, 217 void UpdateComplete(int thread_id,
212 int provider_id, 218 int provider_id,
213 int request_id, 219 int request_id,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_; 277 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_;
272 278
273 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_; 279 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_;
274 280
275 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); 281 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
276 }; 282 };
277 283
278 } // namespace content 284 } // namespace content
279 285
280 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ 286 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698