Commit b671a523 authored by csharrison's avatar csharrison Committed by Commit bot

[net/predictor] Remove unsafe usage of WeakPtrFactory

The post task to delete the predictor on the IO thread comes from the
profile destruction. Thus, callers into the predictor on the UI thread
with *valid* profiles are guaranteed to have their IO thread tasks queued
before the predictor is torn down on the IO thread.

This means we can safely use base::Unretained in place of weak pointers
in these cases.

BUG=671970

Review-Url: https://codereview.chromium.org/2559323008
Cr-Commit-Position: refs/heads/master@{#437704}
parent e6adcd2e
...@@ -312,9 +312,13 @@ std::vector<GURL> Predictor::GetPredictedUrlListAtStartup( ...@@ -312,9 +312,13 @@ std::vector<GURL> Predictor::GetPredictedUrlListAtStartup(
void Predictor::DiscardAllResultsAndClearPrefsOnUIThread() { void Predictor::DiscardAllResultsAndClearPrefsOnUIThread() {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, // The post task here is guaranteed to execute before the post task in
base::Bind(&Predictor::DiscardAllResults, // ShutdownOnUIThread, because the caller has a valid profile here. Note that
io_weak_factory_->GetWeakPtr())); // 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(); ClearPrefsOnUIThread();
} }
...@@ -688,11 +692,12 @@ void Predictor::SaveStateForNextStartup() { ...@@ -688,11 +692,12 @@ void Predictor::SaveStateForNextStartup() {
base::ListValue* startup_list_raw = startup_list.get(); base::ListValue* startup_list_raw = startup_list.get();
base::ListValue* referral_list_raw = referral_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::PostTaskAndReply(
BrowserThread::IO, FROM_HERE, BrowserThread::IO, FROM_HERE,
base::Bind(&Predictor::WriteDnsPrefetchState, base::Bind(&Predictor::WriteDnsPrefetchState, base::Unretained(this),
io_weak_factory_->GetWeakPtr(), startup_list_raw, startup_list_raw, referral_list_raw),
referral_list_raw),
base::Bind(&Predictor::UpdatePrefsOnUIThread, base::Bind(&Predictor::UpdatePrefsOnUIThread,
ui_weak_factory_->GetWeakPtr(), ui_weak_factory_->GetWeakPtr(),
base::Passed(std::move(startup_list)), base::Passed(std::move(startup_list)),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment