Commit ef213bf6 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Use base::NoDestructor for URL scheme sets.

Change-Id: I8327f38e0cb1c96bb92b0b19a291d21b1a8b36b1
Reviewed-on: https://chromium-review.googlesource.com/961736Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543270}
parent e6ba0e6c
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <iterator>
#include "base/no_destructor.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "content/public/common/content_client.h" #include "content/public/common/content_client.h"
#include "content/public/common/url_constants.h" #include "content/public/common/url_constants.h"
...@@ -17,15 +18,6 @@ ...@@ -17,15 +18,6 @@
namespace content { namespace content {
namespace { namespace {
// These lists are lazily initialized below and are leaked on shutdown to
// prevent any destructors from being called that will slow us down or cause
// problems.
std::vector<std::string>* savable_schemes = nullptr;
// Note we store url::Origins here instead of strings to deal with
// canonicalization.
std::vector<url::Origin>* secure_origins = nullptr;
std::vector<std::string>* service_worker_schemes = nullptr;
const char* const kDefaultSavableSchemes[] = { const char* const kDefaultSavableSchemes[] = {
url::kHttpScheme, url::kHttpScheme,
url::kHttpsScheme, url::kHttpsScheme,
...@@ -37,6 +29,26 @@ const char* const kDefaultSavableSchemes[] = { ...@@ -37,6 +29,26 @@ const char* const kDefaultSavableSchemes[] = {
url::kDataScheme url::kDataScheme
}; };
// These lists are lazily initialized below and are leaked on shutdown to
// prevent any destructors from being called that will slow us down or cause
// problems.
std::vector<std::string>& GetMutableSavableSchemes() {
static base::NoDestructor<std::vector<std::string>> schemes;
return *schemes;
}
// Note we store url::Origins here instead of strings to deal with
// canonicalization.
std::vector<url::Origin>& GetMutableSecureOrigins() {
static base::NoDestructor<std::vector<url::Origin>> origins;
return *origins;
}
std::vector<std::string>& GetMutableServiceWorkerSchemes() {
static base::NoDestructor<std::vector<std::string>> schemes;
return *schemes;
}
} // namespace } // namespace
void RegisterContentSchemes(bool lock_schemes) { void RegisterContentSchemes(bool lock_schemes) {
...@@ -86,34 +98,28 @@ void RegisterContentSchemes(bool lock_schemes) { ...@@ -86,34 +98,28 @@ void RegisterContentSchemes(bool lock_schemes) {
url::LockSchemeRegistries(); url::LockSchemeRegistries();
// Combine the default savable schemes with the additional ones given. // Combine the default savable schemes with the additional ones given.
delete savable_schemes; GetMutableSavableSchemes().assign(std::begin(kDefaultSavableSchemes),
savable_schemes = new std::vector<std::string>; std::end(kDefaultSavableSchemes));
for (auto* default_scheme : kDefaultSavableSchemes) GetMutableSavableSchemes().insert(GetMutableSavableSchemes().end(),
savable_schemes->push_back(default_scheme); schemes.savable_schemes.begin(),
savable_schemes->insert(savable_schemes->end(), schemes.savable_schemes.end());
schemes.savable_schemes.begin(),
schemes.savable_schemes.end()); GetMutableServiceWorkerSchemes() = std::move(schemes.service_worker_schemes);
delete service_worker_schemes; GetMutableSecureOrigins() = std::move(schemes.secure_origins);
service_worker_schemes = new std::vector<std::string>; network::cors::legacy::RegisterSecureOrigins(GetSecureOrigins());
*service_worker_schemes = std::move(schemes.service_worker_schemes);
delete secure_origins;
secure_origins = new std::vector<url::Origin>;
*secure_origins = std::move(schemes.secure_origins);
network::cors::legacy::RegisterSecureOrigins(*secure_origins);
} }
const std::vector<std::string>& GetSavableSchemes() { const std::vector<std::string>& GetSavableSchemes() {
return *savable_schemes; return GetMutableSavableSchemes();
} }
const std::vector<url::Origin>& GetSecureOrigins() { const std::vector<url::Origin>& GetSecureOrigins() {
return *secure_origins; return GetMutableSecureOrigins();
} }
const std::vector<std::string>& GetServiceWorkerSchemes() { const std::vector<std::string>& GetServiceWorkerSchemes() {
return *service_worker_schemes; return GetMutableServiceWorkerSchemes();
} }
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment