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

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: kill waitable event references 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') | no next file with comments »
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 29 matching lines...) Expand all
40 #include "net/base/host_port_pair.h" 40 #include "net/base/host_port_pair.h"
41 #include "url/gurl.h" 41 #include "url/gurl.h"
42 42
43 class IOThread; 43 class IOThread;
44 class PrefService; 44 class PrefService;
45 class Profile; 45 class Profile;
46 class ProfileIOData; 46 class ProfileIOData;
47 47
48 namespace base { 48 namespace base {
49 class ListValue; 49 class ListValue;
50 class WaitableEvent;
51 } 50 }
52 51
53 namespace net { 52 namespace net {
54 class HostResolver; 53 class HostResolver;
55 class SSLConfigService; 54 class SSLConfigService;
56 class ProxyService; 55 class ProxyService;
57 class TransportSecurityState; 56 class TransportSecurityState;
58 class URLRequestContextGetter; 57 class URLRequestContextGetter;
59 } 58 }
60 59
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // Clears the preferences used by the predictor. Must be called on the UI 164 // Clears the preferences used by the predictor. Must be called on the UI
166 // thread. 165 // thread.
167 void ClearPrefsOnUIThread(); 166 void ClearPrefsOnUIThread();
168 167
169 static void set_max_queueing_delay(int max_queueing_delay_ms); 168 static void set_max_queueing_delay(int max_queueing_delay_ms);
170 169
171 static void set_max_parallel_resolves(size_t max_parallel_resolves); 170 static void set_max_parallel_resolves(size_t max_parallel_resolves);
172 171
173 virtual void ShutdownOnUIThread(); 172 virtual void ShutdownOnUIThread();
174 173
174 void UpdatePrefsOnUIThread(std::unique_ptr<base::ListValue> startup_list,
175 std::unique_ptr<base::ListValue> referral_list);
176
175 // ------------- End UI thread methods. 177 // ------------- End UI thread methods.
176 178
177 // ------------- Start IO thread methods. 179 // ------------- Start IO thread methods.
178 180
181 void WriteDnsPrefetchState(base::ListValue* startup_list,
182 base::ListValue* referral_list);
183
179 // Cancel pending requests and prevent new ones from being made. 184 // Cancel pending requests and prevent new ones from being made.
180 void Shutdown(); 185 void Shutdown();
181 186
182 // In some circumstances, for privacy reasons, all results should be 187 // In some circumstances, for privacy reasons, all results should be
183 // discarded. This method gracefully handles that activity. 188 // discarded. This method gracefully handles that activity.
184 // Destroy all our internal state, which shows what names we've looked up, and 189 // 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 190 // how long each has taken, etc. etc. We also destroy records of suggesses
186 // (cache hits etc.). 191 // (cache hits etc.).
187 void DiscardAllResults(); 192 void DiscardAllResults();
188 193
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 236
232 // Renderer bundles up list and sends to this browser API via IPC. 237 // 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. 238 // TODO(csharrison): Use a GURL vector instead to include port and scheme.
234 void DnsPrefetchList(const std::vector<std::string>& hostnames); 239 void DnsPrefetchList(const std::vector<std::string>& hostnames);
235 240
236 // May be called from either the IO or UI thread and will PostTask 241 // May be called from either the IO or UI thread and will PostTask
237 // to the IO thread if necessary. 242 // to the IO thread if necessary.
238 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls, 243 void DnsPrefetchMotivatedList(const std::vector<GURL>& urls,
239 UrlInfo::ResolutionMotivation motivation); 244 UrlInfo::ResolutionMotivation motivation);
240 245
241 // May be called from either the IO or UI thread and will PostTask 246 // Called from the UI thread in response to the load event.
242 // to the IO thread if necessary.
243 void SaveStateForNextStartup(); 247 void SaveStateForNextStartup();
244 248
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 249 // May be called from either the IO or UI thread and will PostTask
250 // to the IO thread if necessary. 250 // to the IO thread if necessary.
251 void PreconnectUrl(const GURL& url, 251 void PreconnectUrl(const GURL& url,
252 const GURL& first_party_for_cookies, 252 const GURL& first_party_for_cookies,
253 UrlInfo::ResolutionMotivation motivation, 253 UrlInfo::ResolutionMotivation motivation,
254 bool allow_credentials, 254 bool allow_credentials,
255 int count); 255 int count);
256 256
257 void PreconnectUrlOnIOThread(const GURL& url, 257 void PreconnectUrlOnIOThread(const GURL& url,
258 const GURL& first_party_for_cookies, 258 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 533 // 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 534 // need to pre-resolve or pre-connect to when there is a navigation to the
535 // orginial hostname. 535 // orginial hostname.
536 Referrers referrers_; 536 Referrers referrers_;
537 537
538 // An observer for testing. 538 // An observer for testing.
539 PredictorObserver* observer_; 539 PredictorObserver* observer_;
540 540
541 std::unique_ptr<TimedCache> timed_cache_; 541 std::unique_ptr<TimedCache> timed_cache_;
542 542
543 std::unique_ptr<base::WeakPtrFactory<Predictor>> weak_factory_; 543 // TODO(csharrison): It is not great that two weak pointer factories are
544 // needed in this class. Let's split it into two classes that live on each
545 // thread.
546 //
547 // Weak factory for weak pointers that should be dereferenced on the IO
548 // thread.
549 std::unique_ptr<base::WeakPtrFactory<Predictor>> io_weak_factory_;
550
551 // Weak factory for weak pointers that should be dereferenced on the UI
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') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698