Chromium Code Reviews| 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/browser/message_port_message_filter.h" | 27 #include "content/browser/message_port_message_filter.h" |
| 28 #include "content/browser/message_port_service.h" | 28 #include "content/browser/message_port_service.h" |
| 29 #include "content/browser/service_worker/embedded_worker_instance.h" | 29 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 30 #include "content/browser/service_worker/embedded_worker_registry.h" | 30 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 31 #include "content/browser/service_worker/embedded_worker_status.h" | 31 #include "content/browser/service_worker/embedded_worker_status.h" |
| 32 #include "content/browser/service_worker/service_worker_client_utils.h" | 32 #include "content/browser/service_worker/service_worker_client_utils.h" |
| 33 #include "content/browser/service_worker/service_worker_context_core.h" | 33 #include "content/browser/service_worker/service_worker_context_core.h" |
| 34 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 34 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 35 #include "content/browser/service_worker/service_worker_metrics.h" | 35 #include "content/browser/service_worker/service_worker_metrics.h" |
| 36 #include "content/browser/service_worker/service_worker_registration.h" | 36 #include "content/browser/service_worker/service_worker_registration.h" |
| 37 #include "content/common/origin_trials/trial_token_validator.h" | |
| 37 #include "content/common/service_worker/embedded_worker_messages.h" | 38 #include "content/common/service_worker/embedded_worker_messages.h" |
| 38 #include "content/common/service_worker/embedded_worker_start_params.h" | 39 #include "content/common/service_worker/embedded_worker_start_params.h" |
| 39 #include "content/common/service_worker/service_worker_messages.h" | 40 #include "content/common/service_worker/service_worker_messages.h" |
| 40 #include "content/common/service_worker/service_worker_type_converters.h" | 41 #include "content/common/service_worker/service_worker_type_converters.h" |
| 41 #include "content/common/service_worker/service_worker_utils.h" | 42 #include "content/common/service_worker/service_worker_utils.h" |
| 42 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 43 #include "content/public/browser/content_browser_client.h" | 44 #include "content/public/browser/content_browser_client.h" |
| 44 #include "content/public/browser/render_process_host.h" | 45 #include "content/public/browser/render_process_host.h" |
| 45 #include "content/public/common/content_client.h" | 46 #include "content/public/common/content_client.h" |
| 46 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
| 47 #include "content/public/common/result_codes.h" | 48 #include "content/public/common/result_codes.h" |
| 48 #include "mojo/common/common_type_converters.h" | 49 #include "mojo/common/common_type_converters.h" |
| 49 #include "net/http/http_response_headers.h" | 50 #include "net/http/http_response_headers.h" |
| 50 #include "net/http/http_response_info.h" | 51 #include "net/http/http_response_info.h" |
| 52 #include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h" | |
| 51 | 53 |
| 52 namespace content { | 54 namespace content { |
| 53 | 55 |
| 54 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 56 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
| 55 | 57 |
| 56 namespace { | 58 namespace { |
| 57 | 59 |
| 58 // Time to wait until stopping an idle worker. | 60 // Time to wait until stopping an idle worker. |
| 59 const int kIdleWorkerTimeoutSeconds = 30; | 61 const int kIdleWorkerTimeoutSeconds = 30; |
| 60 | 62 |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 693 else | 695 else |
| 694 embedded_worker_->Stop(); | 696 embedded_worker_->Stop(); |
| 695 } | 697 } |
| 696 if (!context_) | 698 if (!context_) |
| 697 return; | 699 return; |
| 698 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 700 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
| 699 script_cache_map_.GetResources(&resources); | 701 script_cache_map_.GetResources(&resources); |
| 700 context_->storage()->PurgeResources(resources); | 702 context_->storage()->PurgeResources(resources); |
| 701 } | 703 } |
| 702 | 704 |
| 705 void ServiceWorkerVersion::SetValidOriginTrialTokens( | |
| 706 const TrialTokenValidator::FeatureToTokensMap& tokens) { | |
| 707 origin_trial_tokens_ = | |
| 708 base::MakeUnique<TrialTokenValidator::FeatureToTokensMap>(); | |
| 709 for (const auto& feature : tokens) { | |
| 710 for (const std::string& token : feature.second) { | |
| 711 std::string feature_name; | |
| 712 if (TrialTokenValidator::ValidateToken(token, url::Origin(scope()), | |
|
chasej
2016/10/05 23:39:54
ValidateToken() does not currently check if the en
horo
2016/10/06 06:59:25
Done.
| |
| 713 &feature_name) == | |
| 714 blink::WebOriginTrialTokenStatus::Success) { | |
| 715 (*origin_trial_tokens_)[feature.first].push_back(token); | |
| 716 } | |
| 717 } | |
| 718 } | |
| 719 } | |
| 720 | |
| 703 void ServiceWorkerVersion::SetDevToolsAttached(bool attached) { | 721 void ServiceWorkerVersion::SetDevToolsAttached(bool attached) { |
| 704 embedded_worker()->set_devtools_attached(attached); | 722 embedded_worker()->set_devtools_attached(attached); |
| 705 if (stop_when_devtools_detached_ && !attached) { | 723 if (stop_when_devtools_detached_ && !attached) { |
| 706 DCHECK_EQ(REDUNDANT, status()); | 724 DCHECK_EQ(REDUNDANT, status()); |
| 707 if (running_status() == EmbeddedWorkerStatus::STARTING || | 725 if (running_status() == EmbeddedWorkerStatus::STARTING || |
| 708 running_status() == EmbeddedWorkerStatus::RUNNING) { | 726 running_status() == EmbeddedWorkerStatus::RUNNING) { |
| 709 embedded_worker_->Stop(); | 727 embedded_worker_->Stop(); |
| 710 } | 728 } |
| 711 return; | 729 return; |
| 712 } | 730 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 734 | 752 |
| 735 // Reactivate request timeouts, setting them all to the same expiration time. | 753 // Reactivate request timeouts, setting them all to the same expiration time. |
| 736 SetAllRequestExpirations( | 754 SetAllRequestExpirations( |
| 737 base::TimeTicks::Now() + | 755 base::TimeTicks::Now() + |
| 738 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes)); | 756 base::TimeDelta::FromMinutes(kRequestTimeoutMinutes)); |
| 739 } | 757 } |
| 740 | 758 |
| 741 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( | 759 void ServiceWorkerVersion::SetMainScriptHttpResponseInfo( |
| 742 const net::HttpResponseInfo& http_info) { | 760 const net::HttpResponseInfo& http_info) { |
| 743 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); | 761 main_script_http_info_.reset(new net::HttpResponseInfo(http_info)); |
| 762 | |
| 763 // Updates |origin_trial_tokens_| if it is not set yet. This happens when: | |
| 764 // 1) The worer is a new one. | |
| 765 // OR | |
| 766 // 2) The worker is an existing one but the entry in ServiceWorkerDatabase | |
| 767 // was written by old version Chrome, so |origin_trial_tokens| wasn't set | |
| 768 // in the entry. | |
| 769 if (!origin_trial_tokens_) { | |
| 770 origin_trial_tokens_ = TrialTokenValidator::GetValidTokens( | |
| 771 url::Origin(scope()), http_info.headers.get()); | |
| 772 } | |
| 773 | |
| 744 FOR_EACH_OBSERVER(Listener, listeners_, | 774 FOR_EACH_OBSERVER(Listener, listeners_, |
| 745 OnMainScriptHttpResponseInfoSet(this)); | 775 OnMainScriptHttpResponseInfoSet(this)); |
| 746 } | 776 } |
| 747 | 777 |
| 748 void ServiceWorkerVersion::SimulatePingTimeoutForTesting() { | 778 void ServiceWorkerVersion::SimulatePingTimeoutForTesting() { |
| 749 ping_controller_->SimulateTimeoutForTesting(); | 779 ping_controller_->SimulateTimeoutForTesting(); |
| 750 } | 780 } |
| 751 | 781 |
| 752 const net::HttpResponseInfo* | 782 const net::HttpResponseInfo* |
| 753 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { | 783 ServiceWorkerVersion::GetMainScriptHttpResponseInfo() { |
| (...skipping 1041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1795 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1825 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1796 idle_time_); | 1826 idle_time_); |
| 1797 } | 1827 } |
| 1798 | 1828 |
| 1799 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { | 1829 void ServiceWorkerVersion::FinishStartWorker(ServiceWorkerStatusCode status) { |
| 1800 start_worker_first_purpose_ = base::nullopt; | 1830 start_worker_first_purpose_ = base::nullopt; |
| 1801 RunCallbacks(this, &start_callbacks_, status); | 1831 RunCallbacks(this, &start_callbacks_, status); |
| 1802 } | 1832 } |
| 1803 | 1833 |
| 1804 } // namespace content | 1834 } // namespace content |
| OLD | NEW |