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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 params.name, | 81 params.name, |
82 params.content_security_policy, | 82 params.content_security_policy, |
83 params.security_policy_type, | 83 params.security_policy_type, |
84 resource_context, | 84 resource_context, |
85 partition)); | 85 partition)); |
86 instance->AddFilter(filter, route_id); | 86 instance->AddFilter(filter, route_id); |
87 instance->worker_document_set()->Add( | 87 instance->worker_document_set()->Add( |
88 filter, params.document_id, filter->render_process_id(), | 88 filter, params.document_id, filter->render_process_id(), |
89 params.render_frame_route_id); | 89 params.render_frame_route_id); |
90 | 90 |
91 scoped_ptr<SharedWorkerHost> worker(new SharedWorkerHost(instance.release())); | 91 scoped_ptr<SharedWorkerHost> host(new SharedWorkerHost(instance.release())); |
92 worker->Init(filter); | 92 host->Init(filter); |
93 const int worker_route_id = worker->worker_route_id(); | 93 const int worker_route_id = host->worker_route_id(); |
94 worker_hosts_.push_back(worker.release()); | 94 worker_hosts_.set(std::make_pair(filter->render_process_id(), |
95 worker_route_id), | |
96 host.Pass()); | |
95 | 97 |
96 FOR_EACH_OBSERVER( | 98 FOR_EACH_OBSERVER( |
97 WorkerServiceObserver, observers_, | 99 WorkerServiceObserver, observers_, |
98 WorkerCreated(params.url, | 100 WorkerCreated(params.url, |
99 params.name, | 101 params.name, |
100 filter->render_process_id(), | 102 filter->render_process_id(), |
101 worker_route_id)); | 103 worker_route_id)); |
102 } | 104 } |
103 | 105 |
104 void SharedWorkerServiceImpl::ForwardToWorker( | 106 void SharedWorkerServiceImpl::ForwardToWorker( |
105 const IPC::Message& message, | 107 const IPC::Message& message, |
106 SharedWorkerMessageFilter* filter) { | 108 SharedWorkerMessageFilter* filter) { |
107 // TODO(horo): implement this. | 109 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
108 NOTIMPLEMENTED(); | 110 iter != worker_hosts_.end(); |
111 ++iter) { | |
112 if (iter->second->FilterMessage(message, filter)) | |
113 return; | |
114 } | |
109 } | 115 } |
110 | 116 |
111 void SharedWorkerServiceImpl::DocumentDetached( | 117 void SharedWorkerServiceImpl::DocumentDetached( |
112 unsigned long long document_id, | 118 unsigned long long document_id, |
113 SharedWorkerMessageFilter* filter) { | 119 SharedWorkerMessageFilter* filter) { |
114 // TODO(horo): implement this. | 120 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
115 NOTIMPLEMENTED(); | 121 iter != worker_hosts_.end(); |
122 ++iter) { | |
123 iter->second->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(); |
123 } | 132 } |
124 | 133 |
125 void SharedWorkerServiceImpl::WorkerContextDestroyed( | 134 void SharedWorkerServiceImpl::WorkerContextDestroyed( |
126 int worker_route_id, | 135 int worker_route_id, |
127 SharedWorkerMessageFilter* filter) { | 136 SharedWorkerMessageFilter* filter) { |
128 // TODO(horo): implement this. | 137 scoped_ptr<SharedWorkerHost> host = |
129 NOTIMPLEMENTED(); | 138 worker_hosts_.take_and_erase(std::make_pair(filter->render_process_id(), |
139 worker_route_id)); | |
140 if (!host) | |
141 return; | |
142 host->WorkerContextDestroyed(); | |
130 } | 143 } |
131 | 144 |
132 void SharedWorkerServiceImpl::WorkerScriptLoaded( | 145 void SharedWorkerServiceImpl::WorkerScriptLoaded( |
133 int worker_route_id, | 146 int worker_route_id, |
134 SharedWorkerMessageFilter* filter) { | 147 SharedWorkerMessageFilter* filter) { |
135 // TODO(horo): implement this. | 148 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
136 NOTIMPLEMENTED(); | 149 host->WorkerScriptLoaded(); |
137 } | 150 } |
138 | 151 |
139 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( | 152 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
140 int worker_route_id, | 153 int worker_route_id, |
141 SharedWorkerMessageFilter* filter) { | 154 SharedWorkerMessageFilter* filter) { |
142 // TODO(horo): implement this. | 155 scoped_ptr<SharedWorkerHost> host = |
143 NOTIMPLEMENTED(); | 156 worker_hosts_.take_and_erase(std::make_pair(filter->render_process_id(), |
157 worker_route_id)); | |
158 if (!host) | |
kinuko
2014/02/28 06:52:20
if (!host || !host->instance()) ?
horo
2014/02/28 07:16:16
Added null check of instance in SharedWorkerHost.
| |
159 return; | |
160 host->WorkerScriptLoadFailed(); | |
144 } | 161 } |
145 | 162 |
146 void SharedWorkerServiceImpl::WorkerConnected( | 163 void SharedWorkerServiceImpl::WorkerConnected( |
147 int message_port_id, | 164 int message_port_id, |
148 int worker_route_id, | 165 int worker_route_id, |
149 SharedWorkerMessageFilter* filter) { | 166 SharedWorkerMessageFilter* filter) { |
150 // TODO(horo): implement this. | 167 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
151 NOTIMPLEMENTED(); | 168 host->WorkerConnected(message_port_id); |
152 } | 169 } |
153 | 170 |
154 void SharedWorkerServiceImpl::AllowDatabase( | 171 void SharedWorkerServiceImpl::AllowDatabase( |
155 int worker_route_id, | 172 int worker_route_id, |
156 const GURL& url, | 173 const GURL& url, |
157 const base::string16& name, | 174 const base::string16& name, |
158 const base::string16& display_name, | 175 const base::string16& display_name, |
159 unsigned long estimated_size, | 176 unsigned long estimated_size, |
160 bool* result, | 177 bool* result, |
161 SharedWorkerMessageFilter* filter) { | 178 SharedWorkerMessageFilter* filter) { |
162 // TODO(horo): implement this. | 179 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
163 NOTIMPLEMENTED(); | 180 host->AllowDatabase(url, name, display_name, estimated_size, result); |
164 } | 181 } |
165 | 182 |
166 void SharedWorkerServiceImpl::AllowFileSystem( | 183 void SharedWorkerServiceImpl::AllowFileSystem( |
167 int worker_route_id, | 184 int worker_route_id, |
168 const GURL& url, | 185 const GURL& url, |
169 bool* result, | 186 bool* result, |
170 SharedWorkerMessageFilter* filter) { | 187 SharedWorkerMessageFilter* filter) { |
171 // TODO(horo): implement this. | 188 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
172 NOTIMPLEMENTED(); | 189 host->AllowFileSystem(url, result); |
173 } | 190 } |
174 | 191 |
175 void SharedWorkerServiceImpl::AllowIndexedDB( | 192 void SharedWorkerServiceImpl::AllowIndexedDB( |
176 int worker_route_id, | 193 int worker_route_id, |
177 const GURL& url, | 194 const GURL& url, |
178 const base::string16& name, | 195 const base::string16& name, |
179 bool* result, | 196 bool* result, |
180 SharedWorkerMessageFilter* filter) { | 197 SharedWorkerMessageFilter* filter) { |
181 // TODO(horo): implement this. | 198 if (SharedWorkerHost* host = FindSharedWorkerHost(filter, worker_route_id)) |
182 NOTIMPLEMENTED(); | 199 host->AllowIndexedDB(url, name, result); |
183 } | 200 } |
184 | 201 |
185 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( | 202 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
186 SharedWorkerMessageFilter* filter) { | 203 SharedWorkerMessageFilter* filter) { |
187 // TODO(horo): implement this. | 204 std::vector<ProcessRouteIdPair> remove_list; |
188 NOTIMPLEMENTED(); | 205 for (WorkerHostMap::iterator iter = worker_hosts_.begin(); |
206 iter != worker_hosts_.end(); | |
207 ++iter) { | |
208 iter->second->FilterShutdown(filter); | |
209 if (iter->first.first == filter->render_process_id()) | |
210 remove_list.push_back(iter->first); | |
211 } | |
212 for (size_t i = 0; i < remove_list.size(); ++i) | |
213 worker_hosts_.erase(remove_list[i]); | |
214 } | |
215 | |
216 SharedWorkerHost* SharedWorkerServiceImpl::FindSharedWorkerHost( | |
217 SharedWorkerMessageFilter* filter, | |
218 int worker_route_id) { | |
219 return worker_hosts_.get(std::make_pair(filter->render_process_id(), | |
220 worker_route_id)); | |
kinuko
2014/02/28 06:52:20
In the previous implementation we also used to che
horo
2014/02/28 07:16:16
Added null check of instance in SharedWorkerHost.
| |
189 } | 221 } |
190 | 222 |
191 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( | 223 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( |
192 const GURL& url, | 224 const GURL& url, |
193 const base::string16& name, | 225 const base::string16& name, |
194 const WorkerStoragePartition& partition, | 226 const WorkerStoragePartition& partition, |
195 ResourceContext* resource_context) { | 227 ResourceContext* resource_context) { |
196 for (ScopedVector<SharedWorkerHost>::const_iterator iter = | 228 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
197 worker_hosts_.begin(); | |
198 iter != worker_hosts_.end(); | 229 iter != worker_hosts_.end(); |
199 ++iter) { | 230 ++iter) { |
200 SharedWorkerInstance* instance = (*iter)->instance(); | 231 SharedWorkerInstance* instance = iter->second->instance(); |
201 if (instance && | 232 if (instance && instance->Matches(url, name, partition, resource_context)) |
202 instance->Matches(url, name, partition, resource_context)) | |
203 return instance; | 233 return instance; |
204 } | 234 } |
205 return NULL; | 235 return NULL; |
206 } | 236 } |
207 | 237 |
208 } // namespace content | 238 } // namespace content |
OLD | NEW |