| 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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 observer_list_->Notify(FROM_HERE, | 384 observer_list_->Notify(FROM_HERE, |
| 385 &ServiceWorkerContextObserver::OnNewLiveRegistration, | 385 &ServiceWorkerContextObserver::OnNewLiveRegistration, |
| 386 registration->id(), registration->pattern()); | 386 registration->id(), registration->pattern()); |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 | 389 |
| 390 void ServiceWorkerContextCore::RemoveLiveRegistration(int64 id) { | 390 void ServiceWorkerContextCore::RemoveLiveRegistration(int64 id) { |
| 391 live_registrations_.erase(id); | 391 live_registrations_.erase(id); |
| 392 } | 392 } |
| 393 | 393 |
| 394 ServiceWorkerVersion* ServiceWorkerContextCore::GetLiveVersion( | 394 ServiceWorkerVersion* ServiceWorkerContextCore::GetLiveVersion(std::string id) { |
| 395 int64 id) { | |
| 396 VersionMap::iterator it = live_versions_.find(id); | 395 VersionMap::iterator it = live_versions_.find(id); |
| 397 return (it != live_versions_.end()) ? it->second : NULL; | 396 return (it != live_versions_.end()) ? it->second : NULL; |
| 398 } | 397 } |
| 399 | 398 |
| 400 void ServiceWorkerContextCore::AddLiveVersion(ServiceWorkerVersion* version) { | 399 void ServiceWorkerContextCore::AddLiveVersion(ServiceWorkerVersion* version) { |
| 401 DCHECK(!GetLiveVersion(version->version_id())); | 400 DCHECK(!GetLiveVersion(version->version_uuid())); |
| 402 live_versions_[version->version_id()] = version; | 401 live_versions_[version->version_uuid()] = version; |
| 403 version->AddListener(this); | 402 version->AddListener(this); |
| 404 if (observer_list_.get()) { | 403 if (observer_list_.get()) { |
| 405 observer_list_->Notify(FROM_HERE, | 404 observer_list_->Notify(FROM_HERE, |
| 406 &ServiceWorkerContextObserver::OnNewLiveVersion, | 405 &ServiceWorkerContextObserver::OnNewLiveVersion, |
| 407 version->version_id(), version->registration_id(), | 406 version->version_uuid(), version->registration_id(), |
| 408 version->script_url()); | 407 version->script_url()); |
| 409 } | 408 } |
| 410 } | 409 } |
| 411 | 410 |
| 412 void ServiceWorkerContextCore::RemoveLiveVersion(int64 id) { | 411 void ServiceWorkerContextCore::RemoveLiveVersion(std::string version_uuid) { |
| 413 live_versions_.erase(id); | 412 live_versions_.erase(version_uuid); |
| 414 } | 413 } |
| 415 | 414 |
| 416 std::vector<ServiceWorkerRegistrationInfo> | 415 std::vector<ServiceWorkerRegistrationInfo> |
| 417 ServiceWorkerContextCore::GetAllLiveRegistrationInfo() { | 416 ServiceWorkerContextCore::GetAllLiveRegistrationInfo() { |
| 418 std::vector<ServiceWorkerRegistrationInfo> infos; | 417 std::vector<ServiceWorkerRegistrationInfo> infos; |
| 419 for (std::map<int64, ServiceWorkerRegistration*>::const_iterator iter = | 418 for (std::map<int64, ServiceWorkerRegistration*>::const_iterator iter = |
| 420 live_registrations_.begin(); | 419 live_registrations_.begin(); |
| 421 iter != live_registrations_.end(); | 420 iter != live_registrations_.end(); |
| 422 ++iter) { | 421 ++iter) { |
| 423 infos.push_back(iter->second->GetInfo()); | 422 infos.push_back(iter->second->GetInfo()); |
| 424 } | 423 } |
| 425 return infos; | 424 return infos; |
| 426 } | 425 } |
| 427 | 426 |
| 428 std::vector<ServiceWorkerVersionInfo> | 427 std::vector<ServiceWorkerVersionInfo> |
| 429 ServiceWorkerContextCore::GetAllLiveVersionInfo() { | 428 ServiceWorkerContextCore::GetAllLiveVersionInfo() { |
| 430 std::vector<ServiceWorkerVersionInfo> infos; | 429 std::vector<ServiceWorkerVersionInfo> infos; |
| 431 for (std::map<int64, ServiceWorkerVersion*>::const_iterator iter = | 430 for (std::map<std::string, ServiceWorkerVersion*>::const_iterator iter = |
| 432 live_versions_.begin(); | 431 live_versions_.begin(); |
| 433 iter != live_versions_.end(); | 432 iter != live_versions_.end(); ++iter) { |
| 434 ++iter) { | |
| 435 infos.push_back(iter->second->GetInfo()); | 433 infos.push_back(iter->second->GetInfo()); |
| 436 } | 434 } |
| 437 return infos; | 435 return infos; |
| 438 } | 436 } |
| 439 | 437 |
| 440 void ServiceWorkerContextCore::ProtectVersion( | 438 void ServiceWorkerContextCore::ProtectVersion( |
| 441 const scoped_refptr<ServiceWorkerVersion>& version) { | 439 const scoped_refptr<ServiceWorkerVersion>& version) { |
| 442 DCHECK(protected_versions_.find(version->version_id()) == | 440 DCHECK(protected_versions_.find(version->version_uuid()) == |
| 443 protected_versions_.end()); | 441 protected_versions_.end()); |
| 444 protected_versions_[version->version_id()] = version; | 442 protected_versions_[version->version_uuid()] = version; |
| 445 } | 443 } |
| 446 | 444 |
| 447 void ServiceWorkerContextCore::UnprotectVersion(int64 version_id) { | 445 void ServiceWorkerContextCore::UnprotectVersion(std::string version_uuid) { |
| 448 DCHECK(protected_versions_.find(version_id) != protected_versions_.end()); | 446 DCHECK(protected_versions_.find(version_uuid) != protected_versions_.end()); |
| 449 protected_versions_.erase(version_id); | 447 protected_versions_.erase(version_uuid); |
| 450 } | 448 } |
| 451 | 449 |
| 452 int ServiceWorkerContextCore::GetNewServiceWorkerHandleId() { | 450 int ServiceWorkerContextCore::GetNewServiceWorkerHandleId() { |
| 453 return next_handle_id_++; | 451 return next_handle_id_++; |
| 454 } | 452 } |
| 455 | 453 |
| 456 int ServiceWorkerContextCore::GetNewRegistrationHandleId() { | 454 int ServiceWorkerContextCore::GetNewRegistrationHandleId() { |
| 457 return next_registration_handle_id_++; | 455 return next_registration_handle_id_++; |
| 458 } | 456 } |
| 459 | 457 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 map->Replace(new_provider_id, transferee.release()); | 499 map->Replace(new_provider_id, transferee.release()); |
| 502 delete temp; | 500 delete temp; |
| 503 } | 501 } |
| 504 | 502 |
| 505 void ServiceWorkerContextCore::OnRunningStateChanged( | 503 void ServiceWorkerContextCore::OnRunningStateChanged( |
| 506 ServiceWorkerVersion* version) { | 504 ServiceWorkerVersion* version) { |
| 507 if (!observer_list_) | 505 if (!observer_list_) |
| 508 return; | 506 return; |
| 509 observer_list_->Notify(FROM_HERE, | 507 observer_list_->Notify(FROM_HERE, |
| 510 &ServiceWorkerContextObserver::OnRunningStateChanged, | 508 &ServiceWorkerContextObserver::OnRunningStateChanged, |
| 511 version->version_id(), version->running_status()); | 509 version->version_uuid(), version->running_status()); |
| 512 } | 510 } |
| 513 | 511 |
| 514 void ServiceWorkerContextCore::OnVersionStateChanged( | 512 void ServiceWorkerContextCore::OnVersionStateChanged( |
| 515 ServiceWorkerVersion* version) { | 513 ServiceWorkerVersion* version) { |
| 516 if (!observer_list_) | 514 if (!observer_list_) |
| 517 return; | 515 return; |
| 518 observer_list_->Notify(FROM_HERE, | 516 observer_list_->Notify(FROM_HERE, |
| 519 &ServiceWorkerContextObserver::OnVersionStateChanged, | 517 &ServiceWorkerContextObserver::OnVersionStateChanged, |
| 520 version->version_id(), version->status()); | 518 version->version_uuid(), version->status()); |
| 521 } | 519 } |
| 522 | 520 |
| 523 void ServiceWorkerContextCore::OnMainScriptHttpResponseInfoSet( | 521 void ServiceWorkerContextCore::OnMainScriptHttpResponseInfoSet( |
| 524 ServiceWorkerVersion* version) { | 522 ServiceWorkerVersion* version) { |
| 525 if (!observer_list_) | 523 if (!observer_list_) |
| 526 return; | 524 return; |
| 527 const net::HttpResponseInfo* info = version->GetMainScriptHttpResponseInfo(); | 525 const net::HttpResponseInfo* info = version->GetMainScriptHttpResponseInfo(); |
| 528 DCHECK(info); | 526 DCHECK(info); |
| 529 base::Time lastModified; | 527 base::Time lastModified; |
| 530 if (info->headers) | 528 if (info->headers) |
| 531 info->headers->GetLastModifiedValue(&lastModified); | 529 info->headers->GetLastModifiedValue(&lastModified); |
| 532 observer_list_->Notify( | 530 observer_list_->Notify( |
| 533 FROM_HERE, &ServiceWorkerContextObserver::OnMainScriptHttpResponseInfoSet, | 531 FROM_HERE, &ServiceWorkerContextObserver::OnMainScriptHttpResponseInfoSet, |
| 534 version->version_id(), info->response_time, lastModified); | 532 version->version_uuid(), info->response_time, lastModified); |
| 535 } | 533 } |
| 536 | 534 |
| 537 void ServiceWorkerContextCore::OnErrorReported( | 535 void ServiceWorkerContextCore::OnErrorReported( |
| 538 ServiceWorkerVersion* version, | 536 ServiceWorkerVersion* version, |
| 539 const base::string16& error_message, | 537 const base::string16& error_message, |
| 540 int line_number, | 538 int line_number, |
| 541 int column_number, | 539 int column_number, |
| 542 const GURL& source_url) { | 540 const GURL& source_url) { |
| 543 if (!observer_list_) | 541 if (!observer_list_) |
| 544 return; | 542 return; |
| 545 observer_list_->Notify( | 543 observer_list_->Notify( |
| 546 FROM_HERE, &ServiceWorkerContextObserver::OnErrorReported, | 544 FROM_HERE, &ServiceWorkerContextObserver::OnErrorReported, |
| 547 version->version_id(), version->embedded_worker()->process_id(), | 545 version->version_uuid(), version->embedded_worker()->process_id(), |
| 548 version->embedded_worker()->thread_id(), | 546 version->embedded_worker()->thread_id(), |
| 549 ServiceWorkerContextObserver::ErrorInfo(error_message, line_number, | 547 ServiceWorkerContextObserver::ErrorInfo(error_message, line_number, |
| 550 column_number, source_url)); | 548 column_number, source_url)); |
| 551 } | 549 } |
| 552 | 550 |
| 553 void ServiceWorkerContextCore::OnReportConsoleMessage( | 551 void ServiceWorkerContextCore::OnReportConsoleMessage( |
| 554 ServiceWorkerVersion* version, | 552 ServiceWorkerVersion* version, |
| 555 int source_identifier, | 553 int source_identifier, |
| 556 int message_level, | 554 int message_level, |
| 557 const base::string16& message, | 555 const base::string16& message, |
| 558 int line_number, | 556 int line_number, |
| 559 const GURL& source_url) { | 557 const GURL& source_url) { |
| 560 if (!observer_list_) | 558 if (!observer_list_) |
| 561 return; | 559 return; |
| 562 observer_list_->Notify( | 560 observer_list_->Notify( |
| 563 FROM_HERE, &ServiceWorkerContextObserver::OnReportConsoleMessage, | 561 FROM_HERE, &ServiceWorkerContextObserver::OnReportConsoleMessage, |
| 564 version->version_id(), version->embedded_worker()->process_id(), | 562 version->version_uuid(), version->embedded_worker()->process_id(), |
| 565 version->embedded_worker()->thread_id(), | 563 version->embedded_worker()->thread_id(), |
| 566 ServiceWorkerContextObserver::ConsoleMessage( | 564 ServiceWorkerContextObserver::ConsoleMessage( |
| 567 source_identifier, message_level, message, line_number, source_url)); | 565 source_identifier, message_level, message, line_number, source_url)); |
| 568 } | 566 } |
| 569 | 567 |
| 570 void ServiceWorkerContextCore::OnControlleeAdded( | 568 void ServiceWorkerContextCore::OnControlleeAdded( |
| 571 ServiceWorkerVersion* version, | 569 ServiceWorkerVersion* version, |
| 572 ServiceWorkerProviderHost* provider_host) { | 570 ServiceWorkerProviderHost* provider_host) { |
| 573 if (!observer_list_) | 571 if (!observer_list_) |
| 574 return; | 572 return; |
| 575 observer_list_->Notify(FROM_HERE, | 573 observer_list_->Notify(FROM_HERE, |
| 576 &ServiceWorkerContextObserver::OnControlleeAdded, | 574 &ServiceWorkerContextObserver::OnControlleeAdded, |
| 577 version->version_id(), provider_host->client_uuid(), | 575 version->version_uuid(), provider_host->client_uuid(), |
| 578 provider_host->process_id(), provider_host->route_id(), | 576 provider_host->process_id(), provider_host->route_id(), |
| 579 provider_host->provider_type()); | 577 provider_host->provider_type()); |
| 580 } | 578 } |
| 581 | 579 |
| 582 void ServiceWorkerContextCore::OnControlleeRemoved( | 580 void ServiceWorkerContextCore::OnControlleeRemoved( |
| 583 ServiceWorkerVersion* version, | 581 ServiceWorkerVersion* version, |
| 584 ServiceWorkerProviderHost* provider_host) { | 582 ServiceWorkerProviderHost* provider_host) { |
| 585 if (!observer_list_) | 583 if (!observer_list_) |
| 586 return; | 584 return; |
| 587 observer_list_->Notify(FROM_HERE, | 585 observer_list_->Notify(FROM_HERE, |
| 588 &ServiceWorkerContextObserver::OnControlleeRemoved, | 586 &ServiceWorkerContextObserver::OnControlleeRemoved, |
| 589 version->version_id(), provider_host->client_uuid()); | 587 version->version_uuid(), provider_host->client_uuid()); |
| 590 } | 588 } |
| 591 | 589 |
| 592 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { | 590 ServiceWorkerProcessManager* ServiceWorkerContextCore::process_manager() { |
| 593 return wrapper_->process_manager(); | 591 return wrapper_->process_manager(); |
| 594 } | 592 } |
| 595 | 593 |
| 596 } // namespace content | 594 } // namespace content |
| OLD | NEW |