OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/service_worker_context_watcher.h" | 5 #include "content/browser/service_worker/service_worker_context_watcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/scoped_ptr_hash_map.h" | 8 #include "base/containers/scoped_ptr_hash_map.h" |
9 #include "content/browser/service_worker/service_worker_context_observer.h" | 9 #include "content/browser/service_worker/service_worker_context_observer.h" |
10 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 10 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 scoped_ptr<ServiceWorkerRegistrationInfo>( | 114 scoped_ptr<ServiceWorkerRegistrationInfo>( |
115 new ServiceWorkerRegistrationInfo(registration_info))); | 115 new ServiceWorkerRegistrationInfo(registration_info))); |
116 StoreVersionInfo(registration_info.active_version); | 116 StoreVersionInfo(registration_info.active_version); |
117 StoreVersionInfo(registration_info.waiting_version); | 117 StoreVersionInfo(registration_info.waiting_version); |
118 StoreVersionInfo(registration_info.installing_version); | 118 StoreVersionInfo(registration_info.installing_version); |
119 } | 119 } |
120 | 120 |
121 void ServiceWorkerContextWatcher::StoreVersionInfo( | 121 void ServiceWorkerContextWatcher::StoreVersionInfo( |
122 const ServiceWorkerVersionInfo& version_info) { | 122 const ServiceWorkerVersionInfo& version_info) { |
123 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 123 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
124 if (version_info.version_id == kInvalidServiceWorkerVersionId) | 124 if (!version_info.version_uuid.empty()) |
125 return; | 125 return; |
126 version_info_map_.set(version_info.version_id, | 126 version_info_map_.set(version_info.version_uuid, |
127 scoped_ptr<ServiceWorkerVersionInfo>( | 127 scoped_ptr<ServiceWorkerVersionInfo>( |
128 new ServiceWorkerVersionInfo(version_info))); | 128 new ServiceWorkerVersionInfo(version_info))); |
129 } | 129 } |
130 | 130 |
131 void ServiceWorkerContextWatcher::SendRegistrationInfo( | 131 void ServiceWorkerContextWatcher::SendRegistrationInfo( |
132 int64 registration_id, | 132 int64 registration_id, |
133 const GURL& pattern, | 133 const GURL& pattern, |
134 ServiceWorkerRegistrationInfo::DeleteFlag delete_flag) { | 134 ServiceWorkerRegistrationInfo::DeleteFlag delete_flag) { |
135 std::vector<ServiceWorkerRegistrationInfo> registrations; | 135 std::vector<ServiceWorkerRegistrationInfo> registrations; |
136 registrations.push_back( | 136 registrations.push_back( |
(...skipping 10 matching lines...) Expand all Loading... |
147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 147 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
148 base::Bind(version_callback_, versions)); | 148 base::Bind(version_callback_, versions)); |
149 } | 149 } |
150 | 150 |
151 void ServiceWorkerContextWatcher::OnNewLiveRegistration(int64 registration_id, | 151 void ServiceWorkerContextWatcher::OnNewLiveRegistration(int64 registration_id, |
152 const GURL& pattern) { | 152 const GURL& pattern) { |
153 SendRegistrationInfo(registration_id, pattern, | 153 SendRegistrationInfo(registration_id, pattern, |
154 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 154 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
155 } | 155 } |
156 | 156 |
157 void ServiceWorkerContextWatcher::OnNewLiveVersion(int64 version_id, | 157 void ServiceWorkerContextWatcher::OnNewLiveVersion(std::string version_uuid, |
158 int64 registration_id, | 158 int64 registration_id, |
159 const GURL& script_url) { | 159 const GURL& script_url) { |
160 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_id)) { | 160 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid)) { |
161 DCHECK_EQ(version->registration_id, registration_id); | 161 DCHECK_EQ(version->registration_id, registration_id); |
162 DCHECK_EQ(version->script_url, script_url); | 162 DCHECK_EQ(version->script_url, script_url); |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 scoped_ptr<ServiceWorkerVersionInfo> version(new ServiceWorkerVersionInfo()); | 166 scoped_ptr<ServiceWorkerVersionInfo> version(new ServiceWorkerVersionInfo()); |
167 version->version_id = version_id; | 167 version->version_uuid = version_uuid; |
168 version->registration_id = registration_id; | 168 version->registration_id = registration_id; |
169 version->script_url = script_url; | 169 version->script_url = script_url; |
170 SendVersionInfo(*version); | 170 SendVersionInfo(*version); |
171 if (!IsStoppedAndRedundant(*version)) | 171 if (!IsStoppedAndRedundant(*version)) |
172 version_info_map_.set(version_id, version.Pass()); | 172 version_info_map_.set(version_uuid, version.Pass()); |
173 } | 173 } |
174 | 174 |
175 void ServiceWorkerContextWatcher::OnRunningStateChanged( | 175 void ServiceWorkerContextWatcher::OnRunningStateChanged( |
176 int64 version_id, | 176 std::string version_uuid, |
177 content::ServiceWorkerVersion::RunningStatus running_status) { | 177 content::ServiceWorkerVersion::RunningStatus running_status) { |
178 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 178 ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid); |
179 DCHECK(version); | 179 DCHECK(version); |
180 if (version->running_status == running_status) | 180 if (version->running_status == running_status) |
181 return; | 181 return; |
182 version->running_status = running_status; | 182 version->running_status = running_status; |
183 SendVersionInfo(*version); | 183 SendVersionInfo(*version); |
184 if (IsStoppedAndRedundant(*version)) | 184 if (IsStoppedAndRedundant(*version)) |
185 version_info_map_.erase(version_id); | 185 version_info_map_.erase(version_uuid); |
186 } | 186 } |
187 | 187 |
188 void ServiceWorkerContextWatcher::OnVersionStateChanged( | 188 void ServiceWorkerContextWatcher::OnVersionStateChanged( |
189 int64 version_id, | 189 std::string version_uuid, |
190 content::ServiceWorkerVersion::Status status) { | 190 content::ServiceWorkerVersion::Status status) { |
191 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 191 ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid); |
192 DCHECK(version); | 192 DCHECK(version); |
193 if (version->status == status) | 193 if (version->status == status) |
194 return; | 194 return; |
195 version->status = status; | 195 version->status = status; |
196 SendVersionInfo(*version); | 196 SendVersionInfo(*version); |
197 if (IsStoppedAndRedundant(*version)) | 197 if (IsStoppedAndRedundant(*version)) |
198 version_info_map_.erase(version_id); | 198 version_info_map_.erase(version_uuid); |
199 } | 199 } |
200 | 200 |
201 void ServiceWorkerContextWatcher::OnMainScriptHttpResponseInfoSet( | 201 void ServiceWorkerContextWatcher::OnMainScriptHttpResponseInfoSet( |
202 int64 version_id, | 202 std::string version_uuid, |
203 base::Time script_response_time, | 203 base::Time script_response_time, |
204 base::Time script_last_modified) { | 204 base::Time script_last_modified) { |
205 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 205 ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid); |
206 DCHECK(version); | 206 DCHECK(version); |
207 version->script_response_time = script_response_time; | 207 version->script_response_time = script_response_time; |
208 version->script_last_modified = script_last_modified; | 208 version->script_last_modified = script_last_modified; |
209 SendVersionInfo(*version); | 209 SendVersionInfo(*version); |
210 } | 210 } |
211 | 211 |
212 void ServiceWorkerContextWatcher::OnErrorReported(int64 version_id, | 212 void ServiceWorkerContextWatcher::OnErrorReported(std::string version_uuid, |
213 int process_id, | 213 int process_id, |
214 int thread_id, | 214 int thread_id, |
215 const ErrorInfo& info) { | 215 const ErrorInfo& info) { |
216 int64 registration_id = kInvalidServiceWorkerRegistrationId; | 216 int64 registration_id = kInvalidServiceWorkerRegistrationId; |
217 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_id)) | 217 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid)) |
218 registration_id = version->registration_id; | 218 registration_id = version->registration_id; |
219 BrowserThread::PostTask( | 219 BrowserThread::PostTask( |
220 BrowserThread::UI, FROM_HERE, | 220 BrowserThread::UI, FROM_HERE, |
221 base::Bind(error_callback_, registration_id, version_id, info)); | 221 base::Bind(error_callback_, registration_id, version_uuid, info)); |
222 } | 222 } |
223 | 223 |
224 void ServiceWorkerContextWatcher::OnReportConsoleMessage( | 224 void ServiceWorkerContextWatcher::OnReportConsoleMessage( |
225 int64 version_id, | 225 std::string version_uuid, |
226 int process_id, | 226 int process_id, |
227 int thread_id, | 227 int thread_id, |
228 const ConsoleMessage& message) { | 228 const ConsoleMessage& message) { |
229 if (message.message_level != CONSOLE_MESSAGE_LEVEL_ERROR) | 229 if (message.message_level != CONSOLE_MESSAGE_LEVEL_ERROR) |
230 return; | 230 return; |
231 int64 registration_id = kInvalidServiceWorkerRegistrationId; | 231 int64 registration_id = kInvalidServiceWorkerRegistrationId; |
232 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_id)) | 232 if (ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid)) |
233 registration_id = version->registration_id; | 233 registration_id = version->registration_id; |
234 BrowserThread::PostTask( | 234 BrowserThread::PostTask( |
235 BrowserThread::UI, FROM_HERE, | 235 BrowserThread::UI, FROM_HERE, |
236 base::Bind(error_callback_, registration_id, version_id, | 236 base::Bind(error_callback_, registration_id, version_uuid, |
237 ErrorInfo(message.message, message.line_number, -1, | 237 ErrorInfo(message.message, message.line_number, -1, |
238 message.source_url))); | 238 message.source_url))); |
239 } | 239 } |
240 | 240 |
241 void ServiceWorkerContextWatcher::OnControlleeAdded( | 241 void ServiceWorkerContextWatcher::OnControlleeAdded( |
242 int64 version_id, | 242 std::string version_uuid, |
243 const std::string& uuid, | 243 const std::string& uuid, |
244 int process_id, | 244 int process_id, |
245 int route_id, | 245 int route_id, |
246 ServiceWorkerProviderType type) { | 246 ServiceWorkerProviderType type) { |
247 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 247 ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid); |
248 DCHECK(version); | 248 DCHECK(version); |
249 version->clients[uuid] = | 249 version->clients[uuid] = |
250 ServiceWorkerVersionInfo::ClientInfo(process_id, route_id, type); | 250 ServiceWorkerVersionInfo::ClientInfo(process_id, route_id, type); |
251 SendVersionInfo(*version); | 251 SendVersionInfo(*version); |
252 } | 252 } |
253 | 253 |
254 void ServiceWorkerContextWatcher::OnControlleeRemoved(int64 version_id, | 254 void ServiceWorkerContextWatcher::OnControlleeRemoved(std::string version_uuid, |
255 const std::string& uuid) { | 255 const std::string& uuid) { |
256 ServiceWorkerVersionInfo* version = version_info_map_.get(version_id); | 256 ServiceWorkerVersionInfo* version = version_info_map_.get(version_uuid); |
257 DCHECK(version); | 257 DCHECK(version); |
258 version->clients.erase(uuid); | 258 version->clients.erase(uuid); |
259 SendVersionInfo(*version); | 259 SendVersionInfo(*version); |
260 } | 260 } |
261 | 261 |
262 void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id, | 262 void ServiceWorkerContextWatcher::OnRegistrationStored(int64 registration_id, |
263 const GURL& pattern) { | 263 const GURL& pattern) { |
264 SendRegistrationInfo(registration_id, pattern, | 264 SendRegistrationInfo(registration_id, pattern, |
265 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); | 265 ServiceWorkerRegistrationInfo::IS_NOT_DELETED); |
266 } | 266 } |
267 | 267 |
268 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, | 268 void ServiceWorkerContextWatcher::OnRegistrationDeleted(int64 registration_id, |
269 const GURL& pattern) { | 269 const GURL& pattern) { |
270 SendRegistrationInfo(registration_id, pattern, | 270 SendRegistrationInfo(registration_id, pattern, |
271 ServiceWorkerRegistrationInfo::IS_DELETED); | 271 ServiceWorkerRegistrationInfo::IS_DELETED); |
272 } | 272 } |
273 | 273 |
274 } // namespace content | 274 } // namespace content |
OLD | NEW |