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

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: further remediation 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);
172 177
173 static PrerenderManagerMode GetMode(); 178 static PrerenderManagerMode GetMode();
174 static void SetMode(PrerenderManagerMode mode); 179 static void SetMode(PrerenderManagerMode mode);
175 static const char* GetModeString(); 180 static const char* GetModeString();
176 static bool IsPrerenderingPossible(); 181 static bool IsPrerenderingPossible();
177 static bool ActuallyPrerendering(); 182 static bool ActuallyPrerendering();
178 static bool IsControlGroup(); 183 static bool IsControlGroup();
179 static bool IsNoUseGroup(); 184 static bool IsNoUseGroup();
180 185
181 // Query the list of current prerender pages to see if the given web contents 186 // Query the list of current prerender pages to see if the given web contents
182 // is prerendering a page. 187 // is prerendering a page. The optional parameter |origin| is an output
183 bool IsWebContentsPrerendering(content::WebContents* web_contents) const; 188 // parameter which, if a prerender is found, is set to the Origin of the
189 // prerender |web_contents|.
190 bool IsWebContentsPrerendering(content::WebContents* web_contents,
191 Origin* origin) const;
184 192
185 // Returns the PrerenderContents object for the given web_contents if it's 193 // Returns the PrerenderContents object for the given web_contents if it's
186 // used for an active prerender page, otherwise returns NULL. 194 // used for an active prerender page, otherwise returns NULL.
187 PrerenderContents* GetPrerenderContents( 195 PrerenderContents* GetPrerenderContents(
188 content::WebContents* web_contents) const; 196 content::WebContents* web_contents) const;
189 197
190 // Maintaining and querying the set of WebContents belonging to this 198 // Maintaining and querying the set of WebContents belonging to this
191 // PrerenderManager that are currently showing prerendered pages. 199 // PrerenderManager that are currently showing prerendered pages.
192 void MarkWebContentsAsPrerendered(content::WebContents* web_contents); 200 void MarkWebContentsAsPrerendered(content::WebContents* web_contents,
193 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents); 201 Origin origin);
202 void MarkWebContentsAsWouldBePrerendered(content::WebContents* web_contents,
203 Origin origin);
194 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents); 204 void MarkWebContentsAsNotPrerendered(content::WebContents* web_contents);
195 bool IsWebContentsPrerendered(content::WebContents* web_contents) const; 205
196 bool WouldWebContentsBePrerendered(content::WebContents* web_contents) const; 206 // Returns true if |web_contents| was originally a prerender that has since
207 // been swapped in. The optional parameter |origin| is an output parameter
208 // which, if a prerender is found, is set to the Origin of the prerender of
209 // |web_contents|.
210 bool IsWebContentsPrerendered(content::WebContents* web_contents,
211 Origin* origin) const;
212 bool WouldWebContentsBePrerendered(content::WebContents* web_contents,
213 Origin* origin) const;
197 214
198 // Checks whether |url| has been recently navigated to. 215 // Checks whether |url| has been recently navigated to.
199 bool HasRecentlyBeenNavigatedTo(const GURL& url); 216 bool HasRecentlyBeenNavigatedTo(Origin origin, const GURL& url);
200 217
201 // Returns true if the method given is invalid for prerendering. 218 // Returns true if the method given is invalid for prerendering.
202 static bool IsValidHttpMethod(const std::string& method); 219 static bool IsValidHttpMethod(const std::string& method);
203 220
204 // Returns a Value object containing the active pages being prerendered, and 221 // Returns a Value object containing the active pages being prerendered, and
205 // a history of pages which were prerendered. The caller is responsible for 222 // a history of pages which were prerendered. The caller is responsible for
206 // deleting the return value. 223 // deleting the return value.
207 base::DictionaryValue* GetAsValue() const; 224 base::DictionaryValue* GetAsValue() const;
208 225
209 // Clears the data indicated by which bits of clear_flags are set. 226 // Clears the data indicated by which bits of clear_flags are set.
(...skipping 25 matching lines...) Expand all
235 252
236 // Adds a condition. This is owned by the PrerenderManager. 253 // Adds a condition. This is owned by the PrerenderManager.
237 void AddCondition(const PrerenderCondition* condition); 254 void AddCondition(const PrerenderCondition* condition);
238 255
239 // Records that some visible tab navigated (or was redirected) to the 256 // Records that some visible tab navigated (or was redirected) to the
240 // provided URL. 257 // provided URL.
241 void RecordNavigation(const GURL& url); 258 void RecordNavigation(const GURL& url);
242 259
243 Profile* profile() const { return profile_; } 260 Profile* profile() const { return profile_; }
244 261
245 PrerenderHistograms* histograms() const { return histograms_.get(); }
246
247 protected: 262 protected:
248 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> { 263 class PrerenderData : public base::SupportsWeakPtr<PrerenderData> {
249 public: 264 public:
250 // Constructor for a pending prerender, which will get its contents later. 265 // Constructor for a pending prerender, which will get its contents later.
251 explicit PrerenderData(PrerenderManager* manager); 266 explicit PrerenderData(PrerenderManager* manager);
252 267
253 // Constructor for an active prerender. 268 // Constructor for an active prerender.
254 PrerenderData(PrerenderManager* manager, 269 PrerenderData(PrerenderManager* manager,
255 PrerenderContents* contents, 270 PrerenderContents* contents,
256 base::TimeTicks expiry_time); 271 base::TimeTicks expiry_time);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 343
329 private: 344 private:
330 friend class PrerenderBrowserTest; 345 friend class PrerenderBrowserTest;
331 friend class PrerenderContents; 346 friend class PrerenderContents;
332 friend class PrerenderHandle; 347 friend class PrerenderHandle;
333 friend class UnitTestPrerenderManager; 348 friend class UnitTestPrerenderManager;
334 349
335 class OnCloseTabContentsDeleter; 350 class OnCloseTabContentsDeleter;
336 struct NavigationRecord; 351 struct NavigationRecord;
337 352
338 typedef base::hash_map<content::WebContents*, bool> WouldBePrerenderedMap; 353 // For each WebContents that is swapped in, we store a
354 // PrerenderedWebContentsData so that we can track the origin of the
355 // prerender.
356 struct PrerenderedWebContentsData {
357 explicit PrerenderedWebContentsData(Origin origin);
358
359 Origin origin;
360 };
361
362 // In the control group experimental group for each WebContents "not swapped
363 // in" we create a WouldBePrerenderedWebContentsData to the origin of the
364 // "prerender" we did not launch. We also track a state machine to ensure
365 // the histogram reporting tracks what histograms would have done.
366 struct WouldBePrerenderedWebContentsData {
367 // When the WebContents gets a provisional load, we'd like to remove the
368 // WebContents from the map since the new navigation would not have swapped
369 // in a prerender. But the first provisional load after the control
370 // prerender is not "swapped in" is actually to the prerendered location! So
371 // we don't remove the item from the map on the first provisional load, but
372 // we do for subsequent loads.
373 enum State {
374 WAITING_FOR_PROVISIONAL_LOAD,
375 SEEN_PROVISIONAL_LOAD,
376 };
377
378 static const State INITIAL_STATE = WAITING_FOR_PROVISIONAL_LOAD;
379
380 explicit WouldBePrerenderedWebContentsData(Origin origin);
381
382 Origin origin;
383 State state;
384 };
339 385
340 // Time interval before a new prerender is allowed. 386 // Time interval before a new prerender is allowed.
341 static const int kMinTimeBetweenPrerendersMs = 500; 387 static const int kMinTimeBetweenPrerendersMs = 500;
342 388
343 // Time window for which we record old navigations, in milliseconds. 389 // Time window for which we record old navigations, in milliseconds.
344 static const int kNavigationRecordWindowMs = 5000; 390 static const int kNavigationRecordWindowMs = 5000;
345 391
346 void OnCancelPrerenderHandle(PrerenderData* prerender_data); 392 void OnCancelPrerenderHandle(PrerenderData* prerender_data);
347 393
348 // Adds a prerender for |url| from |referrer| initiated from the process 394 // Adds a prerender for |url| from |referrer| initiated from the process
(...skipping 55 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 450 // If |child_id| and |route_id| correspond to a RenderView that is an active
405 // prerender, returns the PrerenderData object for that prerender. Otherwise, 451 // prerender, returns the PrerenderData object for that prerender. Otherwise,
406 // returns NULL. 452 // returns NULL.
407 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id); 453 PrerenderData* FindPrerenderDataForChildAndRoute(int child_id, int route_id);
408 454
409 // Given the |prerender_contents|, find the iterator in active_prerender_list_ 455 // Given the |prerender_contents|, find the iterator in active_prerender_list_
410 // correponding to the given prerender. 456 // correponding to the given prerender.
411 std::list<linked_ptr<PrerenderData> >::iterator 457 std::list<linked_ptr<PrerenderData> >::iterator
412 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents); 458 FindIteratorForPrerenderContents(PrerenderContents* prerender_contents);
413 459
414 bool DoesRateLimitAllowPrerender() const; 460 bool DoesRateLimitAllowPrerender(Origin origin) const;
415 461
416 // Deletes old WebContents that have been replaced by prerendered ones. This 462 // 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, 463 // is needed because they're replaced in a callback from the old WebContents,
418 // so cannot immediately be deleted. 464 // so cannot immediately be deleted.
419 void DeleteOldTabContents(); 465 void DeleteOldTabContents();
420 466
421 // Cleans up old NavigationRecord's. 467 // Cleans up old NavigationRecord's.
422 void CleanUpOldNavigations(); 468 void CleanUpOldNavigations();
423 469
424 // Arrange for the given tab contents to be deleted asap. If deleter is not 470 // 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. 523 // List of all pending prerenders.
478 std::list<linked_ptr<PrerenderData> > pending_prerender_list_; 524 std::list<linked_ptr<PrerenderData> > pending_prerender_list_;
479 525
480 // List of recent navigations in this profile, sorted by ascending 526 // List of recent navigations in this profile, sorted by ascending
481 // navigate_time_. 527 // navigate_time_.
482 std::list<NavigationRecord> navigations_; 528 std::list<NavigationRecord> navigations_;
483 529
484 // List of prerender elements to be deleted 530 // List of prerender elements to be deleted
485 std::list<PrerenderContents*> pending_delete_list_; 531 std::list<PrerenderContents*> pending_delete_list_;
486 532
487 // Set of WebContents which are currently displaying a prerendered page. 533 // This map is from all WebContents which are currently displaying a
488 base::hash_set<content::WebContents*> prerendered_tab_contents_set_; 534 // prerendered page which has already been swapped in to a
535 // PrerenderedWebContentsData for tracking full lifetime information
536 // on prerenders.
537 base::hash_map<content::WebContents*, PrerenderedWebContentsData>
538 prerendered_web_contents_data_;
489 539
490 // WebContents that would have been swapped out for a prerendered WebContents 540 // 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 541 // 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 542 // WebContents gets a provisional load, the WebContents is removed from
493 // the map since the new navigation would not have swapped in a prerender. 543 // the map since the new navigation would not have swapped in a prerender.
494 // However, one complication exists because the first provisional load after 544 // However, one complication exists because the first provisional load after
495 // the WebContents is marked as "Would Have Been Prerendered" is actually to 545 // 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 546 // the prerendered location. So, we need to keep a state around that does
497 // not clear the item from the map on the first provisional load, but does 547 // not clear the item from the map on the first provisional load, but does
498 // for subsequent loads. 548 // for subsequent loads.
499 WouldBePrerenderedMap would_be_prerendered_map_; 549 base::hash_map<content::WebContents*, WouldBePrerenderedWebContentsData>
550 would_be_prerendered_map_;
500 551
501 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_; 552 scoped_ptr<PrerenderContents::Factory> prerender_contents_factory_;
502 553
503 static PrerenderManagerMode mode_; 554 static PrerenderManagerMode mode_;
504 555
505 // A count of how many prerenders we do per session. Initialized to 0 then 556 // 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. 557 // incremented and emitted to a histogram on each successful prerender.
507 static int prerenders_per_session_count_; 558 static int prerenders_per_session_count_;
508 559
509 // RepeatingTimer to perform periodic cleanups of pending prerendered 560 // RepeatingTimer to perform periodic cleanups of pending prerendered
(...skipping 20 matching lines...) Expand all
530 581
531 DISALLOW_COPY_AND_ASSIGN(PrerenderManager); 582 DISALLOW_COPY_AND_ASSIGN(PrerenderManager);
532 }; 583 };
533 584
534 PrerenderManager* FindPrerenderManagerUsingRenderProcessId( 585 PrerenderManager* FindPrerenderManagerUsingRenderProcessId(
535 int render_process_id); 586 int render_process_id);
536 587
537 } // namespace prerender 588 } // namespace prerender
538 589
539 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_ 590 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698