1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 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 7 // process. This allows the more standard DNS prefetching services, such as 8 // provided by Predictor to be left as more generally usable code, and possibly 9 // be shared across multiple client projects. 10 11 #ifndef CHROME_BROWSER_NET_PREDICTOR_API_H_ 12 #define CHROME_BROWSER_NET_PREDICTOR_API_H_ 13 #pragma once 14 15 16 #include <string> 17 #include <vector> 18 19 #include "base/memory/ref_counted.h" 20 #include "chrome/browser/autocomplete/autocomplete.h" 21 #include "chrome/browser/net/predictor.h" 22 23 namespace base { 24 class FieldTrial; 25 } 26 27 class PrefService; 28 29 namespace chrome_browser_net { 30 31 // Deletes |referral_list| when done. 32 void FinalizePredictorInitialization( 33 Predictor* global_predictor, 34 const std::vector<GURL>& urls_to_prefetch, 35 ListValue* referral_list); 36 37 // Free all resources allocated by FinalizePredictorInitialization. After that 38 // you must not call any function from this file. 39 void FreePredictorResources(); 40 41 //------------------------------------------------------------------------------ 42 // Global APIs relating to predictions in browser. 43 void EnablePredictor(bool enable); 44 void DiscardInitialNavigationHistory(); 45 void RegisterUserPrefs(PrefService* user_prefs); 46 47 // Renderer bundles up list and sends to this browser API via IPC. 48 // TODO(jar): Use UrlList instead to include port and scheme. 49 void DnsPrefetchList(const NameList& hostnames); 50 51 // This API is used by the autocomplete popup box (as user types). 52 // This will either preresolve the domain name, or possibly preconnect creating 53 // an open TCP/IP connection to the host. 54 void AnticipateOmniboxUrl(const GURL& url, bool preconnectable); 55 56 // This API should only be called when we're absolutely certain that we will 57 // be connecting to the URL. It will preconnect the url and it's associated 58 // subresource domains immediately. 59 void PreconnectUrlAndSubresources(const GURL& url); 60 61 // When displaying info in about:dns, the following API is called. 62 void PredictorGetHtmlInfo(std::string* output); 63 64 // Destroy the predictor's internal state: referrers and work queue. 65 void ClearPredictorCache(); 66 67 //------------------------------------------------------------------------------ 68 // When we navigate to a frame that may contain embedded resources, we may know 69 // in advance some other URLs that will need to be connected to (via TCP and 70 // sometimes SSL). This function initiates those connections 71 void PredictFrameSubresources(const GURL& url); 72 73 // During startup, we learn what the first N urls visited are, and then resolve 74 // the associated hosts ASAP during our next startup. 75 void LearnAboutInitialNavigation(const GURL& url); 76 77 // Call when we should learn from a navigation about a relationship to a 78 // subresource target, and its containing frame, which was loaded as a referring 79 // URL. 80 void LearnFromNavigation(const GURL& referring_url, const GURL& target_url); 81 82 //------------------------------------------------------------------------------ 83 void SavePredictorStateForNextStartupAndTrim(PrefService* prefs); 84 // Helper class to handle global init and shutdown. 85 class PredictorInit { 86 public: 87 // Too many concurrent lookups performed in parallel may overload a resolver, 88 // or may cause problems for a local router. The following limits that count. 89 static const size_t kMaxSpeculativeParallelResolves; 90 91 // When prefetch requests are queued beyond some period of time, then the 92 // system is congested, and we need to clear all queued requests to get out 93 // of that state. The following is the suggested default time limit. 94 static const int kMaxSpeculativeResolveQueueDelayMs; 95 96 PredictorInit(PrefService* user_prefs, PrefService* local_state, 97 bool preconnect_enabled); 98 ~PredictorInit(); 99 100 private: 101 // Maintain a field trial instance when we do A/B testing. 102 scoped_refptr<base::FieldTrial> trial_; 103 104 DISALLOW_COPY_AND_ASSIGN(PredictorInit); 105 }; 106 107 } // namespace chrome_browser_net 108 109 #endif // CHROME_BROWSER_NET_PREDICTOR_API_H_ 110