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" | |
8 #include "content/browser/shared_worker/shared_worker_instance.h" | |
7 #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" | |
11 #include "content/common/view_messages.h" | |
8 #include "content/common/worker_messages.h" | 12 #include "content/common/worker_messages.h" |
9 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
10 #include "content/public/browser/worker_service_observer.h" | 14 #include "content/public/browser/worker_service_observer.h" |
11 | 15 |
12 namespace content { | 16 namespace content { |
13 | 17 |
14 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { | 18 SharedWorkerServiceImpl* SharedWorkerServiceImpl::GetInstance() { |
15 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
16 return Singleton<SharedWorkerServiceImpl>::get(); | 20 return Singleton<SharedWorkerServiceImpl>::get(); |
17 } | 21 } |
(...skipping 25 matching lines...) Expand all Loading... | |
43 observers_.RemoveObserver(observer); | 47 observers_.RemoveObserver(observer); |
44 } | 48 } |
45 | 49 |
46 void SharedWorkerServiceImpl::CreateWorker( | 50 void SharedWorkerServiceImpl::CreateWorker( |
47 const ViewHostMsg_CreateWorker_Params& params, | 51 const ViewHostMsg_CreateWorker_Params& params, |
48 int route_id, | 52 int route_id, |
49 SharedWorkerMessageFilter* filter, | 53 SharedWorkerMessageFilter* filter, |
50 ResourceContext* resource_context, | 54 ResourceContext* resource_context, |
51 const WorkerStoragePartition& partition, | 55 const WorkerStoragePartition& partition, |
52 bool* url_mismatch) { | 56 bool* url_mismatch) { |
53 // TODO(horo): implement this. | 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
54 NOTIMPLEMENTED(); | 58 *url_mismatch = false; |
59 SharedWorkerInstance* existing_instance = | |
60 FindSharedWorkerInstance( | |
61 params.url, params.name, partition, resource_context); | |
62 if (existing_instance) { | |
63 if (params.url != existing_instance->url()) { | |
64 *url_mismatch = true; | |
65 return; | |
66 } | |
67 if (existing_instance->load_failed()) { | |
68 filter->Send(new ViewMsg_WorkerScriptLoadFailed(route_id)); | |
69 return; | |
70 } | |
71 existing_instance->AddFilter(filter, route_id); | |
72 existing_instance->worker_document_set()->Add( | |
73 filter, params.document_id, filter->render_process_id(), | |
74 params.render_frame_route_id); | |
75 filter->Send(new ViewMsg_WorkerCreated(route_id)); | |
76 return; | |
77 } | |
78 | |
79 scoped_ptr<SharedWorkerInstance> instance(new SharedWorkerInstance( | |
80 params.url, | |
81 params.name, | |
82 params.content_security_policy, | |
83 params.security_policy_type, | |
84 resource_context, | |
85 partition)); | |
86 instance->AddFilter(filter, route_id); | |
87 instance->worker_document_set()->Add( | |
88 filter, params.document_id, filter->render_process_id(), | |
89 params.render_frame_route_id); | |
90 | |
91 SharedWorkerHost *worker(new SharedWorkerHost(instance.release())); | |
kinuko
2014/02/26 08:51:17
nit: can we create this as scoped_ptr<SharedWorker
horo
2014/02/26 10:36:19
Done.
| |
92 worker->Init(filter); | |
kinuko
2014/02/26 08:51:17
We don't need to check the return value of Init()
horo
2014/02/26 10:36:19
I changed the return value type of SharedWorkerHos
| |
93 // |worker_hosts_| owns |worker|. | |
94 worker_hosts_.push_back(worker); | |
95 FOR_EACH_OBSERVER( | |
96 WorkerServiceObserver, observers_, | |
97 WorkerCreated(worker->instance()->url(), | |
98 worker->instance()->name(), | |
99 filter->render_process_id(), | |
100 worker->worker_route_id())); | |
55 } | 101 } |
56 | 102 |
57 void SharedWorkerServiceImpl::ForwardToWorker( | 103 void SharedWorkerServiceImpl::ForwardToWorker( |
58 const IPC::Message& message, | 104 const IPC::Message& message, |
59 SharedWorkerMessageFilter* filter) { | 105 SharedWorkerMessageFilter* filter) { |
60 // TODO(horo): implement this. | 106 // TODO(horo): implement this. |
61 NOTIMPLEMENTED(); | 107 NOTIMPLEMENTED(); |
62 } | 108 } |
63 | 109 |
64 void SharedWorkerServiceImpl::DocumentDetached( | 110 void SharedWorkerServiceImpl::DocumentDetached( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 // TODO(horo): implement this. | 180 // TODO(horo): implement this. |
135 NOTIMPLEMENTED(); | 181 NOTIMPLEMENTED(); |
136 } | 182 } |
137 | 183 |
138 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( | 184 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
139 SharedWorkerMessageFilter* filter) { | 185 SharedWorkerMessageFilter* filter) { |
140 // TODO(horo): implement this. | 186 // TODO(horo): implement this. |
141 NOTIMPLEMENTED(); | 187 NOTIMPLEMENTED(); |
142 } | 188 } |
143 | 189 |
190 SharedWorkerInstance* SharedWorkerServiceImpl::FindSharedWorkerInstance( | |
191 const GURL& url, | |
192 const base::string16& name, | |
193 const WorkerStoragePartition& partition, | |
194 ResourceContext* resource_context) { | |
195 for (ScopedVector<SharedWorkerHost>::const_iterator iter = | |
196 worker_hosts_.begin(); | |
197 iter != worker_hosts_.end(); | |
198 ++iter) { | |
199 SharedWorkerInstance* instance = (*iter)->instance(); | |
200 if (instance && | |
201 instance->Matches(url, name, partition, resource_context)) | |
202 return instance; | |
203 } | |
204 return NULL; | |
205 } | |
206 | |
144 } // namespace content | 207 } // namespace content |
OLD | NEW |