 Chromium Code Reviews
 Chromium Code Reviews Issue 2559323008:
  [net/predictor] Remove unsafe usage of WeakPtrFactory  (Closed)
    
  
    Issue 2559323008:
  [net/predictor] Remove unsafe usage of WeakPtrFactory  (Closed) 
  | OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "chrome/browser/net/predictor.h" | 5 #include "chrome/browser/net/predictor.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <cmath> | 8 #include <cmath> | 
| 9 #include <iterator> | 9 #include <iterator> | 
| 10 #include <set> | 10 #include <set> | 
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 } | 305 } | 
| 306 | 306 | 
| 307 if (urls.empty()) | 307 if (urls.empty()) | 
| 308 urls.push_back(GURL("http://www.google.com:80")); | 308 urls.push_back(GURL("http://www.google.com:80")); | 
| 309 | 309 | 
| 310 return urls; | 310 return urls; | 
| 311 } | 311 } | 
| 312 | 312 | 
| 313 void Predictor::DiscardAllResultsAndClearPrefsOnUIThread() { | 313 void Predictor::DiscardAllResultsAndClearPrefsOnUIThread() { | 
| 314 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 314 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 315 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 315 // The post task here is guaranteed to execute before the post task in | 
| 316 base::Bind(&Predictor::DiscardAllResults, | 316 // ShutdownOnUIThread, because we must have a valid profile here. Note that | 
| 
mmenke
2016/12/09 22:01:18
nit:  --we
 | |
| 317 io_weak_factory_->GetWeakPtr())); | 317 // the ChromeNetBenchmarkingMessageFilter calls unsafely (an existing bug) | 
| 318 // into the profile, but doing so would crash before this point anyways. | |
| 319 BrowserThread::PostTask( | |
| 320 BrowserThread::IO, FROM_HERE, | |
| 321 base::Bind(&Predictor::DiscardAllResults, base::Unretained(this))); | |
| 318 ClearPrefsOnUIThread(); | 322 ClearPrefsOnUIThread(); | 
| 319 } | 323 } | 
| 320 | 324 | 
| 321 void Predictor::ClearPrefsOnUIThread() { | 325 void Predictor::ClearPrefsOnUIThread() { | 
| 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 326 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| 323 user_prefs_->ClearPref(prefs::kDnsPrefetchingStartupList); | 327 user_prefs_->ClearPref(prefs::kDnsPrefetchingStartupList); | 
| 324 user_prefs_->ClearPref(prefs::kDnsPrefetchingHostReferralList); | 328 user_prefs_->ClearPref(prefs::kDnsPrefetchingHostReferralList); | 
| 325 } | 329 } | 
| 326 | 330 | 
| 327 void Predictor::set_max_queueing_delay(int max_queueing_delay_ms) { | 331 void Predictor::set_max_queueing_delay(int max_queueing_delay_ms) { | 
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 681 return; | 685 return; | 
| 682 | 686 | 
| 683 std::unique_ptr<base::ListValue> startup_list(new base::ListValue); | 687 std::unique_ptr<base::ListValue> startup_list(new base::ListValue); | 
| 684 std::unique_ptr<base::ListValue> referral_list(new base::ListValue); | 688 std::unique_ptr<base::ListValue> referral_list(new base::ListValue); | 
| 685 | 689 | 
| 686 // Get raw pointers to pass to the first task. Ownership of the unique_ptrs | 690 // Get raw pointers to pass to the first task. Ownership of the unique_ptrs | 
| 687 // will be passed to the reply task. | 691 // will be passed to the reply task. | 
| 688 base::ListValue* startup_list_raw = startup_list.get(); | 692 base::ListValue* startup_list_raw = startup_list.get(); | 
| 689 base::ListValue* referral_list_raw = referral_list.get(); | 693 base::ListValue* referral_list_raw = referral_list.get(); | 
| 690 | 694 | 
| 695 // The first post task here is guaranteed to execute before the post task in | |
| 696 // ShutdownOnUIThread, because we have a valid profile here. | |
| 
mmenke
2016/12/09 22:01:18
nit: --we
 | |
| 691 BrowserThread::PostTaskAndReply( | 697 BrowserThread::PostTaskAndReply( | 
| 692 BrowserThread::IO, FROM_HERE, | 698 BrowserThread::IO, FROM_HERE, | 
| 693 base::Bind(&Predictor::WriteDnsPrefetchState, | 699 base::Bind(&Predictor::WriteDnsPrefetchState, base::Unretained(this), | 
| 694 io_weak_factory_->GetWeakPtr(), startup_list_raw, | 700 startup_list_raw, referral_list_raw), | 
| 695 referral_list_raw), | |
| 696 base::Bind(&Predictor::UpdatePrefsOnUIThread, | 701 base::Bind(&Predictor::UpdatePrefsOnUIThread, | 
| 697 ui_weak_factory_->GetWeakPtr(), | 702 ui_weak_factory_->GetWeakPtr(), | 
| 698 base::Passed(std::move(startup_list)), | 703 base::Passed(std::move(startup_list)), | 
| 699 base::Passed(std::move(referral_list)))); | 704 base::Passed(std::move(referral_list)))); | 
| 700 } | 705 } | 
| 701 | 706 | 
| 702 void Predictor::UpdatePrefsOnUIThread( | 707 void Predictor::UpdatePrefsOnUIThread( | 
| 703 std::unique_ptr<base::ListValue> startup_list, | 708 std::unique_ptr<base::ListValue> startup_list, | 
| 704 std::unique_ptr<base::ListValue> referral_list) { | 709 std::unique_ptr<base::ListValue> referral_list) { | 
| 705 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 710 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1196 } | 1201 } | 
| 1197 | 1202 | 
| 1198 void SimplePredictor::ShutdownOnUIThread() { | 1203 void SimplePredictor::ShutdownOnUIThread() { | 
| 1199 SetShutdown(true); | 1204 SetShutdown(true); | 
| 1200 } | 1205 } | 
| 1201 | 1206 | 
| 1202 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 1207 bool SimplePredictor::CanPrefetchAndPrerender() const { return true; } | 
| 1203 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 1208 bool SimplePredictor::CanPreresolveAndPreconnect() const { return true; } | 
| 1204 | 1209 | 
| 1205 } // namespace chrome_browser_net | 1210 } // namespace chrome_browser_net | 
| OLD | NEW |