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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/debug/alias.h" | 14 #include "base/debug/alias.h" |
| 15 #include "base/feature_list.h" |
15 #include "base/guid.h" | 16 #include "base/guid.h" |
16 #include "base/location.h" | 17 #include "base/location.h" |
17 #include "base/macros.h" | 18 #include "base/macros.h" |
18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/stl_util.h" | 22 #include "base/stl_util.h" |
22 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 14 matching lines...) Expand all Loading... |
39 #include "content/common/origin_trials/trial_token_validator.h" | 40 #include "content/common/origin_trials/trial_token_validator.h" |
40 #include "content/common/service_worker/embedded_worker_messages.h" | 41 #include "content/common/service_worker/embedded_worker_messages.h" |
41 #include "content/common/service_worker/embedded_worker_start_params.h" | 42 #include "content/common/service_worker/embedded_worker_start_params.h" |
42 #include "content/common/service_worker/service_worker_messages.h" | 43 #include "content/common/service_worker/service_worker_messages.h" |
43 #include "content/common/service_worker/service_worker_type_converters.h" | 44 #include "content/common/service_worker/service_worker_type_converters.h" |
44 #include "content/common/service_worker/service_worker_utils.h" | 45 #include "content/common/service_worker/service_worker_utils.h" |
45 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
46 #include "content/public/browser/content_browser_client.h" | 47 #include "content/public/browser/content_browser_client.h" |
47 #include "content/public/browser/render_process_host.h" | 48 #include "content/public/browser/render_process_host.h" |
48 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
| 50 #include "content/public/common/content_features.h" |
49 #include "content/public/common/content_switches.h" | 51 #include "content/public/common/content_switches.h" |
50 #include "content/public/common/result_codes.h" | 52 #include "content/public/common/result_codes.h" |
51 #include "net/http/http_response_headers.h" | 53 #include "net/http/http_response_headers.h" |
52 #include "net/http/http_response_info.h" | 54 #include "net/http/http_response_info.h" |
53 | 55 |
54 namespace content { | 56 namespace content { |
55 | 57 |
56 using StatusCallback = ServiceWorkerVersion::StatusCallback; | 58 using StatusCallback = ServiceWorkerVersion::StatusCallback; |
57 | 59 |
58 namespace { | 60 namespace { |
(...skipping 1065 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 | 1126 |
1125 void ServiceWorkerVersion::NotifyMainScriptRequestHandlerCreated() { | 1127 void ServiceWorkerVersion::NotifyMainScriptRequestHandlerCreated() { |
1126 main_script_request_handler_created_ = true; | 1128 main_script_request_handler_created_ = true; |
1127 } | 1129 } |
1128 | 1130 |
1129 void ServiceWorkerVersion::NotifyMainScriptJobCreated( | 1131 void ServiceWorkerVersion::NotifyMainScriptJobCreated( |
1130 ServiceWorkerContextRequestHandler::CreateJobStatus status) { | 1132 ServiceWorkerContextRequestHandler::CreateJobStatus status) { |
1131 main_script_job_created_ = status; | 1133 main_script_job_created_ = status; |
1132 } | 1134 } |
1133 | 1135 |
| 1136 ServiceWorkerVersion::NavigationPreloadSupportStatus |
| 1137 ServiceWorkerVersion::GetNavigationPreloadSupportStatus() const { |
| 1138 // The origin trial of Navigation Preload started from M57. And the worker |
| 1139 // entry in the database written by Chrome (>= M56) must have the |
| 1140 // origin_trial_tokens field. |
| 1141 const bool has_valid_token = |
| 1142 origin_trial_tokens_ && |
| 1143 base::ContainsKey(*origin_trial_tokens_, |
| 1144 "ServiceWorkerNavigationPreload"); |
| 1145 if (!has_valid_token) { |
| 1146 if (base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine( |
| 1147 features::kServiceWorkerNavigationPreload.name, |
| 1148 base::FeatureList::OVERRIDE_ENABLE_FEATURE)) { |
| 1149 return NavigationPreloadSupportStatus::SUPPORTED; |
| 1150 } else { |
| 1151 return NavigationPreloadSupportStatus:: |
| 1152 NOT_SUPPORTED_NO_VALID_ORIGIN_TRIAL_TOKEN; |
| 1153 } |
| 1154 } |
| 1155 if (base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine( |
| 1156 features::kServiceWorkerNavigationPreload.name, |
| 1157 base::FeatureList::OVERRIDE_ENABLE_FEATURE)) { |
| 1158 return NavigationPreloadSupportStatus::SUPPORTED; |
| 1159 } |
| 1160 if (base::FeatureList::GetInstance()->IsFeatureOverriddenFromCommandLine( |
| 1161 features::kServiceWorkerNavigationPreload.name, |
| 1162 base::FeatureList::OVERRIDE_DISABLE_FEATURE)) { |
| 1163 return NavigationPreloadSupportStatus:: |
| 1164 NOT_SUPPORTED_DISABLED_BY_COMMAND_LINE; |
| 1165 } |
| 1166 if (base::FeatureList::IsEnabled(features::kServiceWorkerNavigationPreload)) { |
| 1167 return NavigationPreloadSupportStatus::SUPPORTED; |
| 1168 } |
| 1169 return NavigationPreloadSupportStatus::NOT_SUPPORTED_FIELD_TRIAL_STOPPED; |
| 1170 } |
| 1171 |
1134 void ServiceWorkerVersion::OnSimpleEventResponse( | 1172 void ServiceWorkerVersion::OnSimpleEventResponse( |
1135 int request_id, | 1173 int request_id, |
1136 blink::WebServiceWorkerEventResult result, | 1174 blink::WebServiceWorkerEventResult result, |
1137 base::Time dispatch_event_time) { | 1175 base::Time dispatch_event_time) { |
1138 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | 1176 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; |
1139 if (result == blink::WebServiceWorkerEventResultRejected) | 1177 if (result == blink::WebServiceWorkerEventResultRejected) |
1140 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; | 1178 status = SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED; |
1141 OnSimpleEventFinished(request_id, status, dispatch_event_time); | 1179 OnSimpleEventFinished(request_id, status, dispatch_event_time); |
1142 } | 1180 } |
1143 | 1181 |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 | 1963 |
1926 void ServiceWorkerVersion::CleanUpExternalRequest( | 1964 void ServiceWorkerVersion::CleanUpExternalRequest( |
1927 const std::string& request_uuid, | 1965 const std::string& request_uuid, |
1928 ServiceWorkerStatusCode status) { | 1966 ServiceWorkerStatusCode status) { |
1929 if (status == SERVICE_WORKER_OK) | 1967 if (status == SERVICE_WORKER_OK) |
1930 return; | 1968 return; |
1931 external_request_uuid_to_request_id_.erase(request_uuid); | 1969 external_request_uuid_to_request_id_.erase(request_uuid); |
1932 } | 1970 } |
1933 | 1971 |
1934 } // namespace content | 1972 } // namespace content |
OLD | NEW |