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

Side by Side Diff: chrome/browser/prerender/prerender_local_predictor.h

Issue 23622012: Integrate the LocalPredictor with the Prerender Service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_
7 7
8 #include <map>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
11 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
12 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
13 #include "base/timer/timer.h" 14 #include "base/timer/timer.h"
14 #include "chrome/browser/common/cancelable_request.h" 15 #include "chrome/browser/common/cancelable_request.h"
15 #include "chrome/browser/history/visit_database.h" 16 #include "chrome/browser/history/visit_database.h"
17 #include "net/url_request/url_fetcher_delegate.h"
16 #include "url/gurl.h" 18 #include "url/gurl.h"
17 19
18 class HistoryService; 20 class HistoryService;
19 21
20 namespace content { 22 namespace content {
21 class SessionStorageNamespace; 23 class SessionStorageNamespace;
22 class WebContents; 24 class WebContents;
23 } 25 }
24 26
25 namespace gfx { 27 namespace gfx {
26 class Size; 28 class Size;
27 } 29 }
28 30
29 namespace prerender { 31 namespace prerender {
30 32
31 class PrerenderHandle; 33 class PrerenderHandle;
32 class PrerenderManager; 34 class PrerenderManager;
33 35
34 // PrerenderLocalPredictor maintains local browsing history to make prerender 36 // PrerenderLocalPredictor maintains local browsing history to make prerender
35 // predictions. 37 // predictions.
36 // At this point, the class is not actually creating prerenders, but just 38 // At this point, the class is not actually creating prerenders, but just
37 // recording timing stats about the effect prerendering would have. 39 // recording timing stats about the effect prerendering would have.
38 class PrerenderLocalPredictor : public history::VisitDatabaseObserver { 40 class PrerenderLocalPredictor : public history::VisitDatabaseObserver,
41 public net::URLFetcherDelegate {
39 public: 42 public:
40 struct LocalPredictorURLInfo; 43 struct LocalPredictorURLInfo;
41 struct LocalPredictorURLLookupInfo; 44 struct CandidatePrerenderInfo;
42 enum Event { 45 enum Event {
43 EVENT_CONSTRUCTED = 0, 46 EVENT_CONSTRUCTED = 0,
44 EVENT_INIT_SCHEDULED = 1, 47 EVENT_INIT_SCHEDULED = 1,
45 EVENT_INIT_STARTED = 2, 48 EVENT_INIT_STARTED = 2,
46 EVENT_INIT_FAILED_NO_HISTORY = 3, 49 EVENT_INIT_FAILED_NO_HISTORY = 3,
47 EVENT_INIT_SUCCEEDED = 4, 50 EVENT_INIT_SUCCEEDED = 4,
48 EVENT_ADD_VISIT = 5, 51 EVENT_ADD_VISIT = 5,
49 EVENT_ADD_VISIT_INITIALIZED = 6, 52 EVENT_ADD_VISIT_INITIALIZED = 6,
50 EVENT_ADD_VISIT_PRERENDER_IDENTIFIED = 7, 53 EVENT_ADD_VISIT_PRERENDER_IDENTIFIED = 7,
51 EVENT_ADD_VISIT_RELEVANT_TRANSITION = 8, 54 EVENT_ADD_VISIT_RELEVANT_TRANSITION = 8,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 EVENT_TAB_HELPER_URL_SEEN = 46, 92 EVENT_TAB_HELPER_URL_SEEN = 46,
90 EVENT_TAB_HELPER_URL_SEEN_MATCH = 47, 93 EVENT_TAB_HELPER_URL_SEEN_MATCH = 47,
91 EVENT_TAB_HELPER_URL_SEEN_NAMESPACE_MATCH = 48, 94 EVENT_TAB_HELPER_URL_SEEN_NAMESPACE_MATCH = 48,
92 EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND = 49, 95 EVENT_PRERENDER_URL_LOOKUP_MULTIPLE_SOURCE_WEBCONTENTS_FOUND = 49,
93 EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST = 50, 96 EVENT_CONTINUE_PRERENDER_CHECK_ON_SIDE_EFFECT_FREE_WHITELIST = 50,
94 EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL = 51, 97 EVENT_CONTINUE_PRERENDER_CHECK_EXAMINE_NEXT_URL = 51,
95 EVENT_ISSUE_PRERENDER_ALREADY_PRERENDERING = 52, 98 EVENT_ISSUE_PRERENDER_ALREADY_PRERENDERING = 52,
96 EVENT_ISSUE_PRERENDER_NEW_PRERENDER = 53, 99 EVENT_ISSUE_PRERENDER_NEW_PRERENDER = 53,
97 EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER = 54, 100 EVENT_ISSUE_PRERENDER_CANCELLED_OLD_PRERENDER = 54,
98 EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING = 55, 101 EVENT_CONTINUE_PRERENDER_CHECK_FALLTHROUGH_PRERENDERING = 55,
102 EVENT_PRERENDER_URL_LOOKUP_SUCCESS = 56,
103 EVENT_PRERENDER_SERVICE_DISABLED = 57,
104 EVENT_PRERENDER_SERVICE_ISSUED_LOOKUP = 58,
105 EVENT_PRERENDER_SERVICE_LOOKUP_TIMED_OUT = 59,
106 EVENT_PRERENDER_SERVICE_RECEIVED_RESULT = 60,
107 EVENT_PRERENDER_SERVICE_NO_RECORD_FOR_RESULT = 61,
108 EVENT_PRERENDER_SERVICE_PARSED_CORRECTLY = 62,
109 EVENT_PRERENDER_SERVICE_PARSE_ERROR = 63,
110 EVENT_PRERENDER_SERVICE_PARSE_ERROR_INCORRECT_JSON = 64,
111 EVENT_PRERENDER_SERVICE_HINTING_TIMED_OUT = 65,
112 EVENT_PRERENDER_SERVICE_HINTING_URL_LOOKUP_TIMED_OUT = 66,
113 EVENT_PRERENDER_SERVICE_CANDIDATE_URL_LOOKUP_TIMED_OUT = 67,
114 EVENT_CONTINUE_PRERENDER_CHECK_ON_SERVICE_WHITELIST = 68,
99 EVENT_MAX_VALUE 115 EVENT_MAX_VALUE
100 }; 116 };
101 117
102 // A PrerenderLocalPredictor is owned by the PrerenderManager specified 118 // A PrerenderLocalPredictor is owned by the PrerenderManager specified
103 // in the constructor. It will be destoryed at the time its owning 119 // in the constructor. It will be destoryed at the time its owning
104 // PrerenderManager is destroyed. 120 // PrerenderManager is destroyed.
105 explicit PrerenderLocalPredictor(PrerenderManager* prerender_manager); 121 explicit PrerenderLocalPredictor(PrerenderManager* prerender_manager);
106 virtual ~PrerenderLocalPredictor(); 122 virtual ~PrerenderLocalPredictor();
107 123
108 void Shutdown(); 124 void Shutdown();
109 125
110 // history::VisitDatabaseObserver implementation 126 // history::VisitDatabaseObserver implementation
111 virtual void OnAddVisit(const history::BriefVisitInfo& info) OVERRIDE; 127 virtual void OnAddVisit(const history::BriefVisitInfo& info) OVERRIDE;
112 128
113 void OnGetInitialVisitHistory( 129 void OnGetInitialVisitHistory(
114 scoped_ptr<std::vector<history::BriefVisitInfo> > visit_history); 130 scoped_ptr<std::vector<history::BriefVisitInfo> > visit_history);
115 131
116 void OnPLTEventForURL(const GURL& url, base::TimeDelta page_load_time); 132 void OnPLTEventForURL(const GURL& url, base::TimeDelta page_load_time);
117 133
118 void OnTabHelperURLSeen(const GURL& url, content::WebContents* web_contents); 134 void OnTabHelperURLSeen(const GURL& url, content::WebContents* web_contents);
119 135
136 void virtual OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE;
jam 2013/08/30 20:34:30 usually we write // net::URLFetcherDelegate imple
tburkard 2013/08/30 20:59:01 Done.
137
120 private: 138 private:
121 struct PrerenderProperties; 139 struct PrerenderProperties;
122 HistoryService* GetHistoryIfExists() const; 140 HistoryService* GetHistoryIfExists() const;
123 void Init(); 141 void Init();
124 bool IsPrerenderStillValid(PrerenderProperties* prerender) const; 142 bool IsPrerenderStillValid(PrerenderProperties* prerender) const;
125 bool DoesPrerenderMatchPLTRecord(PrerenderProperties* prerender, 143 bool DoesPrerenderMatchPLTRecord(PrerenderProperties* prerender,
126 const GURL& url, 144 const GURL& url,
127 base::TimeDelta plt) const; 145 base::TimeDelta plt) const;
128 void RecordEvent(Event event) const; 146 void RecordEvent(Event event) const;
129 147
130 void OnLookupURL(scoped_ptr<LocalPredictorURLLookupInfo> info); 148 void OnLookupURL(scoped_ptr<CandidatePrerenderInfo> info);
149
150 // Lookup the prerender candidate in the Prerender Service (if applicable).
151 void DoPrerenderServiceCheck(scoped_ptr<CandidatePrerenderInfo> info);
152
153 // Lookup the prerender candidate in the LoggedIn Predictor.
154 void DoLoggedInLookup(scoped_ptr<CandidatePrerenderInfo> info);
131 155
132 // Returns an element of issued_prerenders_, which should be replaced 156 // Returns an element of issued_prerenders_, which should be replaced
133 // by a new prerender of the priority indicated, or NULL, if the priority 157 // by a new prerender of the priority indicated, or NULL, if the priority
134 // is too low. 158 // is too low.
135 PrerenderProperties* GetIssuedPrerenderSlotForPriority(double priority); 159 PrerenderProperties* GetIssuedPrerenderSlotForPriority(double priority);
136 160
137 void ContinuePrerenderCheck( 161 void ContinuePrerenderCheck(scoped_ptr<CandidatePrerenderInfo> info);
138 scoped_refptr<content::SessionStorageNamespace> session_storage_namespace,
139 scoped_ptr<gfx::Size> size,
140 scoped_ptr<LocalPredictorURLLookupInfo> info);
141 void LogCandidateURLStats(const GURL& url) const; 162 void LogCandidateURLStats(const GURL& url) const;
142 void IssuePrerender(scoped_refptr<content::SessionStorageNamespace> 163 void IssuePrerender(scoped_ptr<CandidatePrerenderInfo> info,
143 session_storage_namespace, 164 scoped_ptr<LocalPredictorURLInfo> url_info,
144 scoped_ptr<gfx::Size> size,
145 scoped_ptr<LocalPredictorURLInfo> info,
146 PrerenderProperties* prerender_properties); 165 PrerenderProperties* prerender_properties);
166 void MaybeCancelURLFetcher(net::URLFetcher* fetcher);
167 typedef std::map<net::URLFetcher*, CandidatePrerenderInfo*>
168 OutstandingFetchers;
jam 2013/08/30 20:34:30 indent
tburkard 2013/08/30 20:59:01 Done.
169 OutstandingFetchers outstanding_prerender_service_requests_;
147 PrerenderManager* prerender_manager_; 170 PrerenderManager* prerender_manager_;
148 base::OneShotTimer<PrerenderLocalPredictor> timer_; 171 base::OneShotTimer<PrerenderLocalPredictor> timer_;
149 172
150 // Delay after which to initialize, to avoid putting to much load on the 173 // Delay after which to initialize, to avoid putting to much load on the
151 // database thread early on when Chrome is starting up. 174 // database thread early on when Chrome is starting up.
152 static const int kInitDelayMs = 5 * 1000; 175 static const int kInitDelayMs = 5 * 1000;
153 176
154 // Whether we're registered with the history service as a 177 // Whether we're registered with the history service as a
155 // history::VisitDatabaseObserver. 178 // history::VisitDatabaseObserver.
156 bool is_visit_database_observer_; 179 bool is_visit_database_observer_;
(...skipping 10 matching lines...) Expand all
167 base::hash_set<int64> url_whitelist_; 190 base::hash_set<int64> url_whitelist_;
168 191
169 base::WeakPtrFactory<PrerenderLocalPredictor> weak_factory_; 192 base::WeakPtrFactory<PrerenderLocalPredictor> weak_factory_;
170 193
171 DISALLOW_COPY_AND_ASSIGN(PrerenderLocalPredictor); 194 DISALLOW_COPY_AND_ASSIGN(PrerenderLocalPredictor);
172 }; 195 };
173 196
174 } // namespace prerender 197 } // namespace prerender
175 198
176 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_ 199 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_LOCAL_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698