OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/prerender/prerender_contents.h" | 5 #include "chrome/browser/prerender/prerender_contents.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 bool PrerenderContents::GetRouteId(int* route_id) const { | 342 bool PrerenderContents::GetRouteId(int* route_id) const { |
343 CHECK(route_id); | 343 CHECK(route_id); |
344 DCHECK_GE(route_id_, -1); | 344 DCHECK_GE(route_id_, -1); |
345 *route_id = route_id_; | 345 *route_id = route_id_; |
346 return route_id_ != -1; | 346 return route_id_ != -1; |
347 } | 347 } |
348 | 348 |
349 void PrerenderContents::set_final_status(FinalStatus final_status) { | 349 void PrerenderContents::set_final_status(FinalStatus final_status) { |
350 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); | 350 DCHECK(final_status >= FINAL_STATUS_USED && final_status < FINAL_STATUS_MAX); |
351 DCHECK(final_status_ == FINAL_STATUS_MAX || | 351 DCHECK(final_status_ == FINAL_STATUS_MAX || |
352 final_status_ == FINAL_STATUS_CONTROL_GROUP); | 352 final_status_ == FINAL_STATUS_CONTROL_GROUP || |
| 353 final_status_ == FINAL_STATUS_MATCH_COMPLETE_DUMMY); |
353 | 354 |
354 // Don't override final_status_ if it's FINAL_STATUS_CONTROL_GROUP, | 355 // Don't override final_status_ if it's FINAL_STATUS_CONTROL_GROUP or |
355 // otherwise data will be collected in the Prerender.FinalStatus histogram. | 356 // FINAL_STATUS_MATCH_COMPLETE_DUMMY, otherwise data will be collected |
356 if (final_status_ == FINAL_STATUS_CONTROL_GROUP) | 357 // in the Prerender.FinalStatus histogram. |
| 358 if (final_status_ == FINAL_STATUS_CONTROL_GROUP || |
| 359 final_status_ == FINAL_STATUS_MATCH_COMPLETE_DUMMY) |
357 return; | 360 return; |
358 | 361 |
359 final_status_ = final_status; | 362 final_status_ = final_status; |
360 } | 363 } |
361 | 364 |
362 PrerenderContents::~PrerenderContents() { | 365 PrerenderContents::~PrerenderContents() { |
363 DCHECK(final_status_ != FINAL_STATUS_MAX); | 366 DCHECK(final_status_ != FINAL_STATUS_MAX); |
364 DCHECK(prerendering_has_been_cancelled_ || | 367 DCHECK(prerendering_has_been_cancelled_ || |
365 final_status_ == FINAL_STATUS_USED || | 368 final_status_ == FINAL_STATUS_USED || |
366 final_status_ == FINAL_STATUS_CONTROL_GROUP); | 369 final_status_ == FINAL_STATUS_CONTROL_GROUP || |
| 370 final_status_ == FINAL_STATUS_MATCH_COMPLETE_DUMMY); |
367 DCHECK(origin_ != ORIGIN_MAX); | 371 DCHECK(origin_ != ORIGIN_MAX); |
368 | 372 |
369 // If we haven't even started prerendering, we were just in the control | 373 // If we haven't even started prerendering, we were just in the control |
370 // group, which means we do not want to record the status. | 374 // group (or a match complete dummy), which means we do not want to record |
| 375 // the status. |
371 if (prerendering_has_started()) | 376 if (prerendering_has_started()) |
372 prerender_manager_->RecordFinalStatus(origin_, experiment_id_, | 377 prerender_manager_->RecordFinalStatus(origin_, experiment_id_, |
373 final_status_); | 378 final_status_); |
374 | 379 |
375 if (child_id_ != -1 && route_id_ != -1) | 380 if (child_id_ != -1 && route_id_ != -1) |
376 prerender_tracker_->OnPrerenderingFinished(child_id_, route_id_); | 381 prerender_tracker_->OnPrerenderingFinished(child_id_, route_id_); |
377 | 382 |
378 // If we still have a TabContents, clean up anything we need to and then | 383 // If we still have a TabContents, clean up anything we need to and then |
379 // destroy it. | 384 // destroy it. |
380 if (prerender_contents_.get()) | 385 if (prerender_contents_.get()) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_, | 577 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_, |
573 &final_status)) { | 578 &final_status)) { |
574 NOTREACHED(); | 579 NOTREACHED(); |
575 } | 580 } |
576 } | 581 } |
577 set_final_status(final_status); | 582 set_final_status(final_status); |
578 | 583 |
579 prerendering_has_been_cancelled_ = true; | 584 prerendering_has_been_cancelled_ = true; |
580 // This has to be done after setting the final status, as it adds the | 585 // This has to be done after setting the final status, as it adds the |
581 // prerender to the history. | 586 // prerender to the history. |
582 prerender_manager_->MoveEntryToPendingDelete(this); | 587 prerender_manager_->MoveEntryToPendingDelete(this, final_status); |
583 | 588 |
584 // We may destroy the PrerenderContents before we have initialized the | 589 // We may destroy the PrerenderContents before we have initialized the |
585 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 590 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
586 // avoid any more messages being sent. | 591 // avoid any more messages being sent. |
587 if (render_view_host_observer_.get()) | 592 if (render_view_host_observer_.get()) |
588 render_view_host_observer_->set_prerender_contents(NULL); | 593 render_view_host_observer_->set_prerender_contents(NULL); |
589 } | 594 } |
590 | 595 |
591 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 596 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
592 if (process_metrics_.get() == NULL) { | 597 if (process_metrics_.get() == NULL) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 667 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
663 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) | 668 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) |
664 return false; | 669 return false; |
665 const TabContents* tab_contents = prerender_contents_->tab_contents(); | 670 const TabContents* tab_contents = prerender_contents_->tab_contents(); |
666 return (tab_contents->GetSiteInstance() != | 671 return (tab_contents->GetSiteInstance() != |
667 tab_contents->GetPendingSiteInstance()); | 672 tab_contents->GetPendingSiteInstance()); |
668 } | 673 } |
669 | 674 |
670 | 675 |
671 } // namespace prerender | 676 } // namespace prerender |
OLD | NEW |