Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1479)

Unified Diff: chrome/browser/net/predictor.cc

Issue 2559323008: [net/predictor] Remove unsafe usage of WeakPtrFactory (Closed)
Patch Set: s/we have/the caller has/g Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/predictor.cc
diff --git a/chrome/browser/net/predictor.cc b/chrome/browser/net/predictor.cc
index 0ee6a62e861be9e0b8ac36203e4b84b64f066f48..72266b380b2840a4891eb675bc08d1b063f435e1 100644
--- a/chrome/browser/net/predictor.cc
+++ b/chrome/browser/net/predictor.cc
@@ -312,9 +312,13 @@ std::vector<GURL> Predictor::GetPredictedUrlListAtStartup(
void Predictor::DiscardAllResultsAndClearPrefsOnUIThread() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&Predictor::DiscardAllResults,
- io_weak_factory_->GetWeakPtr()));
+ // The post task here is guaranteed to execute before the post task in
+ // ShutdownOnUIThread, because the caller has a valid profile here. Note that
+ // the ChromeNetBenchmarkingMessageFilter calls unsafely (an existing bug)
+ // into the profile, but doing so would crash before this point anyways.
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&Predictor::DiscardAllResults, base::Unretained(this)));
ClearPrefsOnUIThread();
}
@@ -688,11 +692,12 @@ void Predictor::SaveStateForNextStartup() {
base::ListValue* startup_list_raw = startup_list.get();
base::ListValue* referral_list_raw = referral_list.get();
+ // The first post task here is guaranteed to execute before the post task in
+ // ShutdownOnUIThread, because the caller has a valid profile.
BrowserThread::PostTaskAndReply(
BrowserThread::IO, FROM_HERE,
- base::Bind(&Predictor::WriteDnsPrefetchState,
- io_weak_factory_->GetWeakPtr(), startup_list_raw,
- referral_list_raw),
+ base::Bind(&Predictor::WriteDnsPrefetchState, base::Unretained(this),
+ startup_list_raw, referral_list_raw),
base::Bind(&Predictor::UpdatePrefsOnUIThread,
ui_weak_factory_->GetWeakPtr(),
base::Passed(std::move(startup_list)),
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698