Commit 0001626e authored by Tobias Sargeant's avatar Tobias Sargeant Committed by Commit Bot

[aw] cleanup: replace LazyInstance usages with NoDestructor

Replace cases of LazyInstance that are not DestructorAtExit with
NoDestructor equivalents. Clean up trivial con/destructors along the
way.

Bug: none
Change-Id: I7c027948f3bfdc3159d24d7e4c36178b271281f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890336
Commit-Queue: Tobias Sargeant <tobiasjs@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715301}
parent 1d6d71f8
......@@ -323,9 +323,7 @@ AwContentsIoThreadClient::AwContentsIoThreadClient(bool pending_association,
const JavaRef<jobject>& obj)
: pending_association_(pending_association), java_object_(obj) {}
AwContentsIoThreadClient::~AwContentsIoThreadClient() {
// explict, out-of-line destructor.
}
AwContentsIoThreadClient::~AwContentsIoThreadClient() = default;
bool AwContentsIoThreadClient::PendingAssociation() const {
return pending_association_;
......
......@@ -8,6 +8,7 @@
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/websocket_handshake_request_info.h"
......@@ -21,19 +22,15 @@ using content::WebSocketHandshakeRequestInfo;
namespace android_webview {
namespace {
base::LazyInstance<AwCookieAccessPolicy>::Leaky g_lazy_instance;
} // namespace
AwCookieAccessPolicy::~AwCookieAccessPolicy() {
}
AwCookieAccessPolicy::~AwCookieAccessPolicy() = default;
AwCookieAccessPolicy::AwCookieAccessPolicy()
: accept_cookies_(true) {
}
AwCookieAccessPolicy* AwCookieAccessPolicy::GetInstance() {
return g_lazy_instance.Pointer();
static base::NoDestructor<AwCookieAccessPolicy> instance;
return instance.get();
}
bool AwCookieAccessPolicy::GetShouldAcceptCookies() {
......
......@@ -5,8 +5,8 @@
#ifndef ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_
#define ANDROID_WEBVIEW_BROWSER_AW_COOKIE_ACCESS_POLICY_H_
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
class GURL;
......@@ -45,7 +45,7 @@ class AwCookieAccessPolicy {
int render_frame_id);
private:
friend struct base::LazyInstanceTraitsBase<AwCookieAccessPolicy>;
friend class base::NoDestructor<AwCookieAccessPolicy>;
friend class AwCookieAccessPolicyTest;
AwCookieAccessPolicy();
......
......@@ -15,7 +15,6 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/supports_user_data.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_entry.h"
......
......@@ -16,9 +16,9 @@
#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/android/scoped_java_ref.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/no_destructor.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
......@@ -53,14 +53,12 @@ namespace {
const int kFileChooserModeOpenMultiple = 1 << 0;
const int kFileChooserModeOpenFolder = 1 << 1;
base::LazyInstance<AwJavaScriptDialogManager>::Leaky
g_javascript_dialog_manager = LAZY_INSTANCE_INITIALIZER;
}
AwWebContentsDelegate::AwWebContentsDelegate(JNIEnv* env, jobject obj)
: WebContentsDelegateAndroid(env, obj), is_fullscreen_(false) {}
AwWebContentsDelegate::~AwWebContentsDelegate() {}
AwWebContentsDelegate::~AwWebContentsDelegate() = default;
void AwWebContentsDelegate::RendererUnresponsive(
content::WebContents* source,
......@@ -94,7 +92,9 @@ void AwWebContentsDelegate::RendererResponsive(
content::JavaScriptDialogManager*
AwWebContentsDelegate::GetJavaScriptDialogManager(WebContents* source) {
return g_javascript_dialog_manager.Pointer();
static base::NoDestructor<AwJavaScriptDialogManager>
javascript_dialog_manager;
return javascript_dialog_manager.get();
}
void AwWebContentsDelegate::FindReply(WebContents* web_contents,
......
......@@ -20,12 +20,12 @@
#include "base/bind_helpers.h"
#include "base/containers/circular_deque.h"
#include "base/files/file_util.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/optional.h"
#include "base/path_service.h"
#include "base/single_thread_task_runner.h"
......@@ -165,13 +165,10 @@ const bool kDefaultFileSchemeAllowed = false;
} // namespace
namespace {
base::LazyInstance<CookieManager>::Leaky g_lazy_instance;
}
// static
CookieManager* CookieManager::GetInstance() {
return g_lazy_instance.Pointer();
static base::NoDestructor<CookieManager> instance;
return instance.get();
}
namespace {
......@@ -201,7 +198,7 @@ CookieManager::CookieManager()
MigrateCookieStorePath();
}
CookieManager::~CookieManager() {}
CookieManager::~CookieManager() = default;
void CookieManager::MigrateCookieStorePath() {
base::FilePath old_cookie_store_path = GetPathInAppDirectory("Cookies");
......
......@@ -10,7 +10,7 @@
#include "base/android/scoped_java_ref.h"
#include "base/containers/circular_deque.h"
#include "base/lazy_instance.h"
#include "base/no_destructor.h"
#include "base/thread_annotations.h"
#include "base/threading/thread.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
......@@ -154,7 +154,7 @@ class CookieManager {
base::FilePath GetCookieStorePath();
private:
friend struct base::LazyInstanceTraitsBase<CookieManager>;
friend class base::NoDestructor<CookieManager>;
CookieManager();
~CookieManager();
......
......@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/gpu/context_cache_controller.h"
#include "gpu/command_buffer/client/gles2_implementation.h"
......
......@@ -23,7 +23,6 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
#include "components/viz/common/display/renderer_settings.h"
......
......@@ -15,7 +15,6 @@
#include "android_webview/common/aw_features.h"
#include "android_webview/public/browser/draw_gl.h"
#include "base/bind.h"
#include "base/lazy_instance.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
......
......@@ -8,6 +8,7 @@
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/no_destructor.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "components/ui_devtools/buildflags.h"
......
......@@ -16,8 +16,8 @@
#include "base/android/jni_string.h"
#include "base/hash/hash.h"
#include "base/i18n/rtl.h"
#include "base/lazy_instance.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "components/metrics/android_metrics_provider.h"
......@@ -42,8 +42,6 @@
namespace android_webview {
base::LazyInstance<AwMetricsServiceClient>::Leaky g_lazy_instance_;
namespace {
// IMPORTANT: DO NOT CHANGE sample rates without first ensuring the Chrome
......@@ -151,13 +149,13 @@ void PopulateSystemInstallDateIfNecessary(PrefService* prefs) {
// static
AwMetricsServiceClient* AwMetricsServiceClient::GetInstance() {
AwMetricsServiceClient* client = g_lazy_instance_.Pointer();
DCHECK_CALLED_ON_VALID_SEQUENCE(client->sequence_checker_);
return client;
static base::NoDestructor<AwMetricsServiceClient> client;
DCHECK_CALLED_ON_VALID_SEQUENCE(client.get()->sequence_checker_);
return client.get();
}
AwMetricsServiceClient::AwMetricsServiceClient() {}
AwMetricsServiceClient::~AwMetricsServiceClient() {}
AwMetricsServiceClient::AwMetricsServiceClient() = default;
AwMetricsServiceClient::~AwMetricsServiceClient() = default;
void AwMetricsServiceClient::Initialize(PrefService* pref_service) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......
......@@ -8,9 +8,9 @@
#include <memory>
#include <string>
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/metrics/field_trial.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "components/metrics/enabled_state_provider.h"
......@@ -95,7 +95,7 @@ enum class BackfillInstallDate {
class AwMetricsServiceClient : public metrics::MetricsServiceClient,
public metrics::EnabledStateProvider,
public content::NotificationObserver {
friend struct base::LazyInstanceTraitsBase<AwMetricsServiceClient>;
friend class base::NoDestructor<AwMetricsServiceClient>;
public:
static AwMetricsServiceClient* GetInstance();
......
......@@ -11,6 +11,7 @@
#include "base/barrier_closure.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace android_webview {
......@@ -18,8 +19,6 @@ namespace android_webview {
namespace {
const char kProxyServerSwitch[] = "proxy-server";
const char kProxyBypassListSwitch[] = "proxy-bypass-list";
base::LazyInstance<AwProxyConfigMonitor>::Leaky g_instance;
} // namespace
AwProxyConfigMonitor::AwProxyConfigMonitor() {
......@@ -36,7 +35,8 @@ AwProxyConfigMonitor::~AwProxyConfigMonitor() {
}
AwProxyConfigMonitor* AwProxyConfigMonitor::GetInstance() {
return g_instance.Pointer();
static base::NoDestructor<AwProxyConfigMonitor> instance;
return instance.get();
}
void AwProxyConfigMonitor::AddProxyToNetworkContextParams(
......
......@@ -9,6 +9,7 @@
#include <string>
#include <vector>
#include "base/no_destructor.h"
#include "mojo/public/cpp/bindings/remote_set.h"
#include "net/proxy_resolution/proxy_config_service_android.h"
#include "services/network/public/mojom/network_service.mojom.h"
......@@ -19,6 +20,9 @@ namespace android_webview {
// is enabled.
class AwProxyConfigMonitor : public net::ProxyConfigService::Observer {
public:
AwProxyConfigMonitor(const AwProxyConfigMonitor&) = delete;
AwProxyConfigMonitor& operator=(const AwProxyConfigMonitor&) = delete;
static AwProxyConfigMonitor* GetInstance();
void AddProxyToNetworkContextParams(
......@@ -34,11 +38,7 @@ class AwProxyConfigMonitor : public net::ProxyConfigService::Observer {
AwProxyConfigMonitor();
~AwProxyConfigMonitor() override;
AwProxyConfigMonitor(const AwProxyConfigMonitor&) = delete;
AwProxyConfigMonitor& operator=(const AwProxyConfigMonitor&) = delete;
friend struct base::LazyInstanceTraitsBase<AwProxyConfigMonitor>;
friend class base::NoDestructor<AwProxyConfigMonitor>;
// net::ProxyConfigService::Observer implementation:
void OnProxyConfigChanged(
const net::ProxyConfigWithAnnotation& config,
......
......@@ -18,8 +18,8 @@
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/scoped_native_library.h"
#include "build/build_config.h"
......@@ -39,7 +39,7 @@ namespace {
class AwCrashReporterClient : public crash_reporter::CrashReporterClient {
public:
AwCrashReporterClient() {}
AwCrashReporterClient() = default;
// crash_reporter::CrashReporterClient implementation.
bool IsRunningUnattended() override { return false; }
......@@ -116,13 +116,15 @@ class AwCrashReporterClient : public crash_reporter::CrashReporterClient {
AttachCurrentThread(), java_exception);
}
static AwCrashReporterClient* Get() {
static base::NoDestructor<AwCrashReporterClient> crash_reporter_client;
return crash_reporter_client.get();
}
private:
DISALLOW_COPY_AND_ASSIGN(AwCrashReporterClient);
};
base::LazyInstance<AwCrashReporterClient>::Leaky g_crash_reporter_client =
LAZY_INSTANCE_INITIALIZER;
#if defined(ARCH_CPU_X86_FAMILY)
bool SafeToUseSignalHandler() {
// N+ shared library namespacing means that we are unable to dlopen
......@@ -197,7 +199,7 @@ void EnableCrashReporter(const std::string& process_type) {
}
#endif
AwCrashReporterClient* client = g_crash_reporter_client.Pointer();
AwCrashReporterClient* client = AwCrashReporterClient::Get();
crash_reporter::SetCrashReporterClient(client);
crash_reporter::InitializeCrashpad(process_type.empty(), process_type);
if (process_type.empty()) {
......
......@@ -29,7 +29,6 @@
#include "base/cpu.h"
#include "base/i18n/icu_util.h"
#include "base/i18n/rtl.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/posix/global_descriptors.h"
#include "base/strings/string_number_conversions.h"
......@@ -71,9 +70,9 @@
namespace android_webview {
AwMainDelegate::AwMainDelegate() {}
AwMainDelegate::AwMainDelegate() = default;
AwMainDelegate::~AwMainDelegate() {}
AwMainDelegate::~AwMainDelegate() = default;
bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
content::SetContentClient(&content_client_);
......
......@@ -9,7 +9,7 @@
#include "android_webview/common/aw_hit_test_data.h"
#include "android_webview/common/render_view_messages.h"
#include "base/lazy_instance.h"
#include "base/no_destructor.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/content/renderer/autofill_agent.h"
#include "components/autofill/content/renderer/password_autofill_agent.h"
......@@ -145,8 +145,10 @@ void PopulateHitTestData(const GURL& absolute_link_url,
// Registry for RenderFrame => AwRenderFrameExt lookups
typedef std::map<content::RenderFrame*, AwRenderFrameExt*> FrameExtMap;
base::LazyInstance<FrameExtMap>::Leaky render_frame_ext_map =
LAZY_INSTANCE_INITIALIZER;
FrameExtMap* GetFrameExtMap() {
static base::NoDestructor<FrameExtMap> map;
return map.get();
}
AwRenderFrameExt::AwRenderFrameExt(content::RenderFrame* render_frame)
: content::RenderFrameObserver(render_frame) {
......@@ -160,7 +162,7 @@ AwRenderFrameExt::AwRenderFrameExt(content::RenderFrame* render_frame)
new content_capture::ContentCaptureSender(render_frame, &registry_);
// Add myself to the RenderFrame => AwRenderFrameExt register.
render_frame_ext_map.Get().emplace(render_frame, this);
GetFrameExtMap()->emplace(render_frame, this);
}
AwRenderFrameExt::~AwRenderFrameExt() {
......@@ -170,11 +172,11 @@ AwRenderFrameExt::~AwRenderFrameExt() {
// render_frames in the map and wipe the one(s) that point to this
// AwRenderFrameExt
auto& map = render_frame_ext_map.Get();
auto it = map.begin();
while (it != map.end()) {
auto* map = GetFrameExtMap();
auto it = map->begin();
while (it != map->end()) {
if (it->second == this) {
it = map.erase(it);
it = map->erase(it);
} else {
++it;
}
......@@ -184,8 +186,8 @@ AwRenderFrameExt::~AwRenderFrameExt() {
AwRenderFrameExt* AwRenderFrameExt::FromRenderFrame(
content::RenderFrame* render_frame) {
DCHECK(render_frame != nullptr);
auto iter = render_frame_ext_map.Get().find(render_frame);
DCHECK(render_frame_ext_map.Get().end() != iter)
auto iter = GetFrameExtMap()->find(render_frame);
DCHECK(GetFrameExtMap()->end() != iter)
<< "Should always exist a render_frame_ext for a render_frame";
AwRenderFrameExt* render_frame_ext = iter->second;
return render_frame_ext;
......
......@@ -6,8 +6,8 @@
#include "android_webview/public/browser/draw_fn.h"
#include "base/containers/flat_map.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
namespace {
......@@ -59,24 +59,27 @@ class FunctorMap {
}
}
static FunctorMap* Get() {
static base::NoDestructor<FunctorMap> map;
return map.get();
}
private:
base::Lock lock_;
base::flat_map<int, FunctorData> map_;
int next_functor_ = 1;
};
base::LazyInstance<FunctorMap>::Leaky g_map;
AwDrawFnRenderMode QueryRenderMode() {
return AW_DRAW_FN_RENDER_MODE_OPENGL_ES;
}
int CreateFunctor(void* data, AwDrawFnFunctorCallbacks* functor_callbacks) {
return g_map.Get().allocate(data, functor_callbacks);
return FunctorMap::Get()->allocate(data, functor_callbacks);
}
void ReleaseFunctor(int functor) {
g_map.Get().mark_released(functor);
FunctorMap::Get()->mark_released(functor);
}
} // namespace
......@@ -102,7 +105,7 @@ Java_org_chromium_android_1webview_shell_DrawFn_nativeSync(
jclass,
jint functor,
jboolean force_apply_dark) {
FunctorData data = g_map.Get().get(functor);
FunctorData data = FunctorMap::Get()->get(functor);
AwDrawFn_OnSyncParams params{kAwDrawFnVersion, force_apply_dark};
data.functor_callbacks->on_sync(functor, data.data, &params);
}
......@@ -110,7 +113,7 @@ Java_org_chromium_android_1webview_shell_DrawFn_nativeSync(
JNIEXPORT void JNICALL
Java_org_chromium_android_1webview_shell_DrawFn_nativeDestroyReleased(JNIEnv*,
jclass) {
g_map.Get().destroy_released();
FunctorMap::Get()->destroy_released();
}
JNIEXPORT void JNICALL
......@@ -126,7 +129,7 @@ Java_org_chromium_android_1webview_shell_DrawFn_nativeDrawGL(JNIEnv*,
jint height,
jint scroll_x,
jint scroll_y) {
FunctorData data = g_map.Get().get(functor);
FunctorData data = FunctorMap::Get()->get(functor);
AwDrawFn_DrawGLParams params{kAwDrawFnVersion};
params.width = width;
params.height = height;
......
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