Bug 1665373 - Stop using nsCountedRef in widget/gtk. r=karlt

Instead, use RefPtrTraits.

Differential Revision: https://phabricator.services.mozilla.com/D90397
This commit is contained in:
Emilio Cobos Álvarez 2020-09-18 01:04:02 +00:00
Родитель b0d53f9f52
Коммит c5c5fd5757
4 изменённых файлов: 40 добавлений и 37 удалений

32
widget/gtk/GRefPtr.h Normal file
Просмотреть файл

@ -0,0 +1,32 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GRefPtr_h_
#define GRefPtr_h_
// Allows to use RefPtr<T> with various kinds of GObjects
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include "mozilla/RefPtr.h"
namespace mozilla {
template <typename T>
struct GObjectRefPtrTraits {
static void AddRef(T* aObject) { g_object_ref(aObject); }
static void Release(T* aObject) { g_object_unref(aObject); }
};
template <>
struct RefPtrTraits<GtkWidget> : public GObjectRefPtrTraits<GtkWidget> {};
template <>
struct RefPtrTraits<GdkDragContext>
: public GObjectRefPtrTraits<GdkDragContext> {};
} // namespace mozilla
#endif

Просмотреть файл

@ -8,7 +8,6 @@
#include "mozilla/Sprintf.h" #include "mozilla/Sprintf.h"
#include "mozilla/Logging.h" #include "mozilla/Logging.h"
#include "mozilla/ipc/GeckoChildProcessHost.h" #include "mozilla/ipc/GeckoChildProcessHost.h"
#include "nsAutoRef.h"
#include "nsLocalFile.h" #include "nsLocalFile.h"
#include "nsMemoryReporterManager.h" #include "nsMemoryReporterManager.h"
#include "nsNetCID.h" #include "nsNetCID.h"
@ -21,12 +20,6 @@
#define NANOPERSEC 1000000000. #define NANOPERSEC 1000000000.
template <>
class nsAutoRefTraits<DIR> : public nsPointerRefTraits<DIR> {
public:
static void Release(DIR* dirHandle) { closedir(dirHandle); }
};
namespace mozilla { namespace mozilla {
// StatReader can parse and tokenize a POSIX stat file. // StatReader can parse and tokenize a POSIX stat file.
@ -253,7 +246,7 @@ RefPtr<ProcInfoPromise> GetProcInfo(nsTArray<ProcInfoRequest>&& aRequests) {
// Let's look at the threads // Let's look at the threads
nsCString taskPath; nsCString taskPath;
taskPath.AppendPrintf("/proc/%u/task", request.pid); taskPath.AppendPrintf("/proc/%u/task", request.pid);
nsAutoRef<DIR> dirHandle(opendir(taskPath.get())); DIR* dirHandle = opendir(taskPath.get());
if (!dirHandle) { if (!dirHandle) {
// For some reason, we have no data on the threads for this process. // For some reason, we have no data on the threads for this process.
// Most likely reason is that we have just lost a race condition and // Most likely reason is that we have just lost a race condition and
@ -261,6 +254,7 @@ RefPtr<ProcInfoPromise> GetProcInfo(nsTArray<ProcInfoRequest>&& aRequests) {
// Let's stop here and ignore the entire process. // Let's stop here and ignore the entire process.
continue; continue;
} }
auto cleanup = mozilla::MakeScopeExit([&] { closedir(dirHandle); });
// If we can't read some thread info, we ignore that thread. // If we can't read some thread info, we ignore that thread.
dirent* entry; dirent* entry;

Просмотреть файл

@ -28,6 +28,7 @@
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/ClearOnShutdown.h" #include "mozilla/ClearOnShutdown.h"
#include "mozilla/PresShell.h" #include "mozilla/PresShell.h"
#include "GRefPtr.h"
#include "gfxXlibSurface.h" #include "gfxXlibSurface.h"
#include "gfxContext.h" #include "gfxContext.h"
@ -1897,7 +1898,7 @@ gboolean nsDragService::RunScheduledTask() {
// We still reply appropriately to indicate that the drop will or didn't // We still reply appropriately to indicate that the drop will or didn't
// succeeed. // succeeed.
mTargetWidget = mTargetWindow->GetMozContainerWidget(); mTargetWidget = mTargetWindow->GetMozContainerWidget();
mTargetDragContext.steal(mPendingDragContext); mTargetDragContext = std::move(mPendingDragContext);
#ifdef MOZ_WAYLAND #ifdef MOZ_WAYLAND
mTargetWaylandDragContext = std::move(mPendingWaylandDragContext); mTargetWaylandDragContext = std::move(mPendingWaylandDragContext);
#endif #endif

Просмотреть файл

@ -10,7 +10,6 @@
#include "mozilla/RefPtr.h" #include "mozilla/RefPtr.h"
#include "nsBaseDragService.h" #include "nsBaseDragService.h"
#include "nsIObserver.h" #include "nsIObserver.h"
#include "nsAutoRef.h"
#include <gtk/gtk.h> #include <gtk/gtk.h>
class nsWindow; class nsWindow;
@ -22,29 +21,6 @@ class SourceSurface;
} }
} // namespace mozilla } // namespace mozilla
#ifndef HAVE_NSGOBJECTREFTRAITS
# define HAVE_NSGOBJECTREFTRAITS
template <class T>
class nsGObjectRefTraits : public nsPointerRefTraits<T> {
public:
static void Release(T* aPtr) { g_object_unref(aPtr); }
static void AddRef(T* aPtr) { g_object_ref(aPtr); }
};
#endif
#ifndef HAVE_NSAUTOREFTRAITS_GTKWIDGET
# define HAVE_NSAUTOREFTRAITS_GTKWIDGET
template <>
class nsAutoRefTraits<GtkWidget> : public nsGObjectRefTraits<GtkWidget> {};
#endif
#ifndef HAVE_NSAUTOREFTRAITS_GDKDRAGCONTEXT
# define HAVE_NSAUTOREFTRAITS_GDKDRAGCONTEXT
template <>
class nsAutoRefTraits<GdkDragContext>
: public nsGObjectRefTraits<GdkDragContext> {};
#endif
/** /**
* Native GTK DragService wrapper * Native GTK DragService wrapper
*/ */
@ -148,7 +124,7 @@ class nsDragService final : public nsBaseDragService, public nsIObserver {
// will be nullptr if the scheduled task is eDragTaskLeave. // will be nullptr if the scheduled task is eDragTaskLeave.
RefPtr<nsWindow> mPendingWindow; RefPtr<nsWindow> mPendingWindow;
mozilla::LayoutDeviceIntPoint mPendingWindowPoint; mozilla::LayoutDeviceIntPoint mPendingWindowPoint;
nsCountedRef<GdkDragContext> mPendingDragContext; RefPtr<GdkDragContext> mPendingDragContext;
#ifdef MOZ_WAYLAND #ifdef MOZ_WAYLAND
RefPtr<nsWaylandDragContext> mPendingWaylandDragContext; RefPtr<nsWaylandDragContext> mPendingWaylandDragContext;
#endif #endif
@ -161,14 +137,14 @@ class nsDragService final : public nsBaseDragService, public nsIObserver {
mozilla::LayoutDeviceIntPoint mTargetWindowPoint; mozilla::LayoutDeviceIntPoint mTargetWindowPoint;
// mTargetWidget and mTargetDragContext are set only while dispatching // mTargetWidget and mTargetDragContext are set only while dispatching
// motion or drop events. mTime records the corresponding timestamp. // motion or drop events. mTime records the corresponding timestamp.
nsCountedRef<GtkWidget> mTargetWidget; RefPtr<GtkWidget> mTargetWidget;
nsCountedRef<GdkDragContext> mTargetDragContext; RefPtr<GdkDragContext> mTargetDragContext;
#ifdef MOZ_WAYLAND #ifdef MOZ_WAYLAND
RefPtr<nsWaylandDragContext> mTargetWaylandDragContext; RefPtr<nsWaylandDragContext> mTargetWaylandDragContext;
#endif #endif
// mTargetDragContextForRemote is set while waiting for a reply from // mTargetDragContextForRemote is set while waiting for a reply from
// a child process. // a child process.
nsCountedRef<GdkDragContext> mTargetDragContextForRemote; RefPtr<GdkDragContext> mTargetDragContextForRemote;
#ifdef MOZ_WAYLAND #ifdef MOZ_WAYLAND
RefPtr<nsWaylandDragContext> mTargetWaylandDragContextForRemote; RefPtr<nsWaylandDragContext> mTargetWaylandDragContextForRemote;
#endif #endif