OLD | NEW |
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 #include "content/browser/service_worker/embedded_worker_registry.h" | 5 #include "content/browser/service_worker/embedded_worker_registry.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "content/browser/renderer_host/render_widget_helper.h" | 9 #include "content/browser/renderer_host/render_widget_helper.h" |
10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 } | 77 } |
78 | 78 |
79 void EmbeddedWorkerRegistry::Shutdown() { | 79 void EmbeddedWorkerRegistry::Shutdown() { |
80 for (WorkerInstanceMap::iterator it = worker_map_.begin(); | 80 for (WorkerInstanceMap::iterator it = worker_map_.begin(); |
81 it != worker_map_.end(); | 81 it != worker_map_.end(); |
82 ++it) { | 82 ++it) { |
83 it->second->Stop(); | 83 it->second->Stop(); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
| 87 void EmbeddedWorkerRegistry::OnWorkerScriptLoaded(int process_id, |
| 88 int embedded_worker_id) { |
| 89 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
| 90 if (found == worker_map_.end()) { |
| 91 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; |
| 92 return; |
| 93 } |
| 94 if (found->second->process_id() != process_id) { |
| 95 LOG(ERROR) << "Incorrect embedded_worker_id"; |
| 96 return; |
| 97 } |
| 98 found->second->OnScriptLoaded(); |
| 99 } |
| 100 |
| 101 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id, |
| 102 int embedded_worker_id) { |
| 103 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
| 104 if (found == worker_map_.end()) { |
| 105 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; |
| 106 return; |
| 107 } |
| 108 if (found->second->process_id() != process_id) { |
| 109 LOG(ERROR) << "Incorrect embedded_worker_id"; |
| 110 return; |
| 111 } |
| 112 found->second->OnScriptLoadFailed(); |
| 113 } |
| 114 |
87 void EmbeddedWorkerRegistry::OnWorkerStarted( | 115 void EmbeddedWorkerRegistry::OnWorkerStarted( |
88 int process_id, int thread_id, int embedded_worker_id) { | 116 int process_id, int thread_id, int embedded_worker_id) { |
89 DCHECK(!ContainsKey(worker_process_map_, process_id) || | 117 DCHECK(!ContainsKey(worker_process_map_, process_id) || |
90 worker_process_map_[process_id].count(embedded_worker_id) == 0); | 118 worker_process_map_[process_id].count(embedded_worker_id) == 0); |
91 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 119 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
92 if (found == worker_map_.end()) { | 120 if (found == worker_map_.end()) { |
93 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; | 121 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; |
94 return; | 122 return; |
95 } | 123 } |
| 124 if (found->second->process_id() != process_id) { |
| 125 LOG(ERROR) << "Incorrect embedded_worker_id"; |
| 126 return; |
| 127 } |
96 worker_process_map_[process_id].insert(embedded_worker_id); | 128 worker_process_map_[process_id].insert(embedded_worker_id); |
97 DCHECK_EQ(found->second->process_id(), process_id); | |
98 found->second->OnStarted(thread_id); | 129 found->second->OnStarted(thread_id); |
99 } | 130 } |
100 | 131 |
101 void EmbeddedWorkerRegistry::OnWorkerStopped( | 132 void EmbeddedWorkerRegistry::OnWorkerStopped( |
102 int process_id, int embedded_worker_id) { | 133 int process_id, int embedded_worker_id) { |
103 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); | 134 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); |
104 if (found == worker_map_.end()) { | 135 if (found == worker_map_.end()) { |
105 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; | 136 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; |
106 return; | 137 return; |
107 } | 138 } |
108 DCHECK_EQ(found->second->process_id(), process_id); | 139 if (found->second->process_id() != process_id) { |
| 140 LOG(ERROR) << "Incorrect embedded_worker_id"; |
| 141 return; |
| 142 } |
109 worker_process_map_[process_id].erase(embedded_worker_id); | 143 worker_process_map_[process_id].erase(embedded_worker_id); |
110 found->second->OnStopped(); | 144 found->second->OnStopped(); |
111 } | 145 } |
112 | 146 |
113 void EmbeddedWorkerRegistry::OnReportException( | 147 void EmbeddedWorkerRegistry::OnReportException( |
114 int embedded_worker_id, | 148 int embedded_worker_id, |
115 const base::string16& error_message, | 149 const base::string16& error_message, |
116 int line_number, | 150 int line_number, |
117 int column_number, | 151 int column_number, |
118 const GURL& source_url) { | 152 const GURL& source_url) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 261 } |
228 | 262 |
229 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, | 263 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, |
230 int embedded_worker_id) { | 264 int embedded_worker_id) { |
231 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); | 265 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); |
232 worker_map_.erase(embedded_worker_id); | 266 worker_map_.erase(embedded_worker_id); |
233 worker_process_map_.erase(process_id); | 267 worker_process_map_.erase(process_id); |
234 } | 268 } |
235 | 269 |
236 } // namespace content | 270 } // namespace content |
OLD | NEW |