From e94e2c02a515f1faf513c3a9236c69f5ef68708b Mon Sep 17 00:00:00 2001 From: Jocelyn Liu Date: Wed, 10 Feb 2021 22:11:03 -0800 Subject: [PATCH] Remove base::Unretained usage in BraveBrowsingDataRemoverDelegate::ClearIPFSCache --- .../browsing_data/brave_browsing_data_remover_delegate.cc | 8 ++++++-- .../browsing_data/brave_browsing_data_remover_delegate.h | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/browser/browsing_data/brave_browsing_data_remover_delegate.cc b/browser/browsing_data/brave_browsing_data_remover_delegate.cc index 032cf16c3790..790aaf7a5433 100644 --- a/browser/browsing_data/brave_browsing_data_remover_delegate.cc +++ b/browser/browsing_data/brave_browsing_data_remover_delegate.cc @@ -39,6 +39,8 @@ BraveBrowsingDataRemoverDelegate::BraveBrowsingDataRemoverDelegate( : ChromeBrowsingDataRemoverDelegate(browser_context), profile_(Profile::FromBrowserContext(browser_context)) {} +BraveBrowsingDataRemoverDelegate::~BraveBrowsingDataRemoverDelegate() = default; + void BraveBrowsingDataRemoverDelegate::RemoveEmbedderData( const base::Time& delete_begin, const base::Time& delete_end, @@ -170,9 +172,11 @@ void BraveBrowsingDataRemoverDelegate::ClearIPFSCache() { } base::ThreadPool::PostTaskAndReply( - FROM_HERE, {base::TaskPriority::USER_VISIBLE, base::MayBlock()}, + FROM_HERE, + {base::TaskPriority::USER_VISIBLE, base::MayBlock(), + base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN}, base::BindOnce(&BraveBrowsingDataRemoverDelegate::WaitForIPFSRepoGC, - base::Unretained(this), base::Passed(&process)), + weak_ptr_factory_.GetWeakPtr(), base::Passed(&process)), CreateTaskCompletionClosure(TracingDataType::kIPFSCache)); } #endif // BUILDFLAG(IPFS_ENABLED) diff --git a/browser/browsing_data/brave_browsing_data_remover_delegate.h b/browser/browsing_data/brave_browsing_data_remover_delegate.h index ad822e13690a..ab640d9325af 100644 --- a/browser/browsing_data/brave_browsing_data_remover_delegate.h +++ b/browser/browsing_data/brave_browsing_data_remover_delegate.h @@ -6,6 +6,7 @@ #ifndef BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_ #define BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_ +#include "base/memory/weak_ptr.h" #include "base/time/time.h" #include "brave/components/ipfs/buildflags/buildflags.h" #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" @@ -25,7 +26,7 @@ class BraveBrowsingDataRemoverDelegate public: explicit BraveBrowsingDataRemoverDelegate( content::BrowserContext* browser_context); - ~BraveBrowsingDataRemoverDelegate() override = default; + ~BraveBrowsingDataRemoverDelegate() override; BraveBrowsingDataRemoverDelegate( const BraveBrowsingDataRemoverDelegate&) = delete; @@ -52,6 +53,8 @@ class BraveBrowsingDataRemoverDelegate #endif Profile* profile_; + base::WeakPtrFactory weak_ptr_factory_{ + this}; }; #endif // BRAVE_BROWSER_BROWSING_DATA_BRAVE_BROWSING_DATA_REMOVER_DELEGATE_H_