已合并
weakptrfactory必须是最后一个成员变量 #3217
dqwdgit创建于 2025年4月23日
weakptrfactory必须是最后一个成员变量 #3217
已合并
共 11 个文件变更+25-19
| @@ -1003,14 +1003,15 @@ void MediaSessionImpl::OnResumeInternal(SuspendType suspend_type) { | |||
| 1003 | MediaSessionImpl::MediaSessionImpl(WebContents* web_contents) | 1003 | MediaSessionImpl::MediaSessionImpl(WebContents* web_contents) |
| 1004 | : WebContentsObserver(web_contents), | 1004 | : WebContentsObserver(web_contents), |
| 1005 | WebContentsUserData<MediaSessionImpl>(*web_contents), | 1005 | WebContentsUserData<MediaSessionImpl>(*web_contents), |
| 1006 | - | ||
| 1007 | - weakMediaSessionFactory_(this), | ||
| 1008 | - | ||
| 1009 | audio_focus_state_(State::INACTIVE), | 1006 | audio_focus_state_(State::INACTIVE), |
| 1010 | desired_audio_focus_type_(AudioFocusType::kGainTransientMayDuck), | 1007 | desired_audio_focus_type_(AudioFocusType::kGainTransientMayDuck), |
| 1011 | is_ducking_(false), | 1008 | is_ducking_(false), |
| 1012 | ducking_volume_multiplier_(kDefaultDuckingVolumeMultiplier), | 1009 | ducking_volume_multiplier_(kDefaultDuckingVolumeMultiplier), |
| 1013 | - routed_service_(nullptr) { | 1010 | + routed_service_(nullptr) |
| 1011 | + | ||
| 1012 | + , weakMediaSessionFactory_(this) | ||
| 1013 | + | ||
| 1014 | +{ | ||
| 1014 | 1015 | ||
| 1015 | session_android_ = std::make_unique<MediaSessionAndroid>(this); | 1016 | session_android_ = std::make_unique<MediaSessionAndroid>(this); |
| 1016 | should_throttle_duration_update_ = true; | 1017 | should_throttle_duration_update_ = true; |
| @@ -393,7 +393,6 @@ class MediaSessionImpl : public MediaSession, | |||
| 393 | int audioResumeInterval_ = 0; | 393 | int audioResumeInterval_ = 0; |
| 394 | bool audioExclusive_ = true; | 394 | bool audioExclusive_ = true; |
| 395 | bool isPlayingState_ = false; | 395 | bool isPlayingState_ = false; |
| 396 | - base::WeakPtrFactory<content::MediaSessionImpl> weakMediaSessionFactory_; | ||
| 397 | NWebMediaSessionState sessionState_ = NWebMediaSessionState::NOINITIAL; | 396 | NWebMediaSessionState sessionState_ = NWebMediaSessionState::NOINITIAL; |
| 398 | 397 | ||
| 399 | 398 | ||
| @@ -688,6 +687,12 @@ class MediaSessionImpl : public MediaSession, | |||
| 688 | 687 | ||
| 689 | media_session::mojom::RemotePlaybackMetadataPtr remote_playback_metadata_; | 688 | media_session::mojom::RemotePlaybackMetadataPtr remote_playback_metadata_; |
| 690 | 689 | ||
| 690 | + | ||
| 691 | + public: | ||
| 692 | + base::WeakPtrFactory<content::MediaSessionImpl> weakMediaSessionFactory_; | ||
| 693 | + | ||
| 694 | + | ||
| 695 | + private: | ||
| 691 | base::WeakPtrFactory<MediaSessionImpl> weak_factory_{this}; | 696 | base::WeakPtrFactory<MediaSessionImpl> weak_factory_{this}; |
| 692 | 697 | ||
| 693 | WEB_CONTENTS_USER_DATA_KEY_DECL(); | 698 | WEB_CONTENTS_USER_DATA_KEY_DECL(); |
| @@ -81,11 +81,11 @@ class MediaSessionOHOS final | |||
| 81 | std::shared_ptr<OHOS::NWeb::MediaAVSessionPositionAdapter> av_position_; | 81 | std::shared_ptr<OHOS::NWeb::MediaAVSessionPositionAdapter> av_position_; |
| 82 | std::unique_ptr<OHOS::NWeb::MediaAVSessionAdapter> avsession_adapter_; | 82 | std::unique_ptr<OHOS::NWeb::MediaAVSessionAdapter> avsession_adapter_; |
| 83 | OHOS::NWeb::MediaAVSessionType media_type_; | 83 | OHOS::NWeb::MediaAVSessionType media_type_; |
| 84 | - base::WeakPtrFactory<MediaSessionOHOS> weak_factory_{this}; | ||
| 85 | const raw_ptr<MediaSessionImpl, DanglingUntriaged> media_session_; | 84 | const raw_ptr<MediaSessionImpl, DanglingUntriaged> media_session_; |
| 86 | mojo::Receiver<media_session::mojom::MediaSessionObserver> observer_receiver_{this}; | 85 | mojo::Receiver<media_session::mojom::MediaSessionObserver> observer_receiver_{this}; |
| 87 | 86 | ||
| 88 | static constexpr base::TimeDelta kReportMediaInfoInterval = base::Seconds(1); | 87 | static constexpr base::TimeDelta kReportMediaInfoInterval = base::Seconds(1); |
| 88 | + base::WeakPtrFactory<MediaSessionOHOS> weak_factory_{this}; | ||
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | class OHOSMediaAVSessionCallback : public OHOS::NWeb::MediaAVSessionCallbackAdapter { | 91 | class OHOSMediaAVSessionCallback : public OHOS::NWeb::MediaAVSessionCallbackAdapter { |
| @@ -323,11 +323,11 @@ class CONTENT_EXPORT VideoCaptureController | |||
| 323 | // would otherwise not line up between the various ControllerClients. | 323 | // would otherwise not line up between the various ControllerClients. |
| 324 | bool was_crop_ever_called_ = false; | 324 | bool was_crop_ever_called_ = false; |
| 325 | 325 | ||
| 326 | - base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_{this}; | ||
| 327 | - | ||
| 328 | 326 | ||
| 329 | VideoCaptureManager* video_capture_manager_ = nullptr; | 327 | VideoCaptureManager* video_capture_manager_ = nullptr; |
| 330 | 328 | ||
| 329 | + | ||
| 330 | + base::WeakPtrFactory<VideoCaptureController> weak_ptr_factory_{this}; | ||
| 331 | }; | 331 | }; |
| 332 | 332 | ||
| 333 | } // namespace content | 333 | } // namespace content |
| @@ -69,9 +69,9 @@ class MEDIA_EXPORT OHOSAudioCapturerSource final : public AudioCapturerSource { | |||
| 69 | base::Lock callback_lock_; | 69 | base::Lock callback_lock_; |
| 70 | std::shared_ptr<AudioCapturerReadCallback> audioCapturerReadCallback_ = | 70 | std::shared_ptr<AudioCapturerReadCallback> audioCapturerReadCallback_ = |
| 71 | nullptr; | 71 | nullptr; |
| 72 | - base::WeakPtrFactory<OHOSAudioCapturerSource> weak_factory_{this}; | ||
| 73 | raw_ptr<FILE> dumpFile_ = nullptr; | 72 | raw_ptr<FILE> dumpFile_ = nullptr; |
| 74 | std::atomic<bool> is_stopped_{false}; | 73 | std::atomic<bool> is_stopped_{false}; |
| 74 | + base::WeakPtrFactory<OHOSAudioCapturerSource> weak_factory_{this}; | ||
| 75 | }; | 75 | }; |
| 76 | 76 | ||
| 77 | } // namespace media | 77 | } // namespace media |
| @@ -146,7 +146,6 @@ class MediaCodecDecoderBridgeImpl { | |||
| 146 | } | 146 | } |
| 147 | DecoderAdapterCode SetAVCencInfo(uint32_t index, const DecryptConfig* decrypt_config); | 147 | DecoderAdapterCode SetAVCencInfo(uint32_t index, const DecryptConfig* decrypt_config); |
| 148 | 148 | ||
| 149 | - base::WeakPtrFactory<MediaCodecDecoderBridgeImpl> weak_factory_{this}; | ||
| 150 | std::atomic<bool> isRunning_ = false; | 149 | std::atomic<bool> isRunning_ = false; |
| 151 | bool isFirstDecFrame_ = true; | 150 | bool isFirstDecFrame_ = true; |
| 152 | std::shared_ptr<DecoderBridgeSignal> signal_ = nullptr; | 151 | std::shared_ptr<DecoderBridgeSignal> signal_ = nullptr; |
| @@ -161,6 +160,8 @@ class MediaCodecDecoderBridgeImpl { | |||
| 161 | void* window_from_surface_ = nullptr; | 160 | void* window_from_surface_ = nullptr; |
| 162 | int32_t video_surface_id_ = -1; | 161 | int32_t video_surface_id_ = -1; |
| 163 | 162 | ||
| 163 | + | ||
| 164 | + base::WeakPtrFactory<MediaCodecDecoderBridgeImpl> weak_factory_{this}; | ||
| 164 | }; | 165 | }; |
| 165 | 166 | ||
| 166 | } // namespace media | 167 | } // namespace media |
| @@ -223,10 +223,9 @@ class MEDIA_EXPORT OHOSMediaDrmBridge : public ContentDecryptionModule, | |||
| 223 | scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 223 | scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 224 | OHOSMediaCryptoContextImpl media_crypto_context_; | 224 | OHOSMediaCryptoContextImpl media_crypto_context_; |
| 225 | 225 | ||
| 226 | - base::WeakPtrFactory<OHOSMediaDrmBridge> weak_factory_{this}; | ||
| 227 | - | ||
| 228 | std::unique_ptr<OHOS::NWeb::DrmAdapter> ohos_drm_adapter_; | 226 | std::unique_ptr<OHOS::NWeb::DrmAdapter> ohos_drm_adapter_; |
| 229 | OHOS::NWeb::OHOSMediaKeySession ohos_media_key_session_; | 227 | OHOS::NWeb::OHOSMediaKeySession ohos_media_key_session_; |
| 228 | + base::WeakPtrFactory<OHOSMediaDrmBridge> weak_factory_{this}; | ||
| 230 | }; | 229 | }; |
| 231 | 230 | ||
| 232 | class OHOSDrmCallback : public OHOS::NWeb::DrmCallbackAdapter { | 231 | class OHOSDrmCallback : public OHOS::NWeb::DrmCallbackAdapter { |
| @@ -107,9 +107,9 @@ class CAPTURE_EXPORT OHOSCaptureDelegate final { | |||
| 107 | // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | 107 | // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. |
| 108 | int rotation_; | 108 | int rotation_; |
| 109 | 109 | ||
| 110 | - base::WeakPtrFactory<OHOSCaptureDelegate> weak_factory_{this}; | ||
| 111 | - | ||
| 112 | const VideoCaptureParams capture_params_; | 110 | const VideoCaptureParams capture_params_; |
| 111 | + | ||
| 112 | + base::WeakPtrFactory<OHOSCaptureDelegate> weak_factory_{this}; | ||
| 113 | }; | 113 | }; |
| 114 | 114 | ||
| 115 | } // namespace media | 115 | } // namespace media |
| @@ -43,8 +43,8 @@ class CAPTURE_EXPORT VideoCaptureDeviceFactoryOHOS | |||
| 43 | bool CheckAndInitCameraManager(); | 43 | bool CheckAndInitCameraManager(); |
| 44 | scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; | 44 | scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner_; |
| 45 | std::shared_ptr<CameraManagerAdapter> camera_manager_adapter_; | 45 | std::shared_ptr<CameraManagerAdapter> camera_manager_adapter_; |
| 46 | - base::WeakPtrFactory<VideoCaptureDeviceFactoryOHOS> weak_factory_{this}; | ||
| 47 | bool is_camera_manager_created_{false}; | 46 | bool is_camera_manager_created_{false}; |
| 47 | + base::WeakPtrFactory<VideoCaptureDeviceFactoryOHOS> weak_factory_{this}; | ||
| 48 | }; | 48 | }; |
| 49 | 49 | ||
| 50 | } // namespace media | 50 | } // namespace media |
| @@ -200,9 +200,6 @@ class MEDIA_GPU_EXPORT OhosVideoDecoder final | |||
| 200 | int32_t pending_surface_id_ = -1; | 200 | int32_t pending_surface_id_ = -1; |
| 201 | 201 | ||
| 202 | 202 | ||
| 203 | - base::WeakPtrFactory<OhosVideoDecoder> weak_factory_{this}; | ||
| 204 | - base::WeakPtrFactory<OhosVideoDecoder> codec_allocator_weak_factory_{this}; | ||
| 205 | - | ||
| 206 | // ohos cdm object | 203 | // ohos cdm object |
| 207 | raw_ptr<OHOSMediaCryptoContext> ohos_crypto_context_; | 204 | raw_ptr<OHOSMediaCryptoContext> ohos_crypto_context_; |
| 208 | 205 | ||
| @@ -216,6 +213,9 @@ class MEDIA_GPU_EXPORT OhosVideoDecoder final | |||
| 216 | bool waiting_for_key_ = false; | 213 | bool waiting_for_key_ = false; |
| 217 | 214 | ||
| 218 | void* mediaKeySession_ = nullptr; | 215 | void* mediaKeySession_ = nullptr; |
| 216 | + | ||
| 217 | + base::WeakPtrFactory<OhosVideoDecoder> weak_factory_{this}; | ||
| 218 | + base::WeakPtrFactory<OhosVideoDecoder> codec_allocator_weak_factory_{this}; | ||
| 219 | }; | 219 | }; |
| 220 | 220 | ||
| 221 | } // namespace media | 221 | } // namespace media |
| @@ -70,7 +70,6 @@ class MEDIA_GPU_EXPORT OHOSVideoEncodeAccelerator | |||
| 70 | 70 | ||
| 71 | SEQUENCE_CHECKER(sequence_checker_); | 71 | SEQUENCE_CHECKER(sequence_checker_); |
| 72 | 72 | ||
| 73 | - std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | ||
| 74 | std::unique_ptr<OHOSMediaCodecBridge> media_codec_; | 73 | std::unique_ptr<OHOSMediaCodecBridge> media_codec_; |
| 75 | using PendingFrames = | 74 | using PendingFrames = |
| 76 | base::queue<std::tuple<scoped_refptr<VideoFrame>, bool, base::Time>>; | 75 | base::queue<std::tuple<scoped_refptr<VideoFrame>, bool, base::Time>>; |
| @@ -92,6 +91,7 @@ class MEDIA_GPU_EXPORT OHOSVideoEncodeAccelerator | |||
| 92 | // True if there is encoder error. | 91 | // True if there is encoder error. |
| 93 | bool error_occurred_ = false; | 92 | bool error_occurred_ = false; |
| 94 | base::TimeDelta frame_timestamp_last_; | 93 | base::TimeDelta frame_timestamp_last_; |
| 94 | + std::unique_ptr<base::WeakPtrFactory<Client>> client_ptr_factory_; | ||
| 95 | }; | 95 | }; |
| 96 | 96 | ||
| 97 | } // namespace media | 97 | } // namespace media |