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

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

Issue 2396273002: ServiceWorker: Mojofication of ServiceWorkerDispatcherHost (Closed)
Patch Set: Moved ptr of dispatcher_host to SWNetworkProvider Created 4 years, 2 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/id_map.h" 13 #include "base/id_map.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "content/browser/service_worker/service_worker_registration_status.h" 17 #include "content/browser/service_worker/service_worker_registration_status.h"
18 #include "content/common/service_worker/service_worker.mojom.h"
18 #include "content/common/service_worker/service_worker_types.h" 19 #include "content/common/service_worker/service_worker_types.h"
19 #include "content/public/browser/browser_message_filter.h" 20 #include "content/public/browser/browser_message_filter.h"
21 #include "mojo/public/cpp/bindings/associated_binding_set.h"
20 22
21 class GURL; 23 class GURL;
22 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params; 24 struct EmbeddedWorkerHostMsg_ReportConsoleMessage_Params;
23 25
24 namespace url { 26 namespace url {
25 class Origin; 27 class Origin;
26 } 28 }
27 29
28 namespace content { 30 namespace content {
29 31
30 class MessagePortMessageFilter; 32 class MessagePortMessageFilter;
31 class ResourceContext; 33 class ResourceContext;
32 class ServiceWorkerContextCore; 34 class ServiceWorkerContextCore;
33 class ServiceWorkerContextWrapper; 35 class ServiceWorkerContextWrapper;
34 class ServiceWorkerHandle; 36 class ServiceWorkerHandle;
35 class ServiceWorkerProviderHost; 37 class ServiceWorkerProviderHost;
36 class ServiceWorkerRegistration; 38 class ServiceWorkerRegistration;
37 class ServiceWorkerRegistrationHandle; 39 class ServiceWorkerRegistrationHandle;
38 class ServiceWorkerVersion; 40 class ServiceWorkerVersion;
39 struct ServiceWorkerObjectInfo; 41 struct ServiceWorkerObjectInfo;
40 struct ServiceWorkerRegistrationInfo; 42 struct ServiceWorkerRegistrationInfo;
41 struct ServiceWorkerRegistrationObjectInfo; 43 struct ServiceWorkerRegistrationObjectInfo;
42 struct ServiceWorkerVersionAttributes; 44 struct ServiceWorkerVersionAttributes;
43 45
44 class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { 46 class CONTENT_EXPORT ServiceWorkerDispatcherHost
47 : public mojom::ServiceWorkerDispatcherHost,
horo 2016/10/07 07:39:29 I think you can use BrowserAssociatedInterface.
shimazu 2016/10/14 08:15:03 BrowserAssociatedInterface assume that the object
48 public BrowserMessageFilter {
45 public: 49 public:
46 ServiceWorkerDispatcherHost( 50 ServiceWorkerDispatcherHost(
47 int render_process_id, 51 int render_process_id,
48 MessagePortMessageFilter* message_port_message_filter, 52 MessagePortMessageFilter* message_port_message_filter,
49 ResourceContext* resource_context); 53 ResourceContext* resource_context);
50 54
51 void Init(ServiceWorkerContextWrapper* context_wrapper); 55 void Init(ServiceWorkerContextWrapper* context_wrapper);
52 56
53 // BrowserMessageFilter implementation 57 // BrowserMessageFilter implementation
54 void OnFilterAdded(IPC::Channel* channel) override; 58 void OnFilterAdded(IPC::Channel* channel) override;
55 void OnFilterRemoved() override; 59 void OnFilterRemoved() override;
56 void OnDestruct() const override; 60 void OnDestruct() const override;
57 bool OnMessageReceived(const IPC::Message& message) override; 61 bool OnMessageReceived(const IPC::Message& message) override;
58 62
63 // Called when mojom::ServiceWorkerDispatcherHostPtr is created on the
64 // renderer-side.
65 void AddMojoBinding(mojo::ScopedInterfaceEndpointHandle handle);
horo 2016/10/07 07:39:29 Move to private.
shimazu 2016/10/14 08:15:03 Done.
66
59 // IPC::Sender implementation 67 // IPC::Sender implementation
60 68
61 // Send() queues the message until the underlying sender is ready. This 69 // Send() queues the message until the underlying sender is ready. This
62 // class assumes that Send() can only fail after that when the renderer 70 // class assumes that Send() can only fail after that when the renderer
63 // process has terminated, at which point the whole instance will eventually 71 // process has terminated, at which point the whole instance will eventually
64 // be destroyed. 72 // be destroyed.
65 bool Send(IPC::Message* message) override; 73 bool Send(IPC::Message* message) override;
66 74
67 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle); 75 void RegisterServiceWorkerHandle(std::unique_ptr<ServiceWorkerHandle> handle);
68 void RegisterServiceWorkerRegistrationHandle( 76 void RegisterServiceWorkerRegistrationHandle(
69 std::unique_ptr<ServiceWorkerRegistrationHandle> handle); 77 std::unique_ptr<ServiceWorkerRegistrationHandle> handle);
70 78
71 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id, 79 ServiceWorkerHandle* FindServiceWorkerHandle(int provider_id,
72 int64_t version_id); 80 int64_t version_id);
73 81
74 // Returns the existing registration handle whose reference count is 82 // Returns the existing registration handle whose reference count is
75 // incremented or a newly created one if it doesn't exist. 83 // incremented or a newly created one if it doesn't exist.
76 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle( 84 ServiceWorkerRegistrationHandle* GetOrCreateRegistrationHandle(
77 base::WeakPtr<ServiceWorkerProviderHost> provider_host, 85 base::WeakPtr<ServiceWorkerProviderHost> provider_host,
78 ServiceWorkerRegistration* registration); 86 ServiceWorkerRegistration* registration);
79 87
80 MessagePortMessageFilter* message_port_message_filter() { 88 MessagePortMessageFilter* message_port_message_filter() {
81 return message_port_message_filter_; 89 return message_port_message_filter_;
82 } 90 }
83 91
92 base::WeakPtr<ServiceWorkerDispatcherHost> GetWeakPtr() {
93 return weak_factory_.GetWeakPtr();
94 }
95
84 protected: 96 protected:
85 ~ServiceWorkerDispatcherHost() override; 97 ~ServiceWorkerDispatcherHost() override;
86 98
87 private: 99 private:
88 friend class BrowserThread; 100 friend class BrowserThread;
89 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>; 101 friend class base::DeleteHelper<ServiceWorkerDispatcherHost>;
90 friend class ServiceWorkerDispatcherHostTest; 102 friend class ServiceWorkerDispatcherHostTest;
91 friend class TestingServiceWorkerDispatcherHost; 103 friend class TestingServiceWorkerDispatcherHost;
92 104
93 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>; 105 using StatusCallback = base::Callback<void(ServiceWorkerStatusCode status)>;
94 106
107 // mojom::ServiceWorkerDispatcherHost implementation
108 void OnProviderCreated(int provider_id,
109 int route_id,
110 ServiceWorkerProviderType provider_type,
111 bool is_parent_frame_secure) override;
112
95 // IPC Message handlers 113 // IPC Message handlers
96 void OnRegisterServiceWorker(int thread_id, 114 void OnRegisterServiceWorker(int thread_id,
97 int request_id, 115 int request_id,
98 int provider_id, 116 int provider_id,
99 const GURL& pattern, 117 const GURL& pattern,
100 const GURL& script_url); 118 const GURL& script_url);
101 void OnUpdateServiceWorker(int thread_id, 119 void OnUpdateServiceWorker(int thread_id,
102 int request_id, 120 int request_id,
103 int provider_id, 121 int provider_id,
104 int64_t registration_id); 122 int64_t registration_id);
105 void OnUnregisterServiceWorker(int thread_id, 123 void OnUnregisterServiceWorker(int thread_id,
106 int request_id, 124 int request_id,
107 int provider_id, 125 int provider_id,
108 int64_t registration_id); 126 int64_t registration_id);
109 void OnGetRegistration(int thread_id, 127 void OnGetRegistration(int thread_id,
110 int request_id, 128 int request_id,
111 int provider_id, 129 int provider_id,
112 const GURL& document_url); 130 const GURL& document_url);
113 void OnGetRegistrations(int thread_id, int request_id, int provider_id); 131 void OnGetRegistrations(int thread_id, int request_id, int provider_id);
114 void OnGetRegistrationForReady(int thread_id, 132 void OnGetRegistrationForReady(int thread_id,
115 int request_id, 133 int request_id,
116 int provider_id); 134 int provider_id);
117 void OnProviderCreated(int provider_id,
118 int route_id,
119 ServiceWorkerProviderType provider_type,
120 bool is_parent_frame_secure);
121 void OnProviderDestroyed(int provider_id); 135 void OnProviderDestroyed(int provider_id);
122 void OnSetHostedVersionId(int provider_id, 136 void OnSetHostedVersionId(int provider_id,
123 int64_t version_id, 137 int64_t version_id,
124 int embedded_worker_id); 138 int embedded_worker_id);
125 void OnWorkerReadyForInspection(int embedded_worker_id); 139 void OnWorkerReadyForInspection(int embedded_worker_id);
126 void OnWorkerScriptLoaded(int embedded_worker_id); 140 void OnWorkerScriptLoaded(int embedded_worker_id);
127 void OnWorkerThreadStarted(int embedded_worker_id, 141 void OnWorkerThreadStarted(int embedded_worker_id,
128 int thread_id, 142 int thread_id,
129 int provider_id); 143 int provider_id);
130 void OnWorkerScriptLoadFailed(int embedded_worker_id); 144 void OnWorkerScriptLoadFailed(int embedded_worker_id);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 250
237 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_; 251 IDMap<ServiceWorkerHandle, IDMapOwnPointer> handles_;
238 252
239 using RegistrationHandleMap = 253 using RegistrationHandleMap =
240 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>; 254 IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>;
241 RegistrationHandleMap registration_handles_; 255 RegistrationHandleMap registration_handles_;
242 256
243 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL. 257 bool channel_ready_; // True after BrowserMessageFilter::sender_ != NULL.
244 std::vector<std::unique_ptr<IPC::Message>> pending_messages_; 258 std::vector<std::unique_ptr<IPC::Message>> pending_messages_;
245 259
260 mojo::AssociatedBindingSet<mojom::ServiceWorkerDispatcherHost> bindings_;
261
262 base::WeakPtrFactory<ServiceWorkerDispatcherHost> weak_factory_;
263
246 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost); 264 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDispatcherHost);
247 }; 265 };
248 266
249 } // namespace content 267 } // namespace content
250 268
251 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_ 269 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698