Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: content/browser/service_worker/embedded_worker_registry.cc

Issue 489253002: Allow the browser to Send messages to an embedded worker once the script as been loaded without hav… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
77 return; 77 return;
78 } 78 }
79 if (found->second->process_id() != process_id) { 79 if (found->second->process_id() != process_id) {
80 LOG(ERROR) << "Incorrect embedded_worker_id"; 80 LOG(ERROR) << "Incorrect embedded_worker_id";
81 return; 81 return;
82 } 82 }
83 found->second->OnReadyForInspection(); 83 found->second->OnReadyForInspection();
84 } 84 }
85 85
86 void EmbeddedWorkerRegistry::OnWorkerScriptLoaded(int process_id, 86 void EmbeddedWorkerRegistry::OnWorkerScriptLoaded(int process_id,
87 int embedded_worker_id) { 87 int thread_id,
88 int embedded_worker_id ) {
88 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 89 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
89 if (found == worker_map_.end()) { 90 if (found == worker_map_.end()) {
90 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 91 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
91 return; 92 return;
92 } 93 }
93 if (found->second->process_id() != process_id) { 94 if (found->second->process_id() != process_id) {
94 LOG(ERROR) << "Incorrect embedded_worker_id"; 95 LOG(ERROR) << "Incorrect embedded_worker_id";
95 return; 96 return;
96 } 97 }
97 found->second->OnScriptLoaded(); 98 found->second->OnScriptLoaded(thread_id);
98 } 99 }
99 100
100 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id, 101 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id,
101 int embedded_worker_id) { 102 int embedded_worker_id) {
102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 103 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
103 if (found == worker_map_.end()) { 104 if (found == worker_map_.end()) {
104 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 105 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
105 return; 106 return;
106 } 107 }
107 if (found->second->process_id() != process_id) { 108 if (found->second->process_id() != process_id) {
108 LOG(ERROR) << "Incorrect embedded_worker_id"; 109 LOG(ERROR) << "Incorrect embedded_worker_id";
109 return; 110 return;
110 } 111 }
111 found->second->OnScriptLoadFailed(); 112 found->second->OnScriptLoadFailed();
112 } 113 }
113 114
114 void EmbeddedWorkerRegistry::OnWorkerStarted( 115 void EmbeddedWorkerRegistry::OnWorkerStarted(
115 int process_id, int thread_id, int embedded_worker_id) { 116 int process_id, int embedded_worker_id) {
116 DCHECK(!ContainsKey(worker_process_map_, process_id) || 117 DCHECK(!ContainsKey(worker_process_map_, process_id) ||
117 worker_process_map_[process_id].count(embedded_worker_id) == 0); 118 worker_process_map_[process_id].count(embedded_worker_id) == 0);
118 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 119 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
119 if (found == worker_map_.end()) { 120 if (found == worker_map_.end()) {
120 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 121 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
121 return; 122 return;
122 } 123 }
123 if (found->second->process_id() != process_id) { 124 if (found->second->process_id() != process_id) {
124 LOG(ERROR) << "Incorrect embedded_worker_id"; 125 LOG(ERROR) << "Incorrect embedded_worker_id";
125 return; 126 return;
126 } 127 }
127 worker_process_map_[process_id].insert(embedded_worker_id); 128 worker_process_map_[process_id].insert(embedded_worker_id);
128 found->second->OnStarted(thread_id); 129 found->second->OnStarted();
129 } 130 }
130 131
131 void EmbeddedWorkerRegistry::OnWorkerStopped( 132 void EmbeddedWorkerRegistry::OnWorkerStopped(int process_id,
132 int process_id, int embedded_worker_id) { 133 int embedded_worker_id) {
133 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 134 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
134 if (found == worker_map_.end()) { 135 if (found == worker_map_.end()) {
135 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 136 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered";
136 return; 137 return;
137 } 138 }
138 if (found->second->process_id() != process_id) { 139 if (found->second->process_id() != process_id) {
139 LOG(ERROR) << "Incorrect embedded_worker_id"; 140 LOG(ERROR) << "Incorrect embedded_worker_id";
140 return; 141 return;
141 } 142 }
142 worker_process_map_[process_id].erase(embedded_worker_id); 143 worker_process_map_[process_id].erase(embedded_worker_id);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 265 }
265 266
266 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 267 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
267 int embedded_worker_id) { 268 int embedded_worker_id) {
268 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 269 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
269 worker_map_.erase(embedded_worker_id); 270 worker_map_.erase(embedded_worker_id);
270 worker_process_map_.erase(process_id); 271 worker_process_map_.erase(process_id);
271 } 272 }
272 273
273 } // namespace content 274 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698