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

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

Issue 10553029: Handle interface to prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more standard code, simpler handle, no class explosion Created 8 years, 6 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_CONTENTS_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <list> 9 #include <list>
10 #include <string> 10 #include <string>
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 31
32 namespace content { 32 namespace content {
33 class RenderViewHost; 33 class RenderViewHost;
34 class SessionStorageNamespace; 34 class SessionStorageNamespace;
35 class WebContents; 35 class WebContents;
36 } 36 }
37 37
38 namespace prerender { 38 namespace prerender {
39 39
40 class PrerenderHandle;
40 class PrerenderManager; 41 class PrerenderManager;
41 class PrerenderRenderViewHostObserver; 42 class PrerenderRenderViewHostObserver;
42 class PrerenderTracker; 43 class PrerenderTracker;
43 44
44 class PrerenderContents : public content::NotificationObserver, 45 class PrerenderContents : public content::NotificationObserver,
45 public content::WebContentsObserver { 46 public content::WebContentsObserver {
46 public: 47 public:
47 // PrerenderContents::Create uses the currently registered Factory to create 48 // PrerenderContents::Create uses the currently registered Factory to create
48 // the PrerenderContents. Factory is intended for testing. 49 // the PrerenderContents. Factory is intended for testing.
49 class Factory { 50 class Factory {
50 public: 51 public:
51 Factory() {} 52 Factory() {}
52 virtual ~Factory() {} 53 virtual ~Factory() {}
53 54
54 // Ownership is not transfered through this interface as prerender_manager, 55 // Ownership is not transfered through this interface as prerender_manager,
55 // prerender_tracker, and profile are stored as weak pointers. 56 // prerender_tracker, and profile are stored as weak pointers.
56 virtual PrerenderContents* CreatePrerenderContents( 57 virtual PrerenderContents* CreatePrerenderContents(
57 PrerenderManager* prerender_manager, 58 PrerenderManager* prerender_manager,
58 PrerenderTracker* prerender_tracker, 59 PrerenderTracker* prerender_tracker,
59 Profile* profile, 60 Profile* profile,
60 const GURL& url, 61 const GURL& url,
61 const content::Referrer& referrer, 62 const content::Referrer& referrer,
62 Origin origin, 63 Origin origin,
63 uint8 experiment_id) = 0; 64 uint8 experiment_id) = 0;
64 65
65 private: 66 private:
66 DISALLOW_COPY_AND_ASSIGN(Factory); 67 DISALLOW_COPY_AND_ASSIGN(Factory);
67 }; 68 };
68 69
70 // Predicate functor used in maps to sort by load start time.
71 class LessThanByLoadStartTime {
dominich 2012/06/22 15:36:16 public?
72 public:
73 bool operator() (const PrerenderContents* lhs,
74 const PrerenderContents* rhs) const;
75 };
76
69 // Information on pages that the prerendered page has tried to prerender. 77 // Information on pages that the prerendered page has tried to prerender.
70 struct PendingPrerenderInfo; 78 struct PendingPrerenderInfo;
71 typedef std::list<PendingPrerenderInfo> PendingPrerenderList; 79 typedef std::list<PendingPrerenderInfo> PendingPrerenderList;
72 80
73 // Indicates how this PrerenderContents relates to MatchComplete. This is to 81 // Indicates how this PrerenderContents relates to MatchComplete. This is to
74 // figure out which histograms to use to record the FinalStatus, Match (record 82 // figure out which histograms to use to record the FinalStatus, Match (record
75 // all prerenders and control group prerenders) or MatchComplete (record 83 // all prerenders and control group prerenders) or MatchComplete (record
76 // running prerenders only in the way they would have been recorded in the 84 // running prerenders only in the way they would have been recorded in the
77 // control group). 85 // control group).
78 enum MatchCompleteStatus { 86 enum MatchCompleteStatus {
79 // A regular prerender which will be recorded both in Match and 87 // A regular prerender which will be recorded both in Match and
80 // MatchComplete. 88 // MatchComplete.
81 MATCH_COMPLETE_DEFAULT, 89 MATCH_COMPLETE_DEFAULT,
82 // A prerender that used to be a regular prerender, but has since been 90 // A prerender that used to be a regular prerender, but has since been
83 // replaced by a MatchComplete dummy. Therefore, we will record this only 91 // replaced by a MatchComplete dummy. Therefore, we will record this only
84 // for Match, but not for MatchComplete. 92 // for Match, but not for MatchComplete.
85 MATCH_COMPLETE_REPLACED, 93 MATCH_COMPLETE_REPLACED,
86 // A prerender that is a MatchComplete dummy replacing a regular prerender. 94 // A prerender that is a MatchComplete dummy replacing a regular prerender.
87 // In the control group, our prerender never would have been canceled, so 95 // In the control group, our prerender never would have been canceled, so
88 // we record in MatchComplete but not Match. 96 // we record in MatchComplete but not Match.
89 MATCH_COMPLETE_REPLACEMENT, 97 MATCH_COMPLETE_REPLACEMENT,
90 // A prerender that is a MatchComplete dummy, early in the process of being 98 // A prerender that is a MatchComplete dummy, early in the process of being
91 // created. This prerender should not fail. Record for MatchComplete, but 99 // created. This prerender should not fail. Record for MatchComplete, but
92 // not Match. 100 // not Match.
93 MATCH_COMPLETE_REPLACEMENT_PENDING, 101 MATCH_COMPLETE_REPLACEMENT_PENDING,
94 }; 102 };
95 103
96 virtual ~PrerenderContents(); 104 virtual ~PrerenderContents();
97 105
106 // For MatchComplete correctness, create a dummy replacement prerender content s
107 // to stand in for this prerender contents that (which we are about to destroy ).
108 PrerenderContents* CreateDummyReplacement() const;
109
98 bool Init(); 110 bool Init();
99 111
100 static Factory* CreateFactory(); 112 static Factory* CreateFactory();
101 113
102 // Start rendering the contents in the prerendered state. If 114 // Start rendering the contents in the prerendered state. If
103 // |is_control_group| is true, this will go through some of the mechanics of 115 // |is_control_group| is true, this will go through some of the mechanics of
104 // starting a prerender, without actually creating the RenderView. 116 // starting a prerender, without actually creating the RenderView.
105 // |creator_child_id| is the id of the child process that caused the prerender 117 // |creator_child_id| is the id of the child process that caused the prerender
106 // to be created, and is needed so that the prerendered URLs can be sent to it 118 // to be created, and is needed so that the prerendered URLs can be sent to it
107 // so render-initiated navigations will swap in the prerendered page. |size| 119 // so render-initiated navigations will swap in the prerendered page. |size|
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 158
147 // Set the final status for how the PrerenderContents was used. This 159 // Set the final status for how the PrerenderContents was used. This
148 // should only be called once, and should be called before the prerender 160 // should only be called once, and should be called before the prerender
149 // contents are destroyed. 161 // contents are destroyed.
150 void set_final_status(FinalStatus final_status); 162 void set_final_status(FinalStatus final_status);
151 FinalStatus final_status() const { return final_status_; } 163 FinalStatus final_status() const { return final_status_; }
152 164
153 Origin origin() const { return origin_; } 165 Origin origin() const { return origin_; }
154 uint8 experiment_id() const { return experiment_id_; } 166 uint8 experiment_id() const { return experiment_id_; }
155 167
168 int client_count() const { return client_count_; }
dominich 2012/06/22 15:36:16 naming nit: I don't know what a client is or what
169 void IncrementClientCount();
170 void DecrementClientCount();
171
156 base::TimeTicks load_start_time() const { return load_start_time_; } 172 base::TimeTicks load_start_time() const { return load_start_time_; }
157 173
158 // Indicates whether this prerendered page can be used for the provided 174 // Indicates whether this prerendered page can be used for the provided
159 // URL, i.e. whether there is a match. |matching_url| is optional and will be 175 // URL, i.e. whether there is a match. |matching_url| is optional and will be
dominich 2012/06/22 15:36:16 comment needs updating
160 // set to the URL that is found as a match if it is provided. 176 // set to the URL that is found as a match if it is provided.
161 // TODO(gavinp,mmenke): Rework matching to be based on both the URL 177 // TODO(gavinp,mmenke): Rework matching to be based on both the URL
162 // and the session WebStorage. 178 // and the session WebStorage.
163 bool MatchesURL(const GURL& url, GURL* matching_url) const; 179 bool Matches(
180 const GURL& url,
181 const content::SessionStorageNamespace* session_storage_namespace);
164 182
165 void OnJSOutOfMemory(); 183 void OnJSOutOfMemory();
166 bool ShouldSuppressDialogs(); 184 bool ShouldSuppressDialogs();
167 185
168 // content::WebContentsObserver implementation. 186 // content::WebContentsObserver implementation.
169 virtual void DidStopLoading() OVERRIDE; 187 virtual void DidStopLoading() OVERRIDE;
170 virtual void DidStartProvisionalLoadForFrame( 188 virtual void DidStartProvisionalLoadForFrame(
171 int64 frame_id, 189 int64 frame_id,
172 bool is_main_frame, 190 bool is_main_frame,
173 const GURL& validated_url, 191 const GURL& validated_url,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 void CommitHistory(TabContents* tab); 227 void CommitHistory(TabContents* tab);
210 228
211 base::Value* GetAsValue() const; 229 base::Value* GetAsValue() const;
212 230
213 // Returns whether a pending cross-site navigation is happening. 231 // Returns whether a pending cross-site navigation is happening.
214 // This could happen with renderer-issued navigations, such as a 232 // This could happen with renderer-issued navigations, such as a
215 // MouseEvent being dispatched by a link to a website installed as an app. 233 // MouseEvent being dispatched by a link to a website installed as an app.
216 bool IsCrossSiteNavigationPending() const; 234 bool IsCrossSiteNavigationPending() const;
217 235
218 // Adds a pending prerender to the list. 236 // Adds a pending prerender to the list.
219 virtual void AddPendingPrerender(const GURL& url, 237 virtual void AddPendingPrerender(scoped_ptr<PrerenderHandle> prerender_handle,
dominich 2012/06/22 15:36:16 I don't know why, but seeing a scoped_ptr<> passed
238 const GURL& url,
220 const content::Referrer& referrer, 239 const content::Referrer& referrer,
221 const gfx::Size& size); 240 const gfx::Size& size);
222 241
223 // Returns true if |url| corresponds to a pending prerender. 242 // Returns true if |url| corresponds to a pending prerender.
224 bool IsPendingEntry(const GURL& url) const; 243 bool IsPendingEntry(const PrerenderHandle* prerender_handle) const;
dominich 2012/06/22 15:36:16 if |prerender_handle| can never be NULL, prefer pa
225 244
226 // Reissues any pending prerender requests from the prerendered page. Also 245 // Reissues any pending prerender requests from the prerendered page. Also
227 // clears the list of pending requests. 246 // clears the list of pending requests.
228 void StartPendingPrerenders(); 247 void StartPendingPrerenders();
229 248
230 protected: 249 protected:
231 PrerenderContents(PrerenderManager* prerender_manager, 250 PrerenderContents(PrerenderManager* prerender_manager,
232 PrerenderTracker* prerender_tracker, 251 PrerenderTracker* prerender_tracker,
233 Profile* profile, 252 Profile* profile,
234 const GURL& url, 253 const GURL& url,
(...skipping 16 matching lines...) Expand all
251 270
252 bool prerendering_has_been_cancelled() const { 271 bool prerendering_has_been_cancelled() const {
253 return prerendering_has_been_cancelled_; 272 return prerendering_has_been_cancelled_;
254 } 273 }
255 274
256 virtual content::WebContents* CreateWebContents( 275 virtual content::WebContents* CreateWebContents(
257 content::SessionStorageNamespace* session_storage_namespace); 276 content::SessionStorageNamespace* session_storage_namespace);
258 277
259 bool prerendering_has_started_; 278 bool prerendering_has_started_;
260 279
280 // Time at which we started to load the URL. This is used to compute
281 // the time elapsed from initiating a prerender until the time the
282 // (potentially only partially) prerendered page is shown to the user.
dominich 2012/06/22 15:36:16 Is it not used to potentially expire stale prerend
283 base::TimeTicks load_start_time_;
dominich 2012/06/22 15:36:16 The move to protected is unexpected as I thought P
284
261 private: 285 private:
262 class TabContentsDelegateImpl; 286 class TabContentsDelegateImpl;
263 287
264 // Needs to be able to call the constructor. 288 // Needs to be able to call the constructor.
265 friend class PrerenderContentsFactoryImpl; 289 friend class PrerenderContentsFactoryImpl;
266 290
267 friend class PrerenderRenderViewHostObserver; 291 friend class PrerenderRenderViewHostObserver;
268 292
269 // Message handlers. 293 // Message handlers.
270 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls); 294 void OnUpdateFaviconURL(int32 page_id, const std::vector<FaviconURL>& urls);
(...skipping 28 matching lines...) Expand all
299 int32 page_id_; 323 int32 page_id_;
300 GURL url_; 324 GURL url_;
301 GURL icon_url_; 325 GURL icon_url_;
302 content::NotificationRegistrar notification_registrar_; 326 content::NotificationRegistrar notification_registrar_;
303 327
304 // A vector of URLs that this prerendered page matches against. 328 // A vector of URLs that this prerendered page matches against.
305 // This array can contain more than element as a result of redirects, 329 // This array can contain more than element as a result of redirects,
306 // such as HTTP redirects or javascript redirects. 330 // such as HTTP redirects or javascript redirects.
307 std::vector<GURL> alias_urls_; 331 std::vector<GURL> alias_urls_;
308 332
333 // Number of distinct clients of this prerendered page (distinct link elements
334 // for instance).
dominich 2012/06/22 15:36:16 Ah - maybe instance_count_ ?
335 int client_count_;
336
309 bool has_stopped_loading_; 337 bool has_stopped_loading_;
310 338
311 // True when the main frame has finished loading. 339 // True when the main frame has finished loading.
312 bool has_finished_loading_; 340 bool has_finished_loading_;
313 341
314 // This must be the same value as the PrerenderTracker has recorded for 342 // This must be the same value as the PrerenderTracker has recorded for
315 // |this|, when |this| has a RenderView. 343 // |this|, when |this| has a RenderView.
316 FinalStatus final_status_; 344 FinalStatus final_status_;
317 345
318 // The MatchComplete status of the prerender, indicating how it relates 346 // The MatchComplete status of the prerender, indicating how it relates
319 // to being a MatchComplete dummy (see definition of MatchCompleteStatus 347 // to being a MatchComplete dummy (see definition of MatchCompleteStatus
320 // above). 348 // above).
321 MatchCompleteStatus match_complete_status_; 349 MatchCompleteStatus match_complete_status_;
322 350
323 // Tracks whether or not prerendering has been cancelled by calling Destroy. 351 // Tracks whether or not prerendering has been cancelled by calling Destroy.
324 // Used solely to prevent double deletion. 352 // Used solely to prevent double deletion.
325 bool prerendering_has_been_cancelled_; 353 bool prerendering_has_been_cancelled_;
326 354
327 // Time at which we started to load the URL. This is used to compute
328 // the time elapsed from initiating a prerender until the time the
329 // (potentially only partially) prerendered page is shown to the user.
330 base::TimeTicks load_start_time_;
331
332 // Process Metrics of the render process associated with the 355 // Process Metrics of the render process associated with the
333 // RenderViewHost for this object. 356 // RenderViewHost for this object.
334 scoped_ptr<base::ProcessMetrics> process_metrics_; 357 scoped_ptr<base::ProcessMetrics> process_metrics_;
335 358
336 // The prerendered TabContents; may be null. 359 // The prerendered TabContents; may be null.
337 scoped_ptr<TabContents> prerender_contents_; 360 scoped_ptr<TabContents> prerender_contents_;
338 361
339 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_; 362 scoped_ptr<PrerenderRenderViewHostObserver> render_view_host_observer_;
340 363
341 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_; 364 scoped_ptr<TabContentsDelegateImpl> tab_contents_delegate_;
(...skipping 16 matching lines...) Expand all
358 381
359 // The size of the WebView from the launching page. 382 // The size of the WebView from the launching page.
360 gfx::Size size_; 383 gfx::Size size_;
361 384
362 DISALLOW_COPY_AND_ASSIGN(PrerenderContents); 385 DISALLOW_COPY_AND_ASSIGN(PrerenderContents);
363 }; 386 };
364 387
365 } // namespace prerender 388 } // namespace prerender
366 389
367 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_ 390 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_CONTENTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698