| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This is the global interface for the dns prefetch services. It centralizes | 5 // This is the global interface for the dns prefetch services. It centralizes |
| 6 // initialization, along with all the callbacks etc. to connect to the browser | 6 // initialization, along with all the callbacks etc. to connect to the browser |
| 7 // process. This allows the more standard DNS prefetching services, such as | 7 // process. This allows the more standard DNS prefetching services, such as |
| 8 // provided by DnsMaster to be left as more generally usable code, and possibly | 8 // provided by DnsMaster to be left as more generally usable code, and possibly |
| 9 // be shared across multiple client projects. | 9 // be shared across multiple client projects. |
| 10 | 10 |
| 11 #ifndef CHROME_BROWSER_NET_DNS_GLOBAL_H_ | 11 #ifndef CHROME_BROWSER_NET_DNS_GLOBAL_H_ |
| 12 #define CHROME_BROWSER_NET_DNS_GLOBAL_H_ | 12 #define CHROME_BROWSER_NET_DNS_GLOBAL_H_ |
| 13 | 13 |
| 14 #include "chrome/browser/net/dns_master.h" | |
| 15 | 14 |
| 16 #include <string> | 15 #include <string> |
| 17 | 16 |
| 17 #include "base/field_trial.h" |
| 18 #include "base/scoped_ptr.h" |
| 19 #include "chrome/browser/net/dns_master.h" |
| 20 |
| 18 class PrefService; | 21 class PrefService; |
| 19 | 22 |
| 20 namespace net { | 23 namespace net { |
| 21 class HostResolver; | 24 class HostResolver; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace chrome_browser_net { | 27 namespace chrome_browser_net { |
| 25 | 28 |
| 26 // Initialize dns prefetching subsystem. Must be called before any other | 29 // Initialize dns prefetching subsystem. Must be called before any other |
| 27 // functions. | 30 // functions. |
| 28 void InitDnsPrefetch(size_t max_concurrent, PrefService* user_prefs); | 31 void InitDnsPrefetch(TimeDelta max_queue_delay, size_t max_concurrent, |
| 32 PrefService* user_prefs); |
| 29 | 33 |
| 30 // Cancel pending lookup requests and don't make new ones. Does nothing | 34 // Cancel pending lookup requests and don't make new ones. Does nothing |
| 31 // if dns prefetching has not been initialized (to simplify its usage). | 35 // if dns prefetching has not been initialized (to simplify its usage). |
| 32 void EnsureDnsPrefetchShutdown(); | 36 void EnsureDnsPrefetchShutdown(); |
| 33 | 37 |
| 34 // Free all resources allocated by InitDnsPrefetch. After that you must not call | 38 // Free all resources allocated by InitDnsPrefetch. After that you must not call |
| 35 // any function from this file. | 39 // any function from this file. |
| 36 void FreeDnsPrefetchResources(); | 40 void FreeDnsPrefetchResources(); |
| 37 | 41 |
| 38 // Lazily allocates a HostResolver to be used by the DNS prefetch system, on | 42 // Lazily allocates a HostResolver to be used by the DNS prefetch system, on |
| (...skipping 20 matching lines...) Expand all Loading... |
| 59 | 63 |
| 60 // Functions to save and restore sub-resource references. | 64 // Functions to save and restore sub-resource references. |
| 61 void SaveSubresourceReferrers(PrefService* local_state); | 65 void SaveSubresourceReferrers(PrefService* local_state); |
| 62 void RestoreSubresourceReferrers(PrefService* local_state); | 66 void RestoreSubresourceReferrers(PrefService* local_state); |
| 63 void TrimSubresourceReferrers(); | 67 void TrimSubresourceReferrers(); |
| 64 | 68 |
| 65 //------------------------------------------------------------------------------ | 69 //------------------------------------------------------------------------------ |
| 66 // Helper class to handle global init and shutdown. | 70 // Helper class to handle global init and shutdown. |
| 67 class DnsPrefetcherInit { | 71 class DnsPrefetcherInit { |
| 68 public: | 72 public: |
| 69 // Too many concurrent lookups negate benefits of prefetching by trashing the | 73 // Too many concurrent lookups negate benefits of prefetching by trashing |
| 70 // OS cache before all resource loading is complete. This is the default. | 74 // the OS cache before all resource loading is complete. |
| 75 // This is the default. |
| 71 static const size_t kMaxConcurrentLookups; | 76 static const size_t kMaxConcurrentLookups; |
| 72 | 77 |
| 73 DnsPrefetcherInit(size_t max_concurrent, PrefService* user_prefs) { | 78 // When prefetch requests are queued beyond some period of time, then the |
| 74 InitDnsPrefetch(max_concurrent, user_prefs); | 79 // system is congested, and we need to clear all queued requests to get out |
| 75 } | 80 // of that state. The following is the suggested default time limit. |
| 81 static const int kMaxQueueingDelayMs; |
| 76 | 82 |
| 77 ~DnsPrefetcherInit() { | 83 DnsPrefetcherInit(PrefService* user_prefs, PrefService* local_state); |
| 78 FreeDnsPrefetchResources(); | 84 ~DnsPrefetcherInit(); |
| 79 } | |
| 80 | 85 |
| 81 private: | 86 private: |
| 87 // Maintain a field trial instance when we do A/B testing. |
| 88 scoped_refptr<FieldTrial> trial_; |
| 89 |
| 82 DISALLOW_COPY_AND_ASSIGN(DnsPrefetcherInit); | 90 DISALLOW_COPY_AND_ASSIGN(DnsPrefetcherInit); |
| 83 }; | 91 }; |
| 84 | 92 |
| 85 } // namespace chrome_browser_net | 93 } // namespace chrome_browser_net |
| 86 | 94 |
| 87 #endif // CHROME_BROWSER_NET_DNS_GLOBAL_H_ | 95 #endif // CHROME_BROWSER_NET_DNS_GLOBAL_H_ |
| OLD | NEW |