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 #include "content/browser/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
6 | 6 |
7 #include "content/browser/shared_worker/shared_worker_host.h" | 7 #include "content/browser/shared_worker/shared_worker_host.h" |
8 #include "content/browser/shared_worker/shared_worker_instance.h" | 8 #include "content/browser/shared_worker/shared_worker_instance.h" |
9 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 9 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
10 #include "content/browser/worker_host/worker_document_set.h" | 10 #include "content/browser/worker_host/worker_document_set.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
97 WorkerServiceObserver, observers_, | 97 WorkerServiceObserver, observers_, |
98 WorkerCreated(params.url, | 98 WorkerCreated(params.url, |
99 params.name, | 99 params.name, |
100 filter->render_process_id(), | 100 filter->render_process_id(), |
101 worker_route_id)); | 101 worker_route_id)); |
102 } | 102 } |
103 | 103 |
104 void SharedWorkerServiceImpl::ForwardToWorker( | 104 void SharedWorkerServiceImpl::ForwardToWorker( |
105 const IPC::Message& message, | 105 const IPC::Message& message, |
106 SharedWorkerMessageFilter* filter) { | 106 SharedWorkerMessageFilter* filter) { |
107 // TODO(horo): implement this. | 107 for (ScopedVector<SharedWorkerHost>::const_iterator iter = |
108 NOTIMPLEMENTED(); | 108 worker_hosts_.begin(); |
109 iter != worker_hosts_.end(); | |
110 ++iter) { | |
111 if ((*iter)->FilterMessage(message, filter)) | |
112 return; | |
113 } | |
109 } | 114 } |
110 | 115 |
111 void SharedWorkerServiceImpl::DocumentDetached( | 116 void SharedWorkerServiceImpl::DocumentDetached( |
112 unsigned long long document_id, | 117 unsigned long long document_id, |
113 SharedWorkerMessageFilter* filter) { | 118 SharedWorkerMessageFilter* filter) { |
114 // TODO(horo): implement this. | 119 for (ScopedVector<SharedWorkerHost>::const_iterator iter = |
115 NOTIMPLEMENTED(); | 120 worker_hosts_.begin(); |
121 iter != worker_hosts_.end(); | |
122 ++iter) { | |
123 (*iter)->DocumentDetached(filter, document_id); | |
124 } | |
116 } | 125 } |
117 | 126 |
118 void SharedWorkerServiceImpl::WorkerContextClosed( | 127 void SharedWorkerServiceImpl::WorkerContextClosed( |
119 int worker_route_id, | 128 int worker_route_id, |
120 SharedWorkerMessageFilter* filter) { | 129 SharedWorkerMessageFilter* filter) { |
121 // TODO(horo): implement this. | 130 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
122 NOTIMPLEMENTED(); | 131 host->WorkerContextClosed(); |
132 } | |
kinuko
2014/02/27 11:34:44
nit: no need of { } for one-line (unless you're wr
horo
2014/02/28 04:59:14
Done.
| |
123 } | 133 } |
124 | 134 |
125 void SharedWorkerServiceImpl::WorkerContextDestroyed( | 135 void SharedWorkerServiceImpl::WorkerContextDestroyed( |
126 int worker_route_id, | 136 int worker_route_id, |
127 SharedWorkerMessageFilter* filter) { | 137 SharedWorkerMessageFilter* filter) { |
128 // TODO(horo): implement this. | 138 SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id); |
129 NOTIMPLEMENTED(); | 139 if (!host) |
140 return; | |
141 host->WorkerContextDestroyed(); | |
142 for (ScopedVector<SharedWorkerHost>::iterator iter = | |
143 worker_hosts_.begin(); | |
144 iter != worker_hosts_.end();) { | |
145 if (*iter == host) { | |
146 iter = worker_hosts_.erase(iter); | |
147 } else { | |
148 ++iter; | |
149 } | |
150 } | |
130 } | 151 } |
131 | 152 |
132 void SharedWorkerServiceImpl::WorkerScriptLoaded( | 153 void SharedWorkerServiceImpl::WorkerScriptLoaded( |
133 int worker_route_id, | 154 int worker_route_id, |
134 SharedWorkerMessageFilter* filter) { | 155 SharedWorkerMessageFilter* filter) { |
135 // TODO(horo): implement this. | 156 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
136 NOTIMPLEMENTED(); | 157 host->WorkerScriptLoaded(); |
158 } | |
137 } | 159 } |
138 | 160 |
139 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( | 161 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
140 int worker_route_id, | 162 int worker_route_id, |
141 SharedWorkerMessageFilter* filter) { | 163 SharedWorkerMessageFilter* filter) { |
142 // TODO(horo): implement this. | 164 SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id); |
143 NOTIMPLEMENTED(); | 165 if (!host) |
166 return; | |
167 host->WorkerScriptLoadFailed(); | |
168 for (ScopedVector<SharedWorkerHost>::iterator iter = | |
169 worker_hosts_.begin(); | |
170 iter != worker_hosts_.end();) { | |
171 if (*iter == host) { | |
172 iter = worker_hosts_.erase(iter); | |
173 } else { | |
174 ++iter; | |
175 } | |
176 } | |
144 } | 177 } |
145 | 178 |
146 void SharedWorkerServiceImpl::WorkerConnected( | 179 void SharedWorkerServiceImpl::WorkerConnected( |
147 int message_port_id, | 180 int message_port_id, |
148 int worker_route_id, | 181 int worker_route_id, |
149 SharedWorkerMessageFilter* filter) { | 182 SharedWorkerMessageFilter* filter) { |
150 // TODO(horo): implement this. | 183 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
151 NOTIMPLEMENTED(); | 184 host->WorkerConnected(message_port_id); |
185 } | |
152 } | 186 } |
153 | 187 |
154 void SharedWorkerServiceImpl::AllowDatabase( | 188 void SharedWorkerServiceImpl::AllowDatabase( |
155 int worker_route_id, | 189 int worker_route_id, |
156 const GURL& url, | 190 const GURL& url, |
157 const base::string16& name, | 191 const base::string16& name, |
158 const base::string16& display_name, | 192 const base::string16& display_name, |
159 unsigned long estimated_size, | 193 unsigned long estimated_size, |
160 bool* result, | 194 bool* result, |
161 SharedWorkerMessageFilter* filter) { | 195 SharedWorkerMessageFilter* filter) { |
162 // TODO(horo): implement this. | 196 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
163 NOTIMPLEMENTED(); | 197 host->AllowDatabase(url, name, display_name, estimated_size, result); |
198 } | |
164 } | 199 } |
165 | 200 |
166 void SharedWorkerServiceImpl::AllowFileSystem( | 201 void SharedWorkerServiceImpl::AllowFileSystem( |
167 int worker_route_id, | 202 int worker_route_id, |
168 const GURL& url, | 203 const GURL& url, |
169 bool* result, | 204 bool* result, |
170 SharedWorkerMessageFilter* filter) { | 205 SharedWorkerMessageFilter* filter) { |
171 // TODO(horo): implement this. | 206 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
172 NOTIMPLEMENTED(); | 207 host->AllowFileSystem(url, result); |
208 } | |
173 } | 209 } |
174 | 210 |
175 void SharedWorkerServiceImpl::AllowIndexedDB( | 211 void SharedWorkerServiceImpl::AllowIndexedDB( |
176 int worker_route_id, | 212 int worker_route_id, |
177 const GURL& url, | 213 const GURL& url, |
178 const base::string16& name, | 214 const base::string16& name, |
179 bool* result, | 215 bool* result, |
180 SharedWorkerMessageFilter* filter) { | 216 SharedWorkerMessageFilter* filter) { |
181 // TODO(horo): implement this. | 217 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) { |
182 NOTIMPLEMENTED(); | 218 host->AllowIndexedDB(url, name, result); |
219 } | |
183 } | 220 } |
184 | 221 |
185 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( | 222 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
186 SharedWorkerMessageFilter* filter) { | 223 SharedWorkerMessageFilter* filter) { |
187 // TODO(horo): implement this. | 224 for (ScopedVector<SharedWorkerHost>::iterator iter = |
188 NOTIMPLEMENTED(); | 225 worker_hosts_.begin(); |
226 iter != worker_hosts_.end();) { | |
227 (*iter)->FilterShutdown(filter); | |
228 if ((*iter)->parent_render_filter() == filter) { | |
229 iter = worker_hosts_.erase(iter); | |
230 } else { | |
231 ++iter; | |
232 } | |
233 } | |
234 } | |
235 | |
236 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | |
237 SharedWorkerMessageFilter* filter, | |
238 int worker_route_id) { | |
239 for (ScopedVector<SharedWorkerHost>::iterator iter = | |
240 worker_hosts_.begin(); | |
241 iter != worker_hosts_.end(); | |
242 ++iter) { | |
243 if ((*iter)->parent_render_filter() == filter && | |
244 (*iter)->instance() && | |
245 (*iter)->worker_route_id() == worker_route_id) { | |
246 return *iter; | |
247 } | |
248 } | |
kinuko
2014/02/27 11:34:44
Since we often call this (and also sometimes walk
horo
2014/02/28 04:59:14
Changed to use base::ScopedPtrHashMap with <Proces
| |
249 return NULL; | |
189 } | 250 } |
190 | 251 |
191 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( | 252 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( |
192 const GURL& url, | 253 const GURL& url, |
193 const base::string16& name, | 254 const base::string16& name, |
194 const WorkerStoragePartition& partition, | 255 const WorkerStoragePartition& partition, |
195 ResourceContext* resource_context) { | 256 ResourceContext* resource_context) { |
196 for (ScopedVector<SharedWorkerHost>::const_iterator iter = | 257 for (ScopedVector<SharedWorkerHost>::const_iterator iter = |
197 worker_hosts_.begin(); | 258 worker_hosts_.begin(); |
198 iter != worker_hosts_.end(); | 259 iter != worker_hosts_.end(); |
199 ++iter) { | 260 ++iter) { |
200 SharedWorkerInstance* instance = (*iter)->instance(); | 261 SharedWorkerInstance* instance = (*iter)->instance(); |
201 if (instance && | 262 if (instance && |
202 instance->Matches(url, name, partition, resource_context)) | 263 instance->Matches(url, name, partition, resource_context)) |
203 return instance; | 264 return instance; |
204 } | 265 } |
205 return NULL; | 266 return NULL; |
206 } | 267 } |
207 | 268 |
208 } // namespace content | 269 } // namespace content |
OLD | NEW |