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

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

Issue 11028037: Fix prerender histograms for multiple prerender case. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update the rite cl Created 8 years, 2 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_MANAGER_H_ 5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 6 #define CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // load may have started prior to navigation due to prerender hints. 152 // load may have started prior to navigation due to prerender hints.
153 // This must be called on the UI thread. 153 // This must be called on the UI thread.
154 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value 154 // |fraction_plt_elapsed_at_swap_in| must either be in [0.0, 1.0], or a value
155 // outside that range indicating that it doesn't apply. 155 // outside that range indicating that it doesn't apply.
156 static void RecordPerceivedPageLoadTime( 156 static void RecordPerceivedPageLoadTime(
157 base::TimeDelta perceived_page_load_time, 157 base::TimeDelta perceived_page_load_time,
158 double fraction_plt_elapsed_at_swap_in, 158 double fraction_plt_elapsed_at_swap_in,
159 content::WebContents* web_contents, 159 content::WebContents* web_contents,
160 const GURL& url); 160 const GURL& url);
161 161
162 // Records the percentage of pixels of the final page in place at swap-in.
163 void RecordFractionPixelsFinalAtSwapin(
164 content::WebContents* web_contents,
165 double fraction);
166
162 // Set whether prerendering is currently enabled for this manager. 167 // Set whether prerendering is currently enabled for this manager.
163 // Must be called on the UI thread. 168 // Must be called on the UI thread.
164 // If |enabled| is false, existing prerendered pages will still persist until 169 // If |enabled| is false, existing prerendered pages will still persist until
165 // they time out, but new ones will not be generated. 170 // they time out, but new ones will not be generated.
166 void set_enabled(bool enabled); 171 void set_enabled(bool enabled);
167 172
168 // Controls if we launch or squash prefetch requests as they arrive from 173 // Controls if we launch or squash prefetch requests as they arrive from
169 // renderers. 174 // renderers.
170 static bool IsPrefetchEnabled(); 175 static bool IsPrefetchEnabled();
171 static void SetIsPrefetchEnabled(bool enabled); 176 static void SetIsPrefetchEnabled(bool enabled);
(...skipping 10 matching lines...) Expand all
182 // is prerendering a page. 187 // is prerendering a page.
183 bool IsWebContentsPrerendering(content::WebContents* web_contents) const; 188 bool IsWebContentsPrerendering(content::WebContents* web_contents) const;
184 189
185 // Returns the PrerenderContents object for the given web_contents if it's 190 // Returns the PrerenderContents object for the given web_contents if it's
186 // used for an active prerender page, otherwise returns NULL. 191 // used for an active prerender page, otherwise returns NULL.
187 PrerenderContents* GetPrerenderContents( 192 PrerenderContents* GetPrerenderContents(
188 content::WebContents* web_contents) const; 193 content::WebContents* web_contents) const;
189 194
190 // Maintaining and querying the set of WebContents belonging to this 195 // Maintaining and querying the set of WebContents belonging to this
191 // PrerenderManager that are currently showing prerendered pages. 196 // PrerenderManager that are currently showing prerendered pages.
192 void MarkWebContentsAsPrerendered(content::WebContents* web_contents); 197 void MarkWebContentsAsPrerendered(content::WebContents* web_contents,
198 Origin origin);
199
193 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents); 200 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents);
194 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents); 201 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents);
195 bool IsWebContentsPrerendered(content::WebContents* web_contents) const; 202
203 // Returns true if |web_contents| is being prerendered. The optional parameter
mmenke 2012/10/08 18:20:07 Could you fix this comment as well? It's actually
gavinp 2012/10/10 18:14:56 Done.
204 // |origin| is an output parameter which, if a prerender is found, is set to
205 // the Origin of the prerender of |web_contents|.
206 bool IsWebContentsPrerendered(content::WebContents* web_contents,
207 Origin* origin) const;
208
196 bool WouldWebContentsBePrerendered(content::WebContents* web_contents) const; 209 bool WouldWebContentsBePrerendered(content::WebContents* web_contents) const;
197 210
198 // Checks whether |url| has been recently navigated to. 211 // Checks whether |url| has been recently navigated to.
199 bool HasRecentlyBeenNavigatedTo(const GURL& url); 212 bool HasRecentlyBeenNavigatedTo(Origin origin, const GURL& url);
200 213
201 // Returns true if the method given is invalid for prerendering. 214 // Returns true if the method given is invalid for prerendering.
202 static bool IsValidHttpMethod(const std::string& method); 215 static bool IsValidHttpMethod(const std::string& method);
203 216
204 // Returns a Value object containing the active pages being prerendered, and 217 // Returns a Value object containing the active pages being prerendered, and
205 // a history of pages which were prerendered. The caller is responsible for 218 // a history of pages which were prerendered. The caller is responsible for
206 // deleting the return value. 219 // deleting the return value.
207 base::DictionaryValue* GetAsValue() const; 220 base::DictionaryValue* GetAsValue() const;
208 221
209 // Clears the data indicated by which bits of clear_flags are set. 222 // Clears the data indicated by which bits of clear_flags are set.
(...skipping 25 matching lines...) Expand all
235 248
236 // Adds a condition. This is owned by the PrerenderManager. 249 // Adds a condition. This is owned by the PrerenderManager.
237 void AddCondition(const PrerenderCondition* condition); 250 void AddCondition(const PrerenderCondition* condition);
238 251
239 // Records that some visible tab navigated (or was redirected) to the 252 // Records that some visible tab navigated (or was redirected) to the
240 // provided URL. 253 // provided URL.
241 void RecordNavigation(const GURL& url); 254 void RecordNavigation(const GURL& url);
242 255
243 Profile* profile() const { return profile_; } 256 Profile* profile() const { return profile_; }
244 257
245 PrerenderHistograms* histograms() const { return histograms_.get(); } 258 PrerenderHistograms* histograms() { return histograms_.get(); }
246 259
247 protected: 260 protected:
248 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { 261 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> {
249 public: 262 public:
250 // Constructor for a pending prerender, which will get its contents later. 263 // Constructor for a pending prerender, which will get its contents later.
251 explicit PrerenderData(PrerenderManager* manager); 264 explicit PrerenderData(PrerenderManager* manager);
252 265
253 // Constructor for an active prerender. 266 // Constructor for an active prerender.
254 PrerenderData(PrerenderManager* manager, 267 PrerenderData(PrerenderManager* manager,
255 PrerenderContents* contents, 268 PrerenderContents* contents,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 void DoShutdown(); 340 void DoShutdown();
328 341
329 private: 342 private:
330 friend class PrerenderBrowserTest; 343 friend class PrerenderBrowserTest;
331 friend class PrerenderContents; 344 friend class PrerenderContents;
332 friend class PrerenderHandle; 345 friend class PrerenderHandle;
333 friend class UnitTestPrerenderManager; 346 friend class UnitTestPrerenderManager;
334 347
335 class OnCloseTabContentsDeleter; 348 class OnCloseTabContentsDeleter;
336 struct NavigationRecord; 349 struct NavigationRecord;
350 struct PrerenderedWebContentsData {
351 Origin origin;
352
353 explicit PrerenderedWebContentsData(Origin origin);
354 };
337 355
338 typedef base::hash_map<content::WebContents*, bool> WouldBePrerenderedMap; 356 typedef base::hash_map<content::WebContents*, bool> WouldBePrerenderedMap;
339 357
340 // Time interval before a new prerender is allowed. 358 // Time interval before a new prerender is allowed.
341 static const int kMinTimeBetweenPrerendersMs = 500; 359 static const int kMinTimeBetweenPrerendersMs = 500;
342 360
343 // Time window for which we record old navigations, in milliseconds. 361 // Time window for which we record old navigations, in milliseconds.
344 static const int kNavigationRecordWindowMs = 5000; 362 static const int kNavigationRecordWindowMs = 5000;
345 363
346 void OnCancelPrerenderHandle(PrerenderData* prerender_data); 364 void OnCancelPrerenderHandle(PrerenderData* prerender_data);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 // If |child_id| and |route_id| correspond to a RenderView that is an active 422 // If |child_id| and |route_id| correspond to a RenderView that is an active
405 // prerender, returns the PrerenderData object for that prerender. Otherwise, 423 // prerender, returns the PrerenderData object for that prerender. Otherwise,
406 // returns NULL. 424 // returns NULL.
407 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id); 425 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id);
408 426
409 // Given the |prerender_contents|, find the iterator in active_prerender_list_ 427 // Given the |prerender_contents|, find the iterator in active_prerender_list_
410 // correponding to the given prerender. 428 // correponding to the given prerender.
411 std::list<linked_ptr<PrerenderData> >::iterator 429 std::list<linked_ptr<PrerenderData> >::iterator
412 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents); 430 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents);
413 431
414 bool DoesRateLimitAllowPrerender() const; 432 bool DoesRateLimitAllowPrerender(Origin origin) const;
415 433
416 // Deletes old WebContents that have been replaced by prerendered ones. This 434 // Deletes old WebContents that have been replaced by prerendered ones. This
417 // is needed because they're replaced in a callback from the old WebContents, 435 // is needed because they're replaced in a callback from the old WebContents,
418 // so cannot immediately be deleted. 436 // so cannot immediately be deleted.
419 void DeleteOldTabContents(); 437 void DeleteOldTabContents();
420 438
421 // Cleans up old NavigationRecord's. 439 // Cleans up old NavigationRecord's.
422 void CleanUpOldNavigations(); 440 void CleanUpOldNavigations();
423 441
424 // Arrange for the given tab contents to be deleted asap. If deleter is not 442 // Arrange for the given tab contents to be deleted asap. If deleter is not
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 // List of all pending prerenders. 495 // List of all pending prerenders.
478 std::list<linked_ptr<PrerenderData> > pending_prerender_list_; 496 std::list<linked_ptr<PrerenderData> > pending_prerender_list_;
479 497
480 // List of recent navigations in this profile, sorted by ascending 498 // List of recent navigations in this profile, sorted by ascending
481 // navigate_time_. 499 // navigate_time_.
482 std::list<NavigationRecord> navigations_; 500 std::list<NavigationRecord> navigations_;
483 501
484 // List of prerender elements to be deleted 502 // List of prerender elements to be deleted
485 std::list<PrerenderContents*> pending_delete_list_; 503 std::list<PrerenderContents*> pending_delete_list_;
486 504
487 // Set of WebContents which are currently displaying a prerendered page. 505 // This map is from all WebContents which are currently displaying a
488 base::hash_set<content::WebContents*> prerendered_tab_contents_set_; 506 // prerendered page which has already been swapped in to a
507 // PrerenderedWebContentsData for tracking full lifetime information
508 // on prerenders.
509 base::hash_map<content::WebContents*, PrerenderedWebContentsData>
510 prerendered_web_contents_data_;
489 511
490 // WebContents that would have been swapped out for a prerendered WebContents 512 // WebContents that would have been swapped out for a prerendered WebContents
491 // if the user was not part of the control group for measurement. When the 513 // if the user was not part of the control group for measurement. When the
492 // WebContents gets a provisional load, the WebContents is removed from 514 // WebContents gets a provisional load, the WebContents is removed from
493 // the map since the new navigation would not have swapped in a prerender. 515 // the map since the new navigation would not have swapped in a prerender.
494 // However, one complication exists because the first provisional load after 516 // However, one complication exists because the first provisional load after
495 // the WebContents is marked as "Would Have Been Prerendered" is actually to 517 // the WebContents is marked as "Would Have Been Prerendered" is actually to
496 // the prerendered location. So, we need to keep a boolean around that does 518 // the prerendered location. So, we need to keep a boolean around that does
497 // not clear the item from the map on the first provisional load, but does 519 // not clear the item from the map on the first provisional load, but does
498 // for subsequent loads. 520 // for subsequent loads.
499 WouldBePrerenderedMap would_be_prerendered_map_; 521 WouldBePrerenderedMap would_be_prerendered_map_;
tburkard 2012/10/05 21:54:04 In order for this to work symmetrically for contro
gavinp 2012/10/10 18:14:56 Done, but I used an enum, since bools always confu
500 522
501 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; 523 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_;
502 524
503 static PrerenderManagerMode mode_; 525 static PrerenderManagerMode mode_;
504 526
505 // A count of how many prerenders we do per session. Initialized to 0 then 527 // A count of how many prerenders we do per session. Initialized to 0 then
506 // incremented and emitted to a histogram on each successful prerender. 528 // incremented and emitted to a histogram on each successful prerender.
507 static int prerenders_per_session_count_; 529 static int prerenders_per_session_count_;
508 530
509 // RepeatingTimer to perform periodic cleanups of pending prerendered 531 // RepeatingTimer to perform periodic cleanups of pending prerendered
(...skipping 20 matching lines...) Expand all
530 552
531 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 553 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
532 }; 554 };
533 555
534 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( 556 PrerenderManager* FindPrerenderManagerUsingRenderProcessId(
535 int render_process_id); 557 int render_process_id);
536 558
537 } // namespace prerender 559 } // namespace prerender
538 560
539 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 561 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698