[Code Health] Remove some uses of base::SupportsWeakPtr. (gpu/ipc)
Low-Coverage-Reason: LARGE_SCALE_REFACTOR
Bug: 647430
Change-Id: I6055edecb954f738131dbc4d6b5af4509b904c04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5263240
Commit-Queue: Vasiliy Telezhnikov <vasilyt@chromium.org>
Auto-Submit: David Bertoni <dbertoni@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1266398}
diff --git a/gpu/ipc/service/command_buffer_stub.h b/gpu/ipc/service/command_buffer_stub.h
index 68ad357..445beed 100644
--- a/gpu/ipc/service/command_buffer_stub.h
+++ b/gpu/ipc/service/command_buffer_stub.h
@@ -66,8 +66,7 @@
class GPU_IPC_SERVICE_EXPORT CommandBufferStub
: public CommandBufferServiceClient,
public DecoderClient,
- public mojom::CommandBuffer,
- public base::SupportsWeakPtr<CommandBufferStub> {
+ public mojom::CommandBuffer {
public:
class DestructionObserver {
public:
@@ -116,6 +115,8 @@
MemoryTracker* GetMemoryTracker() const;
virtual MemoryTracker* GetContextGroupMemoryTracker() const = 0;
+ virtual base::WeakPtr<CommandBufferStub> AsWeakPtr() = 0;
+
// Executes a DeferredRequest routed to this command buffer by a GpuChannel.
void ExecuteDeferredRequest(
mojom::DeferredCommandBufferRequestParams& params);
diff --git a/gpu/ipc/service/gles2_command_buffer_stub.cc b/gpu/ipc/service/gles2_command_buffer_stub.cc
index f449aa84..c905fc33 100644
--- a/gpu/ipc/service/gles2_command_buffer_stub.cc
+++ b/gpu/ipc/service/gles2_command_buffer_stub.cc
@@ -13,6 +13,7 @@
#include "base/json/json_writer.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/unsafe_shared_memory_region.h"
+#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/time.h"
@@ -408,6 +409,10 @@
return context_group_->memory_tracker();
}
+base::WeakPtr<CommandBufferStub> GLES2CommandBufferStub::AsWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
void GLES2CommandBufferStub::OnGpuSwitched(
gl::GpuPreference active_gpu_heuristic) {
client().OnGpuSwitched(active_gpu_heuristic);
diff --git a/gpu/ipc/service/gles2_command_buffer_stub.h b/gpu/ipc/service/gles2_command_buffer_stub.h
index 73dabd82..f48b26a 100644
--- a/gpu/ipc/service/gles2_command_buffer_stub.h
+++ b/gpu/ipc/service/gles2_command_buffer_stub.h
@@ -17,10 +17,9 @@
struct Mailbox;
-class GPU_IPC_SERVICE_EXPORT GLES2CommandBufferStub
+class GPU_IPC_SERVICE_EXPORT GLES2CommandBufferStub final
: public CommandBufferStub,
- public ImageTransportSurfaceDelegate,
- public base::SupportsWeakPtr<GLES2CommandBufferStub> {
+ public ImageTransportSurfaceDelegate {
public:
GLES2CommandBufferStub(GpuChannel* channel,
const mojom::CreateCommandBufferParams& init_params,
@@ -43,6 +42,8 @@
base::UnsafeSharedMemoryRegion shared_state_shm) override;
MemoryTracker* GetContextGroupMemoryTracker() const override;
+ base::WeakPtr<CommandBufferStub> AsWeakPtr() override;
+
// DecoderClient implementation.
void OnGpuSwitched(gl::GpuPreference active_gpu_heuristic) override;
diff --git a/gpu/ipc/service/raster_command_buffer_stub.cc b/gpu/ipc/service/raster_command_buffer_stub.cc
index 480cd1e..5494ea8 100644
--- a/gpu/ipc/service/raster_command_buffer_stub.cc
+++ b/gpu/ipc/service/raster_command_buffer_stub.cc
@@ -8,6 +8,7 @@
#include <utility>
#include "base/memory/unsafe_shared_memory_region.h"
+#include "base/memory/weak_ptr.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "gpu/command_buffer/common/constants.h"
@@ -160,6 +161,10 @@
return nullptr;
}
+base::WeakPtr<CommandBufferStub> RasterCommandBufferStub::AsWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
void RasterCommandBufferStub::OnSwapBuffers(uint64_t swap_id, uint32_t flags) {}
void RasterCommandBufferStub::SetActiveURL(GURL url) {
diff --git a/gpu/ipc/service/raster_command_buffer_stub.h b/gpu/ipc/service/raster_command_buffer_stub.h
index 71ecef8..98bccca 100644
--- a/gpu/ipc/service/raster_command_buffer_stub.h
+++ b/gpu/ipc/service/raster_command_buffer_stub.h
@@ -5,11 +5,12 @@
#ifndef GPU_IPC_SERVICE_RASTER_COMMAND_BUFFER_STUB_H_
#define GPU_IPC_SERVICE_RASTER_COMMAND_BUFFER_STUB_H_
+#include "base/memory/weak_ptr.h"
#include "gpu/ipc/service/command_buffer_stub.h"
namespace gpu {
-class GPU_IPC_SERVICE_EXPORT RasterCommandBufferStub
+class GPU_IPC_SERVICE_EXPORT RasterCommandBufferStub final
: public CommandBufferStub {
public:
RasterCommandBufferStub(GpuChannel* channel,
@@ -32,10 +33,13 @@
const mojom::CreateCommandBufferParams& init_params,
base::UnsafeSharedMemoryRegion shared_state_shm) override;
MemoryTracker* GetContextGroupMemoryTracker() const override;
+ base::WeakPtr<CommandBufferStub> AsWeakPtr() override;
private:
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
void SetActiveURL(GURL url) override;
+
+ base::WeakPtrFactory<RasterCommandBufferStub> weak_ptr_factory_{this};
};
} // namespace gpu
diff --git a/gpu/ipc/service/webgpu_command_buffer_stub.cc b/gpu/ipc/service/webgpu_command_buffer_stub.cc
index cbc74c4..04a814d 100644
--- a/gpu/ipc/service/webgpu_command_buffer_stub.cc
+++ b/gpu/ipc/service/webgpu_command_buffer_stub.cc
@@ -158,6 +158,10 @@
return nullptr;
}
+base::WeakPtr<CommandBufferStub> WebGPUCommandBufferStub::AsWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+}
+
void WebGPUCommandBufferStub::OnSwapBuffers(uint64_t swap_id, uint32_t flags) {}
} // namespace gpu
diff --git a/gpu/ipc/service/webgpu_command_buffer_stub.h b/gpu/ipc/service/webgpu_command_buffer_stub.h
index 9040aff..3dd3114 100644
--- a/gpu/ipc/service/webgpu_command_buffer_stub.h
+++ b/gpu/ipc/service/webgpu_command_buffer_stub.h
@@ -5,11 +5,12 @@
#ifndef GPU_IPC_SERVICE_WEBGPU_COMMAND_BUFFER_STUB_H_
#define GPU_IPC_SERVICE_WEBGPU_COMMAND_BUFFER_STUB_H_
+#include "base/memory/weak_ptr.h"
#include "gpu/ipc/service/command_buffer_stub.h"
namespace gpu {
-class GPU_IPC_SERVICE_EXPORT WebGPUCommandBufferStub
+class GPU_IPC_SERVICE_EXPORT WebGPUCommandBufferStub final
: public CommandBufferStub {
public:
WebGPUCommandBufferStub(GpuChannel* channel,
@@ -32,9 +33,12 @@
const mojom::CreateCommandBufferParams& init_params,
base::UnsafeSharedMemoryRegion shared_state_shm) override;
MemoryTracker* GetContextGroupMemoryTracker() const override;
+ base::WeakPtr<CommandBufferStub> AsWeakPtr() override;
private:
void OnSwapBuffers(uint64_t swap_id, uint32_t flags) override;
+
+ base::WeakPtrFactory<WebGPUCommandBufferStub> weak_ptr_factory_{this};
};
} // namespace gpu