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_.get()) { |
nhiroki
2015/09/02 06:15:38
nit: How about removing ".get()" like line 149?
falken
2015/09/02 06:28:09
Done.
| |
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 16 matching lines...) Expand all Loading... | |
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_.get()) { |
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_.get()) |
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_.get()) { |
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_.get()) { |
nhiroki
2015/09/02 06:15:38
nit: Can you remove {}?
falken
2015/09/02 06:28:09
Done.
| |
297 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
298 return; | 291 return; |
299 } | 292 } |
300 ServiceWorkerVersion* version = GetLiveVersion(version_id); | 293 ServiceWorkerVersion* version = GetLiveVersion(version_id); |
301 if (!version || version->skip_waiting()) | 294 if (!version || version->skip_waiting()) |
302 return; | 295 return; |
303 ServiceWorkerRegistration* registration = | 296 ServiceWorkerRegistration* registration = |
304 GetLiveRegistration(version->registration_id()); | 297 GetLiveRegistration(version->registration_id()); |
305 if (!registration || version != registration->waiting_version()) | 298 if (!registration || version != registration->waiting_version()) |
306 return; | 299 return; |
307 version->set_skip_waiting(true); | 300 version->set_skip_waiting(true); |
(...skipping 17 matching lines...) Expand all Loading... | |
325 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
326 context()->storage()->FindRegistrationForDocument( | 319 context()->storage()->FindRegistrationForDocument( |
327 net::SimplifyUrlForRequest(url), | 320 net::SimplifyUrlForRequest(url), |
328 base::Bind(&DidFindRegistrationForDocument, callback)); | 321 base::Bind(&DidFindRegistrationForDocument, callback)); |
329 } | 322 } |
330 | 323 |
331 void ServiceWorkerContextWrapper::GetAllOriginsInfo( | 324 void ServiceWorkerContextWrapper::GetAllOriginsInfo( |
332 const GetUsageInfoCallback& callback) { | 325 const GetUsageInfoCallback& callback) { |
333 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 326 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
334 if (!context_core_.get()) { | 327 if (!context_core_.get()) { |
335 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
336 BrowserThread::PostTask( | 328 BrowserThread::PostTask( |
337 BrowserThread::IO, | 329 BrowserThread::IO, |
338 FROM_HERE, | 330 FROM_HERE, |
339 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); | 331 base::Bind(callback, std::vector<ServiceWorkerUsageInfo>())); |
340 return; | 332 return; |
341 } | 333 } |
342 context()->storage()->GetAllRegistrationsInfos(base::Bind( | 334 context()->storage()->GetAllRegistrationsInfos(base::Bind( |
343 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins, | 335 &ServiceWorkerContextWrapper::DidGetAllRegistrationsForGetAllOrigins, |
344 this, callback)); | 336 this, callback)); |
345 } | 337 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 registration->pattern(), other_url))); | 380 registration->pattern(), other_url))); |
389 } | 381 } |
390 | 382 |
391 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( | 383 void ServiceWorkerContextWrapper::DidFindRegistrationForUpdate( |
392 ServiceWorkerStatusCode status, | 384 ServiceWorkerStatusCode status, |
393 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 385 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
394 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 386 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
395 | 387 |
396 if (status != SERVICE_WORKER_OK) | 388 if (status != SERVICE_WORKER_OK) |
397 return; | 389 return; |
398 if (!context_core_.get()) { | 390 if (!context_core_.get()) |
399 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
400 return; | 391 return; |
401 } | |
402 DCHECK(registration); | 392 DCHECK(registration); |
403 context_core_->UpdateServiceWorker(registration.get(), | 393 context_core_->UpdateServiceWorker(registration.get(), |
404 true /* force_bypass_cache */); | 394 true /* force_bypass_cache */); |
405 } | 395 } |
406 | 396 |
407 namespace { | 397 namespace { |
408 void StatusCodeToBoolCallbackAdapter( | 398 void StatusCodeToBoolCallbackAdapter( |
409 const ServiceWorkerContext::ResultCallback& callback, | 399 const ServiceWorkerContext::ResultCallback& callback, |
410 ServiceWorkerStatusCode code) { | 400 ServiceWorkerStatusCode code) { |
411 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); | 401 callback.Run(code == ServiceWorkerStatusCode::SERVICE_WORKER_OK); |
412 } | 402 } |
413 | 403 |
414 void EmptySuccessCallback(bool success) { | 404 void EmptySuccessCallback(bool success) { |
415 } | 405 } |
416 } // namespace | 406 } // namespace |
417 | 407 |
418 void ServiceWorkerContextWrapper::DeleteForOrigin( | 408 void ServiceWorkerContextWrapper::DeleteForOrigin( |
419 const GURL& origin, | 409 const GURL& origin, |
420 const ResultCallback& result) { | 410 const ResultCallback& result) { |
421 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 411 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
422 if (!context_core_.get()) { | 412 if (!context_core_.get()) { |
423 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
424 BrowserThread::PostTask( | 413 BrowserThread::PostTask( |
425 BrowserThread::IO, | 414 BrowserThread::IO, |
426 FROM_HERE, | 415 FROM_HERE, |
427 base::Bind(result, false)); | 416 base::Bind(result, false)); |
428 return; | 417 return; |
429 } | 418 } |
430 context()->UnregisterServiceWorkers( | 419 context()->UnregisterServiceWorkers( |
431 origin.GetOrigin(), base::Bind(&StatusCodeToBoolCallbackAdapter, result)); | 420 origin.GetOrigin(), base::Bind(&StatusCodeToBoolCallbackAdapter, result)); |
432 } | 421 } |
433 | 422 |
434 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin) { | 423 void ServiceWorkerContextWrapper::DeleteForOrigin(const GURL& origin) { |
435 DeleteForOrigin(origin, base::Bind(&EmptySuccessCallback)); | 424 DeleteForOrigin(origin, base::Bind(&EmptySuccessCallback)); |
436 } | 425 } |
437 | 426 |
438 void ServiceWorkerContextWrapper::CheckHasServiceWorker( | 427 void ServiceWorkerContextWrapper::CheckHasServiceWorker( |
439 const GURL& url, | 428 const GURL& url, |
440 const GURL& other_url, | 429 const GURL& other_url, |
441 const CheckHasServiceWorkerCallback& callback) { | 430 const CheckHasServiceWorkerCallback& callback) { |
442 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 431 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
443 BrowserThread::PostTask( | 432 BrowserThread::PostTask( |
444 BrowserThread::IO, FROM_HERE, | 433 BrowserThread::IO, FROM_HERE, |
445 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this, | 434 base::Bind(&ServiceWorkerContextWrapper::CheckHasServiceWorker, this, |
446 url, other_url, callback)); | 435 url, other_url, callback)); |
447 return; | 436 return; |
448 } | 437 } |
449 if (!context_core_.get()) { | 438 if (!context_core_.get()) { |
450 LOG(ERROR) << "ServiceWorkerContextCore is no longer alive."; | |
451 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 439 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
452 base::Bind(callback, false)); | 440 base::Bind(callback, false)); |
453 return; | 441 return; |
454 } | 442 } |
455 context()->storage()->FindRegistrationForDocument( | 443 context()->storage()->FindRegistrationForDocument( |
456 net::SimplifyUrlForRequest(url), | 444 net::SimplifyUrlForRequest(url), |
457 base::Bind(&ServiceWorkerContextWrapper:: | 445 base::Bind(&ServiceWorkerContextWrapper:: |
458 DidFindRegistrationForCheckHasServiceWorker, | 446 DidFindRegistrationForCheckHasServiceWorker, |
459 this, net::SimplifyUrlForRequest(other_url), callback)); | 447 this, net::SimplifyUrlForRequest(other_url), callback)); |
460 } | 448 } |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 observer_list_->Notify(FROM_HERE, | 631 observer_list_->Notify(FROM_HERE, |
644 &ServiceWorkerContextObserver::OnStorageWiped); | 632 &ServiceWorkerContextObserver::OnStorageWiped); |
645 } | 633 } |
646 | 634 |
647 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 635 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
648 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 636 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
649 return context_core_.get(); | 637 return context_core_.get(); |
650 } | 638 } |
651 | 639 |
652 } // namespace content | 640 } // namespace content |
OLD | NEW |