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

Side by Side Diff: chrome/browser/net/predictor.h

Issue 2084093002: Use lossy prefs in the net predictor, and update them more frequently (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@predictor_lru
Patch Set: ui thread weak factory :/ Created 4 years, 4 months 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/net/predictor.cc » ('j') | chrome/browser/net/predictor.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // A Predictor object is instantiated once in the browser process, and manages 5 // A Predictor object is instantiated once in the browser process, and manages
6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected 6 // both preresolution of hostnames, as well as TCP/IP preconnection to expected
7 // subresources. 7 // subresources.
8 // Most hostname lists are provided by the renderer processes, and include URLs 8 // Most hostname lists are provided by the renderer processes, and include URLs
9 // that *might* be used in the near future by the browsing user. One goal of 9 // that *might* be used in the near future by the browsing user. One goal of
10 // this class is to cause the underlying DNS structure to lookup a hostname 10 // this class is to cause the underlying DNS structure to lookup a hostname
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Clears the preferences used by the predictor. Must be called on the UI 165 // Clears the preferences used by the predictor. Must be called on the UI
166 // thread. 166 // thread.
167 void ClearPrefsOnUIThread(); 167 void ClearPrefsOnUIThread();
168 168
169 static void set_max_queueing_delay(int max_queueing_delay_ms); 169 static void set_max_queueing_delay(int max_queueing_delay_ms);
170 170
171 static void set_max_parallel_resolves(size_t max_parallel_resolves); 171 static void set_max_parallel_resolves(size_t max_parallel_resolves);
172 172
173 virtual void ShutdownOnUIThread(); 173 virtual void ShutdownOnUIThread();
174 174
175 void UpdatePrefsOnUIThread(std::unique_ptr<base::ListValue> startup_list,
176 std::unique_ptr<base::ListValue> referral_list);
177
175 // ------------- End UI thread methods. 178 // ------------- End UI thread methods.
176 179
177 // ------------- Start IO thread methods. 180 // ------------- Start IO thread methods.
178 181
182 void WriteDnsPrefetchState(base::ListValue* startup_list,
183 base::ListValue* referral_list);
184
179 // Cancel pending requests and prevent new ones from being made. 185 // Cancel pending requests and prevent new ones from being made.
180 void Shutdown(); 186 void Shutdown();
181 187
182 // In some circumstances, for privacy reasons, all results should be 188 // In some circumstances, for privacy reasons, all results should be
183 // discarded. This method gracefully handles that activity. 189 // discarded. This method gracefully handles that activity.
184 // Destroy all our internal state, which shows what names we've looked up, and 190 // Destroy all our internal state, which shows what names we've looked up, and
185 // how long each has taken, etc. etc. We also destroy records of suggesses 191 // how long each has taken, etc. etc. We also destroy records of suggesses
186 // (cache hits etc.). 192 // (cache hits etc.).
187 void DiscardAllResults(); 193 void DiscardAllResults();
188 194
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 237
232 // Renderer bundles up list and sends to this browser API via IPC. 238 // Renderer bundles up list and sends to this browser API via IPC.
233 // TODO(csharrison): Use a GURL vector instead to include port and scheme. 239 // TODO(csharrison): Use a GURL vector instead to include port and scheme.
234 void DnsPrefetchList(const std::vector<std::string>& hostnames); 240 void DnsPrefetchList(const std::vector<std::string>& hostnames);
235 241
236 // May be called from either the IO or UI thread and will PostTask 242 // May be called from either the IO or UI thread and will PostTask
237 // to the IO thread if necessary. 243 // to the IO thread if necessary.
238 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls, 244 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls,
239 UrlInfo::ResolutionMotivation motivation); 245 UrlInfo::ResolutionMotivation motivation);
240 246
241 // May be called from either the IO or UI thread and will PostTask 247 // Called from the UI thread in response to the load event.
242 // to the IO thread if necessary.
243 void SaveStateForNextStartup(); 248 void SaveStateForNextStartup();
244 249
245 void SaveDnsPrefetchStateForNextStartup(base::ListValue* startup_list,
246 base::ListValue* referral_list,
247 base::WaitableEvent* completion);
248
249 // May be called from either the IO or UI thread and will PostTask 250 // May be called from either the IO or UI thread and will PostTask
250 // to the IO thread if necessary. 251 // to the IO thread if necessary.
251 void PreconnectUrl(const GURL& url, 252 void PreconnectUrl(const GURL& url,
252 const GURL& first_party_for_cookies, 253 const GURL& first_party_for_cookies,
253 UrlInfo::ResolutionMotivation motivation, 254 UrlInfo::ResolutionMotivation motivation,
254 bool allow_credentials, 255 bool allow_credentials,
255 int count); 256 int count);
256 257
257 void PreconnectUrlOnIOThread(const GURL& url, 258 void PreconnectUrlOnIOThread(const GURL& url,
258 const GURL& first_party_for_cookies, 259 const GURL& first_party_for_cookies,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // we have a Referrer list. Each Referrer list has all hostnames we might 534 // we have a Referrer list. Each Referrer list has all hostnames we might
534 // need to pre-resolve or pre-connect to when there is a navigation to the 535 // need to pre-resolve or pre-connect to when there is a navigation to the
535 // orginial hostname. 536 // orginial hostname.
536 Referrers referrers_; 537 Referrers referrers_;
537 538
538 // An observer for testing. 539 // An observer for testing.
539 PredictorObserver* observer_; 540 PredictorObserver* observer_;
540 541
541 std::unique_ptr<TimedCache> timed_cache_; 542 std::unique_ptr<TimedCache> timed_cache_;
542 543
543 std::unique_ptr<base::WeakPtrFactory<Predictor>> weak_factory_; 544 // TODO(csharrison): It is not great that two weak pointer factories are
545 // needed in this class. Let's split it into two classes that live on each
546 // thread.
547 //
548 // Weak factory for weak pointers that should be dereferenced on the IO
549 // thread.
550 std::unique_ptr<base::WeakPtrFactory<Predictor>> io_weak_factory_;
551 // Weak factory for weak pointers that should be dereferenced on the UI
Bernhard Bauer 2016/08/01 09:06:24 Nit: Empty line before the comment?
Charlie Harrison 2016/08/01 12:38:24 Done.
552 // thread.
553 std::unique_ptr<base::WeakPtrFactory<Predictor>> ui_weak_factory_;
544 554
545 // Protects |preconnect_enabled_|. 555 // Protects |preconnect_enabled_|.
546 mutable base::Lock preconnect_enabled_lock_; 556 mutable base::Lock preconnect_enabled_lock_;
547 557
548 DISALLOW_COPY_AND_ASSIGN(Predictor); 558 DISALLOW_COPY_AND_ASSIGN(Predictor);
549 }; 559 };
550 560
551 // This version of the predictor is used for testing. 561 // This version of the predictor is used for testing.
552 class SimplePredictor : public Predictor { 562 class SimplePredictor : public Predictor {
553 public: 563 public:
554 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled) 564 explicit SimplePredictor(bool preconnect_enabled, bool predictor_enabled)
555 : Predictor(preconnect_enabled, predictor_enabled) {} 565 : Predictor(preconnect_enabled, predictor_enabled) {}
556 ~SimplePredictor() override {} 566 ~SimplePredictor() override {}
557 void InitNetworkPredictor(PrefService* user_prefs, 567 void InitNetworkPredictor(PrefService* user_prefs,
558 IOThread* io_thread, 568 IOThread* io_thread,
559 net::URLRequestContextGetter* getter, 569 net::URLRequestContextGetter* getter,
560 ProfileIOData* profile_io_data) override; 570 ProfileIOData* profile_io_data) override;
561 void ShutdownOnUIThread() override; 571 void ShutdownOnUIThread() override;
562 572
563 private: 573 private:
564 // These member functions return True for unittests. 574 // These member functions return True for unittests.
565 bool CanPrefetchAndPrerender() const override; 575 bool CanPrefetchAndPrerender() const override;
566 bool CanPreresolveAndPreconnect() const override; 576 bool CanPreresolveAndPreconnect() const override;
567 }; 577 };
568 578
569 } // namespace chrome_browser_net 579 } // namespace chrome_browser_net
570 580
571 #endif // CHROME_BROWSER_NET_PREDICTOR_H_ 581 #endif // CHROME_BROWSER_NET_PREDICTOR_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/net/predictor.cc » ('j') | chrome/browser/net/predictor.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698