| 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_host.h" | 5 #include "content/browser/shared_worker/shared_worker_host.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram_macros.h" | 7 #include "base/metrics/histogram_macros.h" |
| 8 #include "content/browser/devtools/shared_worker_devtools_manager.h" | 8 #include "content/browser/devtools/shared_worker_devtools_manager.h" |
| 9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
| 10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 int render_frame_id) { | 123 int render_frame_id) { |
| 124 // Walk all instances and remove all the documents in the frame from their | 124 // Walk all instances and remove all the documents in the frame from their |
| 125 // document set. | 125 // document set. |
| 126 worker_document_set_->RemoveRenderFrame(render_process_id, render_frame_id); | 126 worker_document_set_->RemoveRenderFrame(render_process_id, render_frame_id); |
| 127 if (worker_document_set_->IsEmpty()) { | 127 if (worker_document_set_->IsEmpty()) { |
| 128 // This worker has no more associated documents - shut it down. | 128 // This worker has no more associated documents - shut it down. |
| 129 TerminateWorker(); | 129 TerminateWorker(); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 void SharedWorkerHost::CountFeature(uint32_t feature) { |
| 134 if (use_counter_.IsCounted(feature)) |
| 135 return; |
| 136 use_counter_.Count(feature); |
| 137 for (const auto& filter_info : filters_) { |
| 138 filter_info.filter()->Send(new ViewMsg_CountFeatureOnSharedWorker( |
| 139 filter_info.route_id(), feature)); |
| 140 } |
| 141 } |
| 142 |
| 133 void SharedWorkerHost::WorkerContextClosed() { | 143 void SharedWorkerHost::WorkerContextClosed() { |
| 134 // Set the closed flag - this will stop any further messages from | 144 // Set the closed flag - this will stop any further messages from |
| 135 // being sent to the worker (messages can still be sent from the worker, | 145 // being sent to the worker (messages can still be sent from the worker, |
| 136 // for exception reporting, etc). | 146 // for exception reporting, etc). |
| 137 closed_ = true; | 147 closed_ = true; |
| 138 if (!termination_message_sent_) | 148 if (!termination_message_sent_) |
| 139 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); | 149 NotifyWorkerDestroyed(worker_process_id_, worker_route_id_); |
| 140 } | 150 } |
| 141 | 151 |
| 152 void SharedWorkerHost::WorkerContextDestroyed() { |
| 153 for (const auto& filter_info : filters_) { |
| 154 filter_info.filter()->Send( |
| 155 new ViewMsg_WorkerDestroyed(filter_info.route_id())); |
| 156 } |
| 157 } |
| 158 |
| 142 void SharedWorkerHost::WorkerReadyForInspection() { | 159 void SharedWorkerHost::WorkerReadyForInspection() { |
| 143 NotifyWorkerReadyForInspection(worker_process_id_, worker_route_id_); | 160 NotifyWorkerReadyForInspection(worker_process_id_, worker_route_id_); |
| 144 } | 161 } |
| 145 | 162 |
| 146 void SharedWorkerHost::WorkerScriptLoaded() { | 163 void SharedWorkerHost::WorkerScriptLoaded() { |
| 147 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", | 164 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoaded", |
| 148 base::TimeTicks::Now() - creation_time_); | 165 base::TimeTicks::Now() - creation_time_); |
| 149 } | 166 } |
| 150 | 167 |
| 151 void SharedWorkerHost::WorkerScriptLoadFailed() { | 168 void SharedWorkerHost::WorkerScriptLoadFailed() { |
| 152 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", | 169 UMA_HISTOGRAM_TIMES("SharedWorker.TimeToScriptLoadFailed", |
| 153 base::TimeTicks::Now() - creation_time_); | 170 base::TimeTicks::Now() - creation_time_); |
| 154 for (const FilterInfo& info : filters_) | 171 for (const FilterInfo& info : filters_) |
| 155 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id())); | 172 info.filter()->Send(new ViewMsg_WorkerScriptLoadFailed(info.route_id())); |
| 156 } | 173 } |
| 157 | 174 |
| 158 void SharedWorkerHost::WorkerConnected(int message_port_id) { | 175 void SharedWorkerHost::WorkerConnected(int message_port_id) { |
| 159 for (const FilterInfo& info : filters_) { | 176 for (const FilterInfo& info : filters_) { |
| 160 if (info.message_port_id() != message_port_id) | 177 if (info.message_port_id() != message_port_id) |
| 161 continue; | 178 continue; |
| 162 info.filter()->Send(new ViewMsg_WorkerConnected(info.route_id())); | 179 info.filter()->Send( |
| 180 new ViewMsg_WorkerConnected(info.route_id(), use_counter_.Dump())); |
| 163 return; | 181 return; |
| 164 } | 182 } |
| 165 } | 183 } |
| 166 | 184 |
| 167 void SharedWorkerHost::AllowFileSystem( | 185 void SharedWorkerHost::AllowFileSystem( |
| 168 const GURL& url, | 186 const GURL& url, |
| 169 std::unique_ptr<IPC::Message> reply_msg) { | 187 std::unique_ptr<IPC::Message> reply_msg) { |
| 170 GetContentClient()->browser()->AllowWorkerFileSystem( | 188 GetContentClient()->browser()->AllowWorkerFileSystem( |
| 171 url, | 189 url, |
| 172 instance_->resource_context(), | 190 instance_->resource_context(), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 return; | 289 return; |
| 272 } | 290 } |
| 273 } | 291 } |
| 274 } | 292 } |
| 275 | 293 |
| 276 bool SharedWorkerHost::Send(IPC::Message* message) { | 294 bool SharedWorkerHost::Send(IPC::Message* message) { |
| 277 return worker_render_filter_->Send(message); | 295 return worker_render_filter_->Send(message); |
| 278 } | 296 } |
| 279 | 297 |
| 280 } // namespace content | 298 } // namespace content |
| OLD | NEW |