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_core.h" | 5 #include "content/browser/service_worker/service_worker_context_core.h" |
6 | 6 |
7 #include "base/barrier_closure.h" | 7 #include "base/barrier_closure.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 job_coordinator_->Register( | 264 job_coordinator_->Register( |
265 pattern, | 265 pattern, |
266 script_url, | 266 script_url, |
267 provider_host, | 267 provider_host, |
268 base::Bind(&ServiceWorkerContextCore::RegistrationComplete, | 268 base::Bind(&ServiceWorkerContextCore::RegistrationComplete, |
269 AsWeakPtr(), | 269 AsWeakPtr(), |
270 pattern, | 270 pattern, |
271 callback)); | 271 callback)); |
272 } | 272 } |
273 | 273 |
| 274 void ServiceWorkerContextCore::UpdateServiceWorker( |
| 275 ServiceWorkerRegistration* registration, |
| 276 bool force_bypass_cache) { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 278 if (storage()->IsDisabled()) |
| 279 return; |
| 280 |
| 281 job_coordinator_->Update(registration, force_bypass_cache); |
| 282 } |
| 283 |
| 284 void ServiceWorkerContextCore::UpdateServiceWorker( |
| 285 ServiceWorkerRegistration* registration, |
| 286 bool force_bypass_cache, |
| 287 ServiceWorkerProviderHost* provider_host, |
| 288 const UpdateCallback& callback) { |
| 289 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 290 if (storage()->IsDisabled()) { |
| 291 callback.Run(SERVICE_WORKER_ERROR_ABORT, std::string(), |
| 292 kInvalidServiceWorkerRegistrationId); |
| 293 return; |
| 294 } |
| 295 |
| 296 job_coordinator_->Update(registration, force_bypass_cache, provider_host, |
| 297 base::Bind(&ServiceWorkerContextCore::UpdateComplete, |
| 298 AsWeakPtr(), callback)); |
| 299 } |
| 300 |
274 void ServiceWorkerContextCore::UnregisterServiceWorker( | 301 void ServiceWorkerContextCore::UnregisterServiceWorker( |
275 const GURL& pattern, | 302 const GURL& pattern, |
276 const UnregistrationCallback& callback) { | 303 const UnregistrationCallback& callback) { |
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
278 if (storage()->IsDisabled()) { | 305 if (storage()->IsDisabled()) { |
279 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 306 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
280 return; | 307 return; |
281 } | 308 } |
282 | 309 |
283 job_coordinator_->Unregister( | 310 job_coordinator_->Unregister( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 scopes.size(), | 345 scopes.size(), |
319 base::Bind( | 346 base::Bind( |
320 &SuccessReportingCallback, base::Owned(overall_success), result)); | 347 &SuccessReportingCallback, base::Owned(overall_success), result)); |
321 | 348 |
322 for (const GURL& scope : scopes) { | 349 for (const GURL& scope : scopes) { |
323 UnregisterServiceWorker( | 350 UnregisterServiceWorker( |
324 scope, base::Bind(&SuccessCollectorCallback, barrier, overall_success)); | 351 scope, base::Bind(&SuccessCollectorCallback, barrier, overall_success)); |
325 } | 352 } |
326 } | 353 } |
327 | 354 |
328 void ServiceWorkerContextCore::UpdateServiceWorker( | |
329 ServiceWorkerRegistration* registration, | |
330 bool force_bypass_cache) { | |
331 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
332 if (storage()->IsDisabled()) | |
333 return; | |
334 job_coordinator_->Update(registration, force_bypass_cache); | |
335 } | |
336 | |
337 void ServiceWorkerContextCore::RegistrationComplete( | 355 void ServiceWorkerContextCore::RegistrationComplete( |
338 const GURL& pattern, | 356 const GURL& pattern, |
339 const ServiceWorkerContextCore::RegistrationCallback& callback, | 357 const ServiceWorkerContextCore::RegistrationCallback& callback, |
340 ServiceWorkerStatusCode status, | 358 ServiceWorkerStatusCode status, |
341 const std::string& status_message, | 359 const std::string& status_message, |
342 ServiceWorkerRegistration* registration) { | 360 ServiceWorkerRegistration* registration) { |
343 if (status != SERVICE_WORKER_OK) { | 361 if (status != SERVICE_WORKER_OK) { |
344 DCHECK(!registration); | 362 DCHECK(!registration); |
345 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); | 363 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); |
346 return; | 364 return; |
347 } | 365 } |
348 | 366 |
349 DCHECK(registration); | 367 DCHECK(registration); |
350 callback.Run(status, status_message, registration->id()); | 368 callback.Run(status, status_message, registration->id()); |
351 // TODO(falken): At this point the registration promise is resolved, but we | 369 // TODO(falken): At this point the registration promise is resolved, but we |
352 // haven't persisted anything to storage yet. So we should either call | 370 // haven't persisted anything to storage yet. So we should either call |
353 // OnRegistrationStored somewhere else or change its name. | 371 // OnRegistrationStored somewhere else or change its name. |
354 if (observer_list_.get()) { | 372 if (observer_list_.get()) { |
355 observer_list_->Notify(FROM_HERE, | 373 observer_list_->Notify(FROM_HERE, |
356 &ServiceWorkerContextObserver::OnRegistrationStored, | 374 &ServiceWorkerContextObserver::OnRegistrationStored, |
357 registration->id(), pattern); | 375 registration->id(), pattern); |
358 } | 376 } |
359 } | 377 } |
360 | 378 |
| 379 void ServiceWorkerContextCore::UpdateComplete( |
| 380 const ServiceWorkerContextCore::UpdateCallback& callback, |
| 381 ServiceWorkerStatusCode status, |
| 382 const std::string& status_message, |
| 383 ServiceWorkerRegistration* registration) { |
| 384 if (status != SERVICE_WORKER_OK) { |
| 385 DCHECK(!registration); |
| 386 callback.Run(status, status_message, kInvalidServiceWorkerRegistrationId); |
| 387 return; |
| 388 } |
| 389 |
| 390 DCHECK(registration); |
| 391 callback.Run(status, status_message, registration->id()); |
| 392 } |
| 393 |
361 void ServiceWorkerContextCore::UnregistrationComplete( | 394 void ServiceWorkerContextCore::UnregistrationComplete( |
362 const GURL& pattern, | 395 const GURL& pattern, |
363 const ServiceWorkerContextCore::UnregistrationCallback& callback, | 396 const ServiceWorkerContextCore::UnregistrationCallback& callback, |
364 int64 registration_id, | 397 int64 registration_id, |
365 ServiceWorkerStatusCode status) { | 398 ServiceWorkerStatusCode status) { |
366 callback.Run(status); | 399 callback.Run(status); |
367 if (status == SERVICE_WORKER_OK && observer_list_.get()) { | 400 if (status == SERVICE_WORKER_OK && observer_list_.get()) { |
368 observer_list_->Notify(FROM_HERE, | 401 observer_list_->Notify(FROM_HERE, |
369 &ServiceWorkerContextObserver::OnRegistrationDeleted, | 402 &ServiceWorkerContextObserver::OnRegistrationDeleted, |
370 registration_id, pattern); | 403 registration_id, pattern); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 observer_list_->Notify(FROM_HERE, | 623 observer_list_->Notify(FROM_HERE, |
591 &ServiceWorkerContextObserver::OnControlleeRemoved, | 624 &ServiceWorkerContextObserver::OnControlleeRemoved, |
592 version->version_id(), provider_host->client_uuid()); | 625 version->version_id(), provider_host->client_uuid()); |
593 } | 626 } |
594 | 627 |
595 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 628 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
596 return wrapper_->process_manager(); | 629 return wrapper_->process_manager(); |
597 } | 630 } |
598 | 631 |
599 } // namespace content | 632 } // namespace content |
OLD | NEW |