Use weak pointer to store duplicate requests
Bug: 1423304
Change-Id: I7ab170f085c3d05c582f7065b88c1ad2510cc633
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4365724
Commit-Queue: Thomas Nguyen <[email protected]>
Reviewed-by: Andy Paicu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1124133}
diff --git a/components/permissions/permission_request.h b/components/permissions/permission_request.h
index d0c57a5..0328b53 100644
--- a/components/permissions/permission_request.h
+++ b/components/permissions/permission_request.h
@@ -8,6 +8,7 @@
#include <string>
#include "base/functional/callback.h"
+#include "base/memory/weak_ptr.h"
#include "build/build_config.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
@@ -83,6 +84,9 @@
virtual std::u16string GetDialogMessageText() const;
#endif
+ // Returns a weak pointer to this instance.
+ base::WeakPtr<PermissionRequest> GetWeakPtr();
+
#if !BUILDFLAG(IS_ANDROID)
// Returns whether displaying a confirmation chip for the request is
// supported.
@@ -163,6 +167,8 @@
// Called when the request is no longer in use so it can be deleted by the
// caller.
base::OnceClosure delete_callback_;
+
+ base::WeakPtrFactory<PermissionRequest> weak_factory_{this};
};
} // namespace permissions