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

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

Issue 489303002: Use DCHECK instead of LOG(ERROR) in embedded_worker_registry.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 int process_id, int embedded_worker_id) { 46 int process_id, int embedded_worker_id) {
47 return Send(process_id, 47 return Send(process_id,
48 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id)); 48 new EmbeddedWorkerMsg_StopWorker(embedded_worker_id));
49 } 49 }
50 50
51 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) { 51 bool EmbeddedWorkerRegistry::OnMessageReceived(const IPC::Message& message) {
52 // TODO(kinuko): Move all EmbeddedWorker message handling from 52 // TODO(kinuko): Move all EmbeddedWorker message handling from
53 // ServiceWorkerDispatcherHost. 53 // ServiceWorkerDispatcherHost.
54 54
55 WorkerInstanceMap::iterator found = worker_map_.find(message.routing_id()); 55 WorkerInstanceMap::iterator found = worker_map_.find(message.routing_id());
56 if (found == worker_map_.end()) { 56 DCHECK(found != worker_map_.end());
57 LOG(ERROR) << "Worker " << message.routing_id() << " not registered"; 57 if (found == worker_map_.end())
58 return false; 58 return false;
59 }
60 return found->second->OnMessageReceived(message); 59 return found->second->OnMessageReceived(message);
61 } 60 }
62 61
63 void EmbeddedWorkerRegistry::Shutdown() { 62 void EmbeddedWorkerRegistry::Shutdown() {
64 for (WorkerInstanceMap::iterator it = worker_map_.begin(); 63 for (WorkerInstanceMap::iterator it = worker_map_.begin();
65 it != worker_map_.end(); 64 it != worker_map_.end();
66 ++it) { 65 ++it) {
67 it->second->Stop(); 66 it->second->Stop();
68 } 67 }
69 } 68 }
70 69
71 void EmbeddedWorkerRegistry::OnWorkerReadyForInspection( 70 void EmbeddedWorkerRegistry::OnWorkerReadyForInspection(
72 int process_id, 71 int process_id,
73 int embedded_worker_id) { 72 int embedded_worker_id) {
74 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 73 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
75 if (found == worker_map_.end()) { 74 DCHECK(found != worker_map_.end());
76 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 75 DCHECK(found->second->process_id() == process_id);
nhiroki 2014/08/21 02:13:18 Can you use DCHECK_EQ instead here and elsewhere?
horo 2014/08/21 03:56:39 Done.
76 if (found == worker_map_.end() || found->second->process_id() != process_id)
77 return; 77 return;
78 }
79 if (found->second->process_id() != process_id) {
80 LOG(ERROR) << "Incorrect embedded_worker_id";
81 return;
82 }
83 found->second->OnReadyForInspection(); 78 found->second->OnReadyForInspection();
84 } 79 }
85 80
86 void EmbeddedWorkerRegistry::OnWorkerScriptLoaded(int process_id, 81 void EmbeddedWorkerRegistry::OnWorkerScriptLoaded(int process_id,
87 int embedded_worker_id) { 82 int embedded_worker_id) {
88 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 83 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
89 if (found == worker_map_.end()) { 84 DCHECK(found != worker_map_.end());
90 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 85 DCHECK(found->second->process_id() == process_id);
86 if (found == worker_map_.end() || found->second->process_id() != process_id)
91 return; 87 return;
92 }
93 if (found->second->process_id() != process_id) {
94 LOG(ERROR) << "Incorrect embedded_worker_id";
95 return;
96 }
97 found->second->OnScriptLoaded(); 88 found->second->OnScriptLoaded();
98 } 89 }
99 90
100 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id, 91 void EmbeddedWorkerRegistry::OnWorkerScriptLoadFailed(int process_id,
101 int embedded_worker_id) { 92 int embedded_worker_id) {
102 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 93 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
103 if (found == worker_map_.end()) { 94 DCHECK(found != worker_map_.end());
104 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 95 DCHECK(found->second->process_id() == process_id);
96 if (found == worker_map_.end() || found->second->process_id() != process_id)
105 return; 97 return;
106 }
107 if (found->second->process_id() != process_id) {
108 LOG(ERROR) << "Incorrect embedded_worker_id";
109 return;
110 }
111 found->second->OnScriptLoadFailed(); 98 found->second->OnScriptLoadFailed();
112 } 99 }
113 100
114 void EmbeddedWorkerRegistry::OnWorkerStarted( 101 void EmbeddedWorkerRegistry::OnWorkerStarted(
115 int process_id, int thread_id, int embedded_worker_id) { 102 int process_id, int thread_id, int embedded_worker_id) {
116 DCHECK(!ContainsKey(worker_process_map_, process_id) || 103 DCHECK(!ContainsKey(worker_process_map_, process_id) ||
117 worker_process_map_[process_id].count(embedded_worker_id) == 0); 104 worker_process_map_[process_id].count(embedded_worker_id) == 0);
118 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 105 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
119 if (found == worker_map_.end()) { 106 DCHECK(found != worker_map_.end());
120 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 107 DCHECK(found->second->process_id() == process_id);
108 if (found == worker_map_.end() || found->second->process_id() != process_id)
121 return; 109 return;
122 }
123 if (found->second->process_id() != process_id) {
124 LOG(ERROR) << "Incorrect embedded_worker_id";
125 return;
126 }
127 worker_process_map_[process_id].insert(embedded_worker_id); 110 worker_process_map_[process_id].insert(embedded_worker_id);
128 found->second->OnStarted(thread_id); 111 found->second->OnStarted(thread_id);
129 } 112 }
130 113
131 void EmbeddedWorkerRegistry::OnWorkerStopped( 114 void EmbeddedWorkerRegistry::OnWorkerStopped(
132 int process_id, int embedded_worker_id) { 115 int process_id, int embedded_worker_id) {
133 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 116 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
134 if (found == worker_map_.end()) { 117 DCHECK(found != worker_map_.end());
135 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 118 DCHECK(found->second->process_id() == process_id);
119 if (found == worker_map_.end() || found->second->process_id() != process_id)
136 return; 120 return;
137 }
138 if (found->second->process_id() != process_id) {
139 LOG(ERROR) << "Incorrect embedded_worker_id";
140 return;
141 }
142 worker_process_map_[process_id].erase(embedded_worker_id); 121 worker_process_map_[process_id].erase(embedded_worker_id);
143 found->second->OnStopped(); 122 found->second->OnStopped();
144 } 123 }
145 124
146 void EmbeddedWorkerRegistry::OnPausedAfterDownload( 125 void EmbeddedWorkerRegistry::OnPausedAfterDownload(
147 int process_id, int embedded_worker_id) { 126 int process_id, int embedded_worker_id) {
148 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 127 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
149 if (found == worker_map_.end()) { 128 DCHECK(found != worker_map_.end());
150 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 129 DCHECK(found->second->process_id() == process_id);
130 if (found == worker_map_.end() || found->second->process_id() != process_id)
151 return; 131 return;
152 }
153 if (found->second->process_id() != process_id) {
154 LOG(ERROR) << "Incorrect embedded_worker_id";
155 return;
156 }
157 found->second->OnPausedAfterDownload(); 132 found->second->OnPausedAfterDownload();
158 } 133 }
159 134
160 void EmbeddedWorkerRegistry::OnReportException( 135 void EmbeddedWorkerRegistry::OnReportException(
161 int embedded_worker_id, 136 int embedded_worker_id,
162 const base::string16& error_message, 137 const base::string16& error_message,
163 int line_number, 138 int line_number,
164 int column_number, 139 int column_number,
165 const GURL& source_url) { 140 const GURL& source_url) {
166 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 141 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
167 if (found == worker_map_.end()) { 142 DCHECK(found != worker_map_.end());
168 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 143 if (found == worker_map_.end())
169 return; 144 return;
170 }
171 found->second->OnReportException( 145 found->second->OnReportException(
172 error_message, line_number, column_number, source_url); 146 error_message, line_number, column_number, source_url);
173 } 147 }
174 148
175 void EmbeddedWorkerRegistry::OnReportConsoleMessage( 149 void EmbeddedWorkerRegistry::OnReportConsoleMessage(
176 int embedded_worker_id, 150 int embedded_worker_id,
177 int source_identifier, 151 int source_identifier,
178 int message_level, 152 int message_level,
179 const base::string16& message, 153 const base::string16& message,
180 int line_number, 154 int line_number,
181 const GURL& source_url) { 155 const GURL& source_url) {
182 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id); 156 WorkerInstanceMap::iterator found = worker_map_.find(embedded_worker_id);
183 if (found == worker_map_.end()) { 157 DCHECK(found != worker_map_.end());
184 LOG(ERROR) << "Worker " << embedded_worker_id << " not registered"; 158 if (found == worker_map_.end())
185 return; 159 return;
186 }
187 found->second->OnReportConsoleMessage( 160 found->second->OnReportConsoleMessage(
188 source_identifier, message_level, message, line_number, source_url); 161 source_identifier, message_level, message, line_number, source_url);
189 } 162 }
190 163
191 void EmbeddedWorkerRegistry::AddChildProcessSender( 164 void EmbeddedWorkerRegistry::AddChildProcessSender(
192 int process_id, IPC::Sender* sender) { 165 int process_id, IPC::Sender* sender) {
193 process_sender_map_[process_id] = sender; 166 process_sender_map_[process_id] = sender;
194 DCHECK(!ContainsKey(worker_process_map_, process_id)); 167 DCHECK(!ContainsKey(worker_process_map_, process_id));
195 } 168 }
196 169
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 } 237 }
265 238
266 void EmbeddedWorkerRegistry::RemoveWorker(int process_id, 239 void EmbeddedWorkerRegistry::RemoveWorker(int process_id,
267 int embedded_worker_id) { 240 int embedded_worker_id) {
268 DCHECK(ContainsKey(worker_map_, embedded_worker_id)); 241 DCHECK(ContainsKey(worker_map_, embedded_worker_id));
269 worker_map_.erase(embedded_worker_id); 242 worker_map_.erase(embedded_worker_id);
270 worker_process_map_.erase(process_id); 243 worker_process_map_.erase(process_id);
271 } 244 }
272 245
273 } // namespace content 246 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698