Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Unified Diff: content/browser/service_worker/service_worker_version.cc

Issue 2376403004: Store Origin-Trial tokens to ServiceWorkerDataBase (Closed)
Patch Set: Add tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/service_worker_version.cc
diff --git a/content/browser/service_worker/service_worker_version.cc b/content/browser/service_worker/service_worker_version.cc
index 337e676375282f1ea3cf4ccee6738d735cd5aef8..01e3f7ff05628f73ff98e6a2deb10b3b5b2545d6 100644
--- a/content/browser/service_worker/service_worker_version.cc
+++ b/content/browser/service_worker/service_worker_version.cc
@@ -34,6 +34,7 @@
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_metrics.h"
#include "content/browser/service_worker/service_worker_registration.h"
+#include "content/common/origin_trials/trial_token_validator.h"
#include "content/common/service_worker/embedded_worker_messages.h"
#include "content/common/service_worker/embedded_worker_start_params.h"
#include "content/common/service_worker/service_worker_messages.h"
@@ -48,6 +49,7 @@
#include "mojo/common/common_type_converters.h"
#include "net/http/http_response_headers.h"
#include "net/http/http_response_info.h"
+#include "third_party/WebKit/public/platform/WebOriginTrialTokenStatus.h"
namespace content {
@@ -700,6 +702,22 @@ void ServiceWorkerVersion::Doom() {
context_->storage()->PurgeResources(resources);
}
+void ServiceWorkerVersion::SetValidOriginTrialTokens(
+ const TrialTokenValidator::FeatureToTokensMap& tokens) {
+ origin_trial_tokens_ =
+ base::MakeUnique<TrialTokenValidator::FeatureToTokensMap>();
+ for (const auto& feature : tokens) {
+ for (const std::string& token : feature.second) {
+ std::string feature_name;
+ 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.
+ &feature_name) ==
+ blink::WebOriginTrialTokenStatus::Success) {
+ (*origin_trial_tokens_)[feature.first].push_back(token);
+ }
+ }
+ }
+}
+
void ServiceWorkerVersion::SetDevToolsAttached(bool attached) {
embedded_worker()->set_devtools_attached(attached);
if (stop_when_devtools_detached_ && !attached) {
@@ -741,6 +759,18 @@ void ServiceWorkerVersion::SetDevToolsAttached(bool attached) {
void ServiceWorkerVersion::SetMainScriptHttpResponseInfo(
const net::HttpResponseInfo& http_info) {
main_script_http_info_.reset(new net::HttpResponseInfo(http_info));
+
+ // Updates |origin_trial_tokens_| if it is not set yet. This happens when:
+ // 1) The worer is a new one.
+ // OR
+ // 2) The worker is an existing one but the entry in ServiceWorkerDatabase
+ // was written by old version Chrome, so |origin_trial_tokens| wasn't set
+ // in the entry.
+ if (!origin_trial_tokens_) {
+ origin_trial_tokens_ = TrialTokenValidator::GetValidTokens(
+ url::Origin(scope()), http_info.headers.get());
+ }
+
FOR_EACH_OBSERVER(Listener, listeners_,
OnMainScriptHttpResponseInfoSet(this));
}
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/common/origin_trials/trial_token_validator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698