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/service_worker_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 FROM_HERE, | 143 FROM_HERE, |
144 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); | 144 base::Bind(&ServiceWorkerContextWrapper::ShutdownOnIO, this)); |
145 } | 145 } |
146 | 146 |
147 void ServiceWorkerContextWrapper::DeleteAndStartOver() { | 147 void ServiceWorkerContextWrapper::DeleteAndStartOver() { |
148 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 148 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
149 if (!context_core_) { | 149 if (!context_core_) { |
150 // The context could be null due to system shutdown or restart failure. In | 150 // The context could be null due to system shutdown or restart failure. In |
151 // either case, we should not have to recover the system, so just return | 151 // either case, we should not have to recover the system, so just return |
152 // here. | 152 // here. |
153 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
154 return; | 153 return; |
155 } | 154 } |
156 context_core_->DeleteAndStartOver( | 155 context_core_->DeleteAndStartOver( |
157 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); | 156 base::Bind(&ServiceWorkerContextWrapper::DidDeleteAndStartOver, this)); |
158 } | 157 } |
159 | 158 |
160 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { | 159 StoragePartitionImpl* ServiceWorkerContextWrapper::storage_partition() const { |
161 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 160 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
162 return storage_partition_; | 161 return storage_partition_; |
163 } | 162 } |
(...skipping 24 matching lines...) Expand all Loading... |
188 BrowserThread::PostTask( | 187 BrowserThread::PostTask( |
189 BrowserThread::IO, | 188 BrowserThread::IO, |
190 FROM_HERE, | 189 FROM_HERE, |
191 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker, | 190 base::Bind(&ServiceWorkerContextWrapper::RegisterServiceWorker, |
192 this, | 191 this, |
193 pattern, | 192 pattern, |
194 script_url, | 193 script_url, |
195 continuation)); | 194 continuation)); |
196 return; | 195 return; |
197 } | 196 } |
198 if (!context_core_.get()) { | 197 if (!context_core_) { |
199 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
200 BrowserThread::PostTask( | 198 BrowserThread::PostTask( |
201 BrowserThread::IO, | 199 BrowserThread::IO, |
202 FROM_HERE, | 200 FROM_HERE, |
203 base::Bind(continuation, false)); | 201 base::Bind(continuation, false)); |
204 return; | 202 return; |
205 } | 203 } |
206 context()->RegisterServiceWorker( | 204 context()->RegisterServiceWorker( |
207 net::SimplifyUrlForRequest(pattern), | 205 net::SimplifyUrlForRequest(pattern), |
208 net::SimplifyUrlForRequest(script_url), NULL /* provider_host */, | 206 net::SimplifyUrlForRequest(script_url), NULL /* provider_host */, |
209 base::Bind(&FinishRegistrationOnIO, continuation)); | 207 base::Bind(&FinishRegistrationOnIO, continuation)); |
(...skipping 15 matching lines...) Expand all Loading... |
225 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 223 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
226 BrowserThread::PostTask( | 224 BrowserThread::PostTask( |
227 BrowserThread::IO, | 225 BrowserThread::IO, |
228 FROM_HERE, | 226 FROM_HERE, |
229 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker, | 227 base::Bind(&ServiceWorkerContextWrapper::UnregisterServiceWorker, |
230 this, | 228 this, |
231 pattern, | 229 pattern, |
232 continuation)); | 230 continuation)); |
233 return; | 231 return; |
234 } | 232 } |
235 if (!context_core_.get()) { | 233 if (!context_core_) { |
236 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
237 BrowserThread::PostTask( | 234 BrowserThread::PostTask( |
238 BrowserThread::IO, | 235 BrowserThread::IO, |
239 FROM_HERE, | 236 FROM_HERE, |
240 base::Bind(continuation, false)); | 237 base::Bind(continuation, false)); |
241 return; | 238 return; |
242 } | 239 } |
243 | 240 |
244 context()->UnregisterServiceWorker( | 241 context()->UnregisterServiceWorker( |
245 net::SimplifyUrlForRequest(pattern), | 242 net::SimplifyUrlForRequest(pattern), |
246 base::Bind(&FinishUnregistrationOnIO, continuation)); | 243 base::Bind(&FinishUnregistrationOnIO, continuation)); |
247 } | 244 } |
248 | 245 |
249 void ServiceWorkerContextWrapper::UpdateRegistration(const GURL& pattern) { | 246 void ServiceWorkerContextWrapper::UpdateRegistration(const GURL& pattern) { |
250 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 247 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
251 BrowserThread::PostTask( | 248 BrowserThread::PostTask( |
252 BrowserThread::IO, FROM_HERE, | 249 BrowserThread::IO, FROM_HERE, |
253 base::Bind(&ServiceWorkerContextWrapper::UpdateRegistration, this, | 250 base::Bind(&ServiceWorkerContextWrapper::UpdateRegistration, this, |
254 pattern)); | 251 pattern)); |
255 return; | 252 return; |
256 } | 253 } |
257 if (!context_core_.get()) { | 254 if (!context_core_) |
258 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
259 return; | 255 return; |
260 } | |
261 context_core_->storage()->FindRegistrationForPattern( | 256 context_core_->storage()->FindRegistrationForPattern( |
262 net::SimplifyUrlForRequest(pattern), | 257 net::SimplifyUrlForRequest(pattern), |
263 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, | 258 base::Bind(&ServiceWorkerContextWrapper::DidFindRegistrationForUpdate, |
264 this)); | 259 this)); |
265 } | 260 } |
266 | 261 |
267 void ServiceWorkerContextWrapper::StartServiceWorker( | 262 void ServiceWorkerContextWrapper::StartServiceWorker( |
268 const GURL& pattern, | 263 const GURL& pattern, |
269 const StatusCallback& callback) { | 264 const StatusCallback& callback) { |
270 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 265 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
271 BrowserThread::PostTask( | 266 BrowserThread::PostTask( |
272 BrowserThread::IO, FROM_HERE, | 267 BrowserThread::IO, FROM_HERE, |
273 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, | 268 base::Bind(&ServiceWorkerContextWrapper::StartServiceWorker, this, |
274 pattern, callback)); | 269 pattern, callback)); |
275 return; | 270 return; |
276 } | 271 } |
277 if (!context_core_.get()) { | 272 if (!context_core_) { |
278 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
279 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 273 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
280 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); | 274 base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); |
281 return; | 275 return; |
282 } | 276 } |
283 context_core_->storage()->FindRegistrationForPattern( | 277 context_core_->storage()->FindRegistrationForPattern( |
284 net::SimplifyUrlForRequest(pattern), | 278 net::SimplifyUrlForRequest(pattern), |
285 base::Bind(&StartActiveWorkerOnIO, callback)); | 279 base::Bind(&StartActiveWorkerOnIO, callback)); |
286 } | 280 } |
287 | 281 |
288 void ServiceWorkerContextWrapper::SimulateSkipWaiting(int64_t version_id) { | 282 void ServiceWorkerContextWrapper::SimulateSkipWaiting(int64_t version_id) { |
289 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 283 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
290 BrowserThread::PostTask( | 284 BrowserThread::PostTask( |
291 BrowserThread::IO, FROM_HERE, | 285 BrowserThread::IO, FROM_HERE, |
292 base::Bind(&ServiceWorkerContextWrapper::SimulateSkipWaiting, this, | 286 base::Bind(&ServiceWorkerContextWrapper::SimulateSkipWaiting, this, |
293 version_id)); | 287 version_id)); |
294 return; | 288 return; |
295 } | 289 } |
296 if (!context_core_.get()) { | 290 if (!context_core_) |
297 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
298 return; | 291 return; |
299 } | |
300 ServiceWorkerVersion* version = GetLiveVersion(version_id); | 292 ServiceWorkerVersion* version = GetLiveVersion(version_id); |
301 if (!version || version->skip_waiting()) | 293 if (!version || version->skip_waiting()) |
302 return; | 294 return; |
303 ServiceWorkerRegistration* registration = | 295 ServiceWorkerRegistration* registration = |
304 GetLiveRegistration(version->registration_id()); | 296 GetLiveRegistration(version->registration_id()); |
305 if (!registration || version != registration->waiting_version()) | 297 if (!registration || version != registration->waiting_version()) |
306 return; | 298 return; |
307 version->set_skip_waiting(true); | 299 version->set_skip_waiting(true); |
308 registration->ActivateWaitingVersionWhenReady(); | 300 registration->ActivateWaitingVersionWhenReady(); |
309 } | 301 } |
(...skipping 14 matching lines...) Expand all Loading... |
324 const net::CompletionCallback& callback) { | 316 const net::CompletionCallback& callback) { |
325 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 317 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
326 context()->storage()->FindRegistrationForDocument( | 318 context()->storage()->FindRegistrationForDocument( |
327 net::SimplifyUrlForRequest(url), | 319 net::SimplifyUrlForRequest(url), |
328 base::Bind(&DidFindRegistrationForDocument, callback)); | 320 base::Bind(&DidFindRegistrationForDocument, callback)); |
329 } | 321 } |
330 | 322 |
331 void ServiceWorkerContextWrapper::GetAllOriginsInfo( | 323 void ServiceWorkerContextWrapper::GetAllOriginsInfo( |
332 const GetUsageInfoCallback& callback) { | 324 const GetUsageInfoCallback& callback) { |
333 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 325 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
334 if (!context_core_.get()) { | 326 if (!context_core_) { |
335 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
336 BrowserThread::PostTask( | 327 BrowserThread::PostTask( |
337 BrowserThread::IO, | 328 BrowserThread::IO, |
338 FROM_HERE, | 329 FROM_HERE, |
339 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); | 330 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); |
340 return; | 331 return; |
341 } | 332 } |
342 context()->storage()->GetAllRegistrationsInfos(base::Bind( | 333 context()->storage()->GetAllRegistrationsInfos(base::Bind( |
343 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins, | 334 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins, |
344 this, callback)); | 335 this, callback)); |
345 } | 336 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 registration->pattern(), other_url))); | 379 registration->pattern(), other_url))); |
389 } | 380 } |
390 | 381 |
391 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( | 382 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( |
392 ServiceWorkerStatusCode status, | 383 ServiceWorkerStatusCode status, |
393 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 384 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 385 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
395 | 386 |
396 if (status != SERVICE_WORKER_OK) | 387 if (status != SERVICE_WORKER_OK) |
397 return; | 388 return; |
398 if (!context_core_.get()) { | 389 if (!context_core_) |
399 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
400 return; | 390 return; |
401 } | |
402 DCHECK(registration); | 391 DCHECK(registration); |
403 context_core_->UpdateServiceWorker(registration.get(), | 392 context_core_->UpdateServiceWorker(registration.get(), |
404 true /* force_bypass_cache */); | 393 true /* force_bypass_cache */); |
405 } | 394 } |
406 | 395 |
407 namespace { | 396 namespace { |
408 void StatusCodeToBoolCallbackAdapter( | 397 void StatusCodeToBoolCallbackAdapter( |
409 const ServiceWorkerContext::ResultCallback& callback, | 398 const ServiceWorkerContext::ResultCallback& callback, |
410 ServiceWorkerStatusCode code) { | 399 ServiceWorkerStatusCode code) { |
411 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); | 400 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); |
412 } | 401 } |
413 | 402 |
414 void EmptySuccessCallback(bool success) { | 403 void EmptySuccessCallback(bool success) { |
415 } | 404 } |
416 } // namespace | 405 } // namespace |
417 | 406 |
418 void ServiceWorkerContextWrapper::DeleteForOrigin( | 407 void ServiceWorkerContextWrapper::DeleteForOrigin( |
419 const GURL& origin, | 408 const GURL& origin, |
420 const ResultCallback& result) { | 409 const ResultCallback& result) { |
421 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 410 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
422 if (!context_core_.get()) { | 411 if (!context_core_) { |
423 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
424 BrowserThread::PostTask( | 412 BrowserThread::PostTask( |
425 BrowserThread::IO, | 413 BrowserThread::IO, |
426 FROM_HERE, | 414 FROM_HERE, |
427 base::Bind(result, false)); | 415 base::Bind(result, false)); |
428 return; | 416 return; |
429 } | 417 } |
430 context()->UnregisterServiceWorkers( | 418 context()->UnregisterServiceWorkers( |
431 origin.GetOrigin(), base::Bind(&StatusCodeToBoolCallbackAdapter, result)); | 419 origin.GetOrigin(), base::Bind(&StatusCodeToBoolCallbackAdapter, result)); |
432 } | 420 } |
433 | 421 |
434 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin) { | 422 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin) { |
435 DeleteForOrigin(origin, base::Bind(&EmptySuccessCallback)); | 423 DeleteForOrigin(origin, base::Bind(&EmptySuccessCallback)); |
436 } | 424 } |
437 | 425 |
438 void ServiceWorkerContextWrapper::CheckHasServiceWorker( | 426 void ServiceWorkerContextWrapper::CheckHasServiceWorker( |
439 const GURL& url, | 427 const GURL& url, |
440 const GURL& other_url, | 428 const GURL& other_url, |
441 const CheckHasServiceWorkerCallback& callback) { | 429 const CheckHasServiceWorkerCallback& callback) { |
442 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 430 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
443 BrowserThread::PostTask( | 431 BrowserThread::PostTask( |
444 BrowserThread::IO, FROM_HERE, | 432 BrowserThread::IO, FROM_HERE, |
445 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this, | 433 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this, |
446 url, other_url, callback)); | 434 url, other_url, callback)); |
447 return; | 435 return; |
448 } | 436 } |
449 if (!context_core_.get()) { | 437 if (!context_core_) { |
450 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
451 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 438 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
452 base::Bind(callback, false)); | 439 base::Bind(callback, false)); |
453 return; | 440 return; |
454 } | 441 } |
455 context()->storage()->FindRegistrationForDocument( | 442 context()->storage()->FindRegistrationForDocument( |
456 net::SimplifyUrlForRequest(url), | 443 net::SimplifyUrlForRequest(url), |
457 base::Bind(&ServiceWorkerContextWrapper:: | 444 base::Bind(&ServiceWorkerContextWrapper:: |
458 DidFindRegistrationForCheckHasServiceWorker, | 445 DidFindRegistrationForCheckHasServiceWorker, |
459 this, net::SimplifyUrlForRequest(other_url), callback)); | 446 this, net::SimplifyUrlForRequest(other_url), callback)); |
460 } | 447 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 observer_list_->Notify(FROM_HERE, | 630 observer_list_->Notify(FROM_HERE, |
644 &ServiceWorkerContextObserver::OnStorageWiped); | 631 &ServiceWorkerContextObserver::OnStorageWiped); |
645 } | 632 } |
646 | 633 |
647 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 634 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
648 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 635 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
649 return context_core_.get(); | 636 return context_core_.get(); |
650 } | 637 } |
651 | 638 |
652 } // namespace content | 639 } // namespace content |
OLD | NEW |