OLD | NEW |
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 #include "chrome/browser/prerender/prerender_manager.h" | 5 #include "chrome/browser/prerender/prerender_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 return false; | 378 return false; |
379 } | 379 } |
380 | 380 |
381 // If the session storage namespaces don't match, cancel the prerender. | 381 // If the session storage namespaces don't match, cancel the prerender. |
382 RenderViewHost* old_render_view_host = web_contents->GetRenderViewHost(); | 382 RenderViewHost* old_render_view_host = web_contents->GetRenderViewHost(); |
383 RenderViewHost* new_render_view_host = | 383 RenderViewHost* new_render_view_host = |
384 prerender_contents->prerender_contents()->web_contents()-> | 384 prerender_contents->prerender_contents()->web_contents()-> |
385 GetRenderViewHost(); | 385 GetRenderViewHost(); |
386 DCHECK(old_render_view_host); | 386 DCHECK(old_render_view_host); |
387 DCHECK(new_render_view_host); | 387 DCHECK(new_render_view_host); |
388 if (old_render_view_host->session_storage_namespace() != | 388 if (old_render_view_host->GetSessionStorageNamespace() != |
389 new_render_view_host->session_storage_namespace()) { | 389 new_render_view_host->GetSessionStorageNamespace()) { |
390 DestroyAndMarkMatchCompleteAsUsed( | 390 DestroyAndMarkMatchCompleteAsUsed( |
391 prerender_contents.release(), | 391 prerender_contents.release(), |
392 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH); | 392 FINAL_STATUS_SESSION_STORAGE_NAMESPACE_MISMATCH); |
393 return false; | 393 return false; |
394 } | 394 } |
395 | 395 |
396 // If we don't want to use prerenders at all, we are done. | 396 // If we don't want to use prerenders at all, we are done. |
397 // For bookkeeping purposes, we need to mark this TabContents to | 397 // For bookkeeping purposes, we need to mark this TabContents to |
398 // reflect that it would have been prerendered. | 398 // reflect that it would have been prerendered. |
399 if (GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP) { | 399 if (GetMode() == PRERENDER_MODE_EXPERIMENT_NO_USE_GROUP) { |
(...skipping 16 matching lines...) Expand all Loading... |
416 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - | 416 histograms_->RecordTimeUntilUsed(GetCurrentTimeTicks() - |
417 prerender_contents->load_start_time(), | 417 prerender_contents->load_start_time(), |
418 GetMaxAge()); | 418 GetMaxAge()); |
419 } | 419 } |
420 | 420 |
421 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); | 421 histograms_->RecordPerSessionCount(++prerenders_per_session_count_); |
422 histograms_->RecordUsedPrerender(prerender_contents->origin()); | 422 histograms_->RecordUsedPrerender(prerender_contents->origin()); |
423 prerender_contents->set_final_status(FINAL_STATUS_USED); | 423 prerender_contents->set_final_status(FINAL_STATUS_USED); |
424 | 424 |
425 new_render_view_host->Send( | 425 new_render_view_host->Send( |
426 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->routing_id(), | 426 new ChromeViewMsg_SetIsPrerendering(new_render_view_host->GetRoutingID(), |
427 false)); | 427 false)); |
428 | 428 |
429 TabContentsWrapper* new_tab_contents = | 429 TabContentsWrapper* new_tab_contents = |
430 prerender_contents->ReleasePrerenderContents(); | 430 prerender_contents->ReleasePrerenderContents(); |
431 TabContentsWrapper* old_tab_contents = | 431 TabContentsWrapper* old_tab_contents = |
432 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 432 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
433 DCHECK(new_tab_contents); | 433 DCHECK(new_tab_contents); |
434 DCHECK(old_tab_contents); | 434 DCHECK(old_tab_contents); |
435 | 435 |
436 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); | 436 MarkWebContentsAsPrerendered(new_tab_contents->web_contents()); |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 return false; | 862 return false; |
863 } | 863 } |
864 | 864 |
865 RenderViewHost* source_render_view_host = NULL; | 865 RenderViewHost* source_render_view_host = NULL; |
866 if (child_route_id_pair.first != -1) { | 866 if (child_route_id_pair.first != -1) { |
867 source_render_view_host = | 867 source_render_view_host = |
868 RenderViewHost::FromID(child_route_id_pair.first, | 868 RenderViewHost::FromID(child_route_id_pair.first, |
869 child_route_id_pair.second); | 869 child_route_id_pair.second); |
870 // Don't prerender page if parent RenderViewHost no longer exists, or it has | 870 // Don't prerender page if parent RenderViewHost no longer exists, or it has |
871 // no view. The latter should only happen when the RenderView has closed. | 871 // no view. The latter should only happen when the RenderView has closed. |
872 if (!source_render_view_host || !source_render_view_host->view()) { | 872 if (!source_render_view_host || !source_render_view_host->GetView()) { |
873 RecordFinalStatus(origin, experiment, | 873 RecordFinalStatus(origin, experiment, |
874 FINAL_STATUS_SOURCE_RENDER_VIEW_CLOSED); | 874 FINAL_STATUS_SOURCE_RENDER_VIEW_CLOSED); |
875 return false; | 875 return false; |
876 } | 876 } |
877 } | 877 } |
878 | 878 |
879 if (!session_storage_namespace && source_render_view_host) { | 879 if (!session_storage_namespace && source_render_view_host) { |
880 session_storage_namespace = | 880 session_storage_namespace = |
881 source_render_view_host->session_storage_namespace(); | 881 source_render_view_host->GetSessionStorageNamespace(); |
882 } | 882 } |
883 | 883 |
884 PrerenderContents* prerender_contents = CreatePrerenderContents( | 884 PrerenderContents* prerender_contents = CreatePrerenderContents( |
885 url, referrer, origin, experiment); | 885 url, referrer, origin, experiment); |
886 if (!prerender_contents || !prerender_contents->Init()) | 886 if (!prerender_contents || !prerender_contents->Init()) |
887 return false; | 887 return false; |
888 | 888 |
889 histograms_->RecordPrerenderStarted(origin); | 889 histograms_->RecordPrerenderStarted(origin); |
890 | 890 |
891 // TODO(cbentzel): Move invalid checks here instead of PrerenderContents? | 891 // TODO(cbentzel): Move invalid checks here instead of PrerenderContents? |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1200 if (!render_process_host || !render_process_host->GetBrowserContext()) | 1200 if (!render_process_host || !render_process_host->GetBrowserContext()) |
1201 return NULL; | 1201 return NULL; |
1202 Profile* profile = Profile::FromBrowserContext( | 1202 Profile* profile = Profile::FromBrowserContext( |
1203 render_process_host->GetBrowserContext()); | 1203 render_process_host->GetBrowserContext()); |
1204 if (!profile) | 1204 if (!profile) |
1205 return NULL; | 1205 return NULL; |
1206 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); | 1206 return PrerenderManagerFactory::GetInstance()->GetForProfile(profile); |
1207 } | 1207 } |
1208 | 1208 |
1209 } // namespace prerender | 1209 } // namespace prerender |
OLD | NEW |