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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 prerendering_has_been_cancelled_(false), | 196 prerendering_has_been_cancelled_(false), |
197 child_id_(-1), | 197 child_id_(-1), |
198 route_id_(-1), | 198 route_id_(-1), |
199 starting_page_id_(-1), | 199 starting_page_id_(-1), |
200 origin_(origin), | 200 origin_(origin), |
201 experiment_id_(experiment_id) { | 201 experiment_id_(experiment_id) { |
202 DCHECK(prerender_manager != NULL); | 202 DCHECK(prerender_manager != NULL); |
203 } | 203 } |
204 | 204 |
205 bool PrerenderContents::Init() { | 205 bool PrerenderContents::Init() { |
206 return AddAliasURL(prerender_url_); | 206 return AddAliasURL(prerender_url_, false/*destroy_on_failure*/); |
207 } | 207 } |
208 | 208 |
209 // static | 209 // static |
210 PrerenderContents::Factory* PrerenderContents::CreateFactory() { | 210 PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
211 return new PrerenderContentsFactoryImpl(); | 211 return new PrerenderContentsFactoryImpl(); |
212 } | 212 } |
213 | 213 |
214 void PrerenderContents::StartPrerendering( | 214 void PrerenderContents::StartPrerendering( |
215 const RenderViewHost* source_render_view_host, | 215 const RenderViewHost* source_render_view_host, |
216 SessionStorageNamespace* session_storage_namespace) { | 216 SessionStorageNamespace* session_storage_namespace) { |
(...skipping 125 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 21 matching lines...) Expand all Loading... | |
402 // to be remembered for future matching, and if it redirects to | 407 // to be remembered for future matching, and if it redirects to |
403 // an https resource, it needs to be canceled. If a subresource | 408 // an https resource, it needs to be canceled. If a subresource |
404 // is redirected, nothing changes. | 409 // is redirected, nothing changes. |
405 DCHECK(content::Source<RenderViewHostDelegate>(source).ptr() == | 410 DCHECK(content::Source<RenderViewHostDelegate>(source).ptr() == |
406 GetRenderViewHostDelegate()); | 411 GetRenderViewHostDelegate()); |
407 ResourceRedirectDetails* resource_redirect_details = | 412 ResourceRedirectDetails* resource_redirect_details = |
408 content::Details<ResourceRedirectDetails>(details).ptr(); | 413 content::Details<ResourceRedirectDetails>(details).ptr(); |
409 CHECK(resource_redirect_details); | 414 CHECK(resource_redirect_details); |
410 if (resource_redirect_details->resource_type() == | 415 if (resource_redirect_details->resource_type() == |
411 ResourceType::MAIN_FRAME) { | 416 ResourceType::MAIN_FRAME) { |
412 if (!AddAliasURL(resource_redirect_details->new_url())) | 417 if (!AddAliasURL(resource_redirect_details->new_url(), |
418 true/*destroy_on_failure*/)) | |
413 return; | 419 return; |
414 } | 420 } |
415 break; | 421 break; |
416 } | 422 } |
417 | 423 |
418 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { | 424 case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
419 if (prerender_contents_.get()) { | 425 if (prerender_contents_.get()) { |
420 DCHECK_EQ(content::Source<TabContents>(source).ptr(), | 426 DCHECK_EQ(content::Source<TabContents>(source).ptr(), |
421 prerender_contents_->tab_contents()); | 427 prerender_contents_->tab_contents()); |
422 | 428 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 for (std::vector<FaviconURL>::const_iterator it = urls.begin(); | 479 for (std::vector<FaviconURL>::const_iterator it = urls.begin(); |
474 it != urls.end(); ++it) { | 480 it != urls.end(); ++it) { |
475 if (it->icon_type == FaviconURL::FAVICON) { | 481 if (it->icon_type == FaviconURL::FAVICON) { |
476 icon_url_ = it->icon_url; | 482 icon_url_ = it->icon_url; |
477 VLOG(1) << icon_url_; | 483 VLOG(1) << icon_url_; |
478 return; | 484 return; |
479 } | 485 } |
480 } | 486 } |
481 } | 487 } |
482 | 488 |
483 bool PrerenderContents::AddAliasURL(const GURL& url) { | 489 bool PrerenderContents::AddAliasURL(const GURL& url, bool destroy_on_failure) { |
dominich
2011/11/11 20:02:09
How does the caller know what final status to give
| |
484 const bool http = url.SchemeIs(chrome::kHttpScheme); | 490 const bool http = url.SchemeIs(chrome::kHttpScheme); |
485 const bool https = url.SchemeIs(chrome::kHttpsScheme); | 491 const bool https = url.SchemeIs(chrome::kHttpsScheme); |
486 if (!(http || https)) { | 492 if (!(http || https)) { |
487 Destroy(FINAL_STATUS_UNSUPPORTED_SCHEME); | 493 if (destroy_on_failure) |
494 Destroy(FINAL_STATUS_UNSUPPORTED_SCHEME); | |
488 return false; | 495 return false; |
489 } | 496 } |
490 if (https && !prerender_manager_->config().https_allowed) { | 497 if (https && !prerender_manager_->config().https_allowed) { |
491 Destroy(FINAL_STATUS_HTTPS); | 498 if (destroy_on_failure) |
499 Destroy(FINAL_STATUS_HTTPS); | |
492 return false; | 500 return false; |
493 } | 501 } |
494 if (prerender_manager_->HasRecentlyBeenNavigatedTo(url)) { | 502 if (prerender_manager_->HasRecentlyBeenNavigatedTo(url)) { |
495 Destroy(FINAL_STATUS_RECENTLY_VISITED); | 503 if (destroy_on_failure) |
504 Destroy(FINAL_STATUS_RECENTLY_VISITED); | |
496 return false; | 505 return false; |
497 } | 506 } |
498 | 507 |
499 alias_urls_.push_back(url); | 508 alias_urls_.push_back(url); |
500 prerender_tracker_->AddPrerenderURLOnUIThread(url); | 509 prerender_tracker_->AddPrerenderURLOnUIThread(url); |
501 return true; | 510 return true; |
502 } | 511 } |
503 | 512 |
504 bool PrerenderContents::MatchesURL(const GURL& url, GURL* matching_url) const { | 513 bool PrerenderContents::MatchesURL(const GURL& url, GURL* matching_url) const { |
505 std::vector<GURL>::const_iterator matching_url_iterator = | 514 std::vector<GURL>::const_iterator matching_url_iterator = |
(...skipping 20 matching lines...) Expand all Loading... | |
526 has_stopped_loading_ = true; | 535 has_stopped_loading_ = true; |
527 } | 536 } |
528 | 537 |
529 void PrerenderContents::DidStartProvisionalLoadForFrame( | 538 void PrerenderContents::DidStartProvisionalLoadForFrame( |
530 int64 frame_id, | 539 int64 frame_id, |
531 bool is_main_frame, | 540 bool is_main_frame, |
532 const GURL& validated_url, | 541 const GURL& validated_url, |
533 bool is_error_page, | 542 bool is_error_page, |
534 RenderViewHost* render_view_host) { | 543 RenderViewHost* render_view_host) { |
535 if (is_main_frame) { | 544 if (is_main_frame) { |
536 if (!AddAliasURL(validated_url)) | 545 if (!AddAliasURL(validated_url, true/*destroy_on_failure*/)) |
537 return; | 546 return; |
538 | 547 |
539 // Usually, this event fires if the user clicks or enters a new URL. | 548 // Usually, this event fires if the user clicks or enters a new URL. |
540 // Neither of these can happen in the case of an invisible prerender. | 549 // Neither of these can happen in the case of an invisible prerender. |
541 // So the cause is: Some JavaScript caused a new URL to be loaded. In that | 550 // So the cause is: Some JavaScript caused a new URL to be loaded. In that |
542 // case, the spinner would start again in the browser, so we must reset | 551 // case, the spinner would start again in the browser, so we must reset |
543 // has_stopped_loading_ so that the spinner won't be stopped. | 552 // has_stopped_loading_ so that the spinner won't be stopped. |
544 has_stopped_loading_ = false; | 553 has_stopped_loading_ = false; |
545 } | 554 } |
546 } | 555 } |
(...skipping 25 matching lines...) Expand all Loading... | |
572 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_, | 581 if (!prerender_tracker_->GetFinalStatus(child_id_, route_id_, |
573 &final_status)) { | 582 &final_status)) { |
574 NOTREACHED(); | 583 NOTREACHED(); |
575 } | 584 } |
576 } | 585 } |
577 set_final_status(final_status); | 586 set_final_status(final_status); |
578 | 587 |
579 prerendering_has_been_cancelled_ = true; | 588 prerendering_has_been_cancelled_ = true; |
580 // This has to be done after setting the final status, as it adds the | 589 // This has to be done after setting the final status, as it adds the |
581 // prerender to the history. | 590 // prerender to the history. |
582 prerender_manager_->MoveEntryToPendingDelete(this); | 591 prerender_manager_->MoveEntryToPendingDelete(this, final_status); |
583 | 592 |
584 // We may destroy the PrerenderContents before we have initialized the | 593 // We may destroy the PrerenderContents before we have initialized the |
585 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to | 594 // RenderViewHost. Otherwise set the Observer's PrerenderContents to NULL to |
586 // avoid any more messages being sent. | 595 // avoid any more messages being sent. |
587 if (render_view_host_observer_.get()) | 596 if (render_view_host_observer_.get()) |
588 render_view_host_observer_->set_prerender_contents(NULL); | 597 render_view_host_observer_->set_prerender_contents(NULL); |
589 } | 598 } |
590 | 599 |
591 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { | 600 base::ProcessMetrics* PrerenderContents::MaybeGetProcessMetrics() { |
592 if (process_metrics_.get() == NULL) { | 601 if (process_metrics_.get() == NULL) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
662 bool PrerenderContents::IsCrossSiteNavigationPending() const { | 671 bool PrerenderContents::IsCrossSiteNavigationPending() const { |
663 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) | 672 if (!prerender_contents_.get() || !prerender_contents_->tab_contents()) |
664 return false; | 673 return false; |
665 const TabContents* tab_contents = prerender_contents_->tab_contents(); | 674 const TabContents* tab_contents = prerender_contents_->tab_contents(); |
666 return (tab_contents->GetSiteInstance() != | 675 return (tab_contents->GetSiteInstance() != |
667 tab_contents->GetPendingSiteInstance()); | 676 tab_contents->GetPendingSiteInstance()); |
668 } | 677 } |
669 | 678 |
670 | 679 |
671 } // namespace prerender | 680 } // namespace prerender |
OLD | NEW |