Chromium Code Reviews| Index: chrome/browser/prerender/prerender_contents.cc |
| diff --git a/chrome/browser/prerender/prerender_contents.cc b/chrome/browser/prerender/prerender_contents.cc |
| index fa9e06de5fd8aa7711b995af32ba7eeda49a64ad..f8c9971ba6cfdb06099955159928845cd2dd7196 100644 |
| --- a/chrome/browser/prerender/prerender_contents.cc |
| +++ b/chrome/browser/prerender/prerender_contents.cc |
| @@ -7,11 +7,13 @@ |
| #include <algorithm> |
| #include <utility> |
| +#include "base/memory/linked_ptr.h" |
| #include "base/process_util.h" |
| #include "base/utf_string_conversions.h" |
| #include "chrome/browser/history/history_tab_helper.h" |
| #include "chrome/browser/history/history_types.h" |
| #include "chrome/browser/prerender/prerender_final_status.h" |
| +#include "chrome/browser/prerender/prerender_handle.h" |
| #include "chrome/browser/prerender/prerender_manager.h" |
| #include "chrome/browser/prerender/prerender_render_view_host_observer.h" |
| #include "chrome/browser/prerender/prerender_tracker.h" |
| @@ -37,29 +39,13 @@ using content::DownloadItem; |
| using content::OpenURLParams; |
| using content::RenderViewHost; |
| using content::ResourceRedirectDetails; |
| +using content::SessionStorageNamespace; |
| using content::WebContents; |
| namespace prerender { |
| namespace { |
| -// Compares URLs ignoring any ref for the purposes of matching URLs when |
| -// prerendering. |
| -struct PrerenderURLPredicate { |
| - explicit PrerenderURLPredicate(const GURL& url) |
| - : url_(url) { |
| - } |
| - |
| - bool operator()(const GURL& url) const { |
| - return url.scheme() == url_.scheme() && |
| - url.host() == url_.host() && |
| - url.port() == url_.port() && |
| - url.path() == url_.path() && |
| - url.query() == url_.query(); |
| - } |
| - GURL url_; |
| -}; |
| - |
| // Tells the render process at |child_id| whether |url| is a new prerendered |
| // page, or whether |url| is being removed as a prerendered page. Currently |
| // this will only inform the render process that created the prerendered page |
| @@ -96,20 +82,33 @@ class PrerenderContentsFactoryImpl : public PrerenderContents::Factory { |
| } |
| }; |
| +bool PrerenderContents::LessThanByLoadStartTime::operator ()( |
| + const PrerenderContents* lhs, |
| + const PrerenderContents* rhs) const { |
| + DCHECK(!lhs->load_start_time().is_null()); |
| + DCHECK(!rhs->load_start_time().is_null()); |
| + return lhs->load_start_time() < rhs->load_start_time(); |
| +} |
| + |
| struct PrerenderContents::PendingPrerenderInfo { |
| - PendingPrerenderInfo(const GURL& url, |
| + PendingPrerenderInfo(linked_ptr<PrerenderHandle> prerender_handle, |
|
mmenke
2012/06/22 16:12:45
I assume this is to allow copying. linked_ptr is
|
| + const GURL& url, |
| const content::Referrer& referrer, |
| const gfx::Size& size); |
| + |
| + linked_ptr<PrerenderHandle> prerender_handle; |
|
dominich
2012/06/22 15:36:16
You don't see those very often. I would have expec
|
| const GURL url; |
| const content::Referrer referrer; |
| const gfx::Size size; |
| }; |
| PrerenderContents::PendingPrerenderInfo::PendingPrerenderInfo( |
| + linked_ptr<PrerenderHandle> prerender_handle, |
| const GURL& url, |
| const content::Referrer& referrer, |
| const gfx::Size& size) |
| - : url(url), |
| + : prerender_handle(prerender_handle), |
| + url(url), |
| referrer(referrer), |
| size(size) { |
| } |
| @@ -206,18 +205,24 @@ class PrerenderContents::TabContentsDelegateImpl |
| PrerenderContents* prerender_contents_; |
| }; |
| -void PrerenderContents::AddPendingPrerender(const GURL& url, |
| - const content::Referrer& referrer, |
| - const gfx::Size& size) { |
| - pending_prerender_list_.push_back(PendingPrerenderInfo(url, referrer, size)); |
| +void PrerenderContents::AddPendingPrerender( |
| + scoped_ptr<PrerenderHandle> prerender_handle, |
| + const GURL& url, |
| + const content::Referrer& referrer, |
| + const gfx::Size& size) { |
| + pending_prerender_list_.push_back( |
| + PendingPrerenderInfo( |
| + make_linked_ptr(prerender_handle.release()), |
|
dominich
2012/06/22 15:36:16
what is this voodoo?
So you have a prerender hand
|
| + url, referrer, size)); |
| } |
| -bool PrerenderContents::IsPendingEntry(const GURL& url) const { |
| +bool PrerenderContents::IsPendingEntry( |
| + const PrerenderHandle* prerender_handle) const { |
| for (PendingPrerenderList::const_iterator it = |
|
dominich
2012/06/22 15:36:16
what no std::count_if?
|
| pending_prerender_list_.begin(); |
| it != pending_prerender_list_.end(); |
| ++it) { |
| - if (it->url == url) |
| + if (it->prerender_handle == prerender_handle) |
| return true; |
| } |
| return false; |
| @@ -249,6 +254,7 @@ PrerenderContents::PrerenderContents( |
| referrer_(referrer), |
| profile_(profile), |
| page_id_(0), |
| + client_count_(1), |
| has_stopped_loading_(false), |
| has_finished_loading_(false), |
| final_status_(FINAL_STATUS_MAX), |
| @@ -262,6 +268,15 @@ PrerenderContents::PrerenderContents( |
| DCHECK(prerender_manager != NULL); |
| } |
| +PrerenderContents* PrerenderContents::CreateDummyReplacement() const { |
| + PrerenderContents* dummy = |
| + new PrerenderContents(prerender_manager_, prerender_tracker_, profile_, |
| + prerender_url_, referrer_, origin_, experiment_id_); |
| + dummy->load_start_time_ = load_start_time_; |
| + dummy->client_count_ = client_count_; |
|
dominich
2012/06/22 15:36:16
do we not need to copy the child_id, route_id, fin
|
| + return dummy; |
| +} |
| + |
| bool PrerenderContents::Init() { |
| return AddAliasURL(prerender_url_); |
| } |
| @@ -274,7 +289,7 @@ PrerenderContents::Factory* PrerenderContents::CreateFactory() { |
| void PrerenderContents::StartPrerendering( |
| int creator_child_id, |
| const gfx::Size& size, |
| - content::SessionStorageNamespace* session_storage_namespace, |
| + SessionStorageNamespace* session_storage_namespace, |
| bool is_control_group) { |
| DCHECK(profile_ != NULL); |
| DCHECK(!prerendering_has_started_); |
| @@ -502,7 +517,7 @@ void PrerenderContents::OnRenderViewHostCreated( |
| } |
| WebContents* PrerenderContents::CreateWebContents( |
| - content::SessionStorageNamespace* session_storage_namespace) { |
| + SessionStorageNamespace* session_storage_namespace) { |
| return WebContents::Create(profile_, NULL, MSG_ROUTING_NONE, NULL, |
| session_storage_namespace); |
| } |
| @@ -554,17 +569,29 @@ void PrerenderContents::AddAliasURLsFromOtherPrerenderContents( |
| } |
| } |
| -bool PrerenderContents::MatchesURL(const GURL& url, GURL* matching_url) const { |
| - std::vector<GURL>::const_iterator matching_url_iterator = |
| - std::find_if(alias_urls_.begin(), |
| - alias_urls_.end(), |
| - PrerenderURLPredicate(url)); |
| - if (matching_url_iterator != alias_urls_.end()) { |
| - if (matching_url) |
| - *matching_url = *matching_url_iterator; |
| - return true; |
| - } |
| - return false; |
| +void PrerenderContents::IncrementClientCount() { |
| + DCHECK_GT(0, client_count_); |
| + ++client_count_; |
| +} |
| + |
| +void PrerenderContents::DecrementClientCount() { |
|
dominich
2012/06/22 15:36:16
DCHECK_GT(0, client_count_);
|
| + if (--client_count_ == 0) |
| + Destroy(FINAL_STATUS_CANCELLED); |
| +} |
| + |
| +bool PrerenderContents::Matches( |
| + const GURL& url, |
| + const SessionStorageNamespace* session_storage_namespace) { |
| + SessionStorageNamespace* my_session_storage_namespace = |
| + child_id_ == -1 ? NULL |
| + : GetRenderViewHostMutable()->GetSessionStorageNamespace(); |
| + |
| + if (session_storage_namespace != my_session_storage_namespace) |
| + return false; |
| + |
| + return implicit_cast<bool>( |
| + std::count_if(alias_urls_.begin(), alias_urls_.end(), |
| + std::bind2nd(std::equal_to<GURL>(), url))); |
|
dominich
2012/06/22 15:36:16
This will break fragment mismatches. There's a ver
|
| } |
| void PrerenderContents::OnJSOutOfMemory() { |