Chromium Code Reviews| Index: chrome/browser/prerender/prerender_manager.cc |
| diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc |
| index 2b80186a016af74f55beef070ac690160af1de9f..afa83025f4c1b9d3b6c13a887ddc9d60ca4440ec 100644 |
| --- a/chrome/browser/prerender/prerender_manager.cc |
| +++ b/chrome/browser/prerender/prerender_manager.cc |
| @@ -48,6 +48,12 @@ const int kPeriodicCleanupIntervalMs = 1000; |
| // Time interval before a new prerender is allowed. |
| const int kMinTimeBetweenPrerendersMs = 500; |
| +// Valid HTTP methods for prerendering. |
| +const char* kValidHttpMethods[] = { |
|
cbentzel
2011/04/30 01:03:34
I've usually seen as
const char* const
dominich
2011/05/02 16:45:55
Done.
|
| + "OPTIONS", "GET", "HEAD", "TRACE", "CONNECT", |
|
cbentzel
2011/04/30 01:03:34
I'd do one of these per-line, and not include the
dominich
2011/05/02 16:45:55
Done.
|
| + // "PUT", "POST", "DELETE" |
| +}; |
| + |
| } // namespace |
| // static |
| @@ -109,6 +115,16 @@ bool PrerenderManager::MaybeGetQueryStringBasedAliasURL( |
| return false; |
| } |
| +// static |
| +bool PrerenderManager::IsValidHttpMethod(const std::string& method) { |
| + for (size_t i = 0; i < arraysize(kValidHttpMethods); ++i) { |
| + if (method == kValidHttpMethods[i]) |
|
cbentzel
2011/04/30 01:03:34
I'm not sure if these are canonicalized to upper c
dominich
2011/05/02 16:45:55
Tested and they are. Added comment to confirm.
|
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| struct PrerenderManager::PrerenderContentsData { |
| PrerenderContents* contents_; |
| base::Time start_time_; |
| @@ -147,6 +163,18 @@ void HandlePrefetchTagOnUIThread( |
| prerender_manager->AddPreload(child_route_id_pair, url, referrer); |
| } |
| +void DestroyPreloadForChildRouteIdPairOnUIThread( |
| + const base::WeakPtr<PrerenderManager>& prerender_manager_weak_ptr, |
| + const std::pair<int, int>& child_route_id_pair, |
| + FinalStatus final_status) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + PrerenderManager* prerender_manager = prerender_manager_weak_ptr.get(); |
| + if (!prerender_manager) |
| + return; |
| + prerender_manager->DestroyPreloadForChildRouteIdPair(child_route_id_pair, |
| + final_status); |
| +} |
| + |
| PrerenderManager::PrerenderManager(Profile* profile) |
| : rate_limit_enabled_(true), |
| enabled_(true), |
| @@ -265,24 +293,9 @@ void PrerenderManager::AddPendingPreload( |
| const GURL& referrer) { |
| DCHECK(CalledOnValidThread()); |
| // Check if this is coming from a valid prerender RenderViewHost. |
| - bool is_valid_prerender = false; |
| - for (std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
| - it != prerender_list_.end(); ++it) { |
| - PrerenderContents* prerender_contents = it->contents_; |
| - |
| - int child_id; |
| - int route_id; |
| - bool has_child_id = prerender_contents->GetChildId(&child_id); |
| - bool has_route_id = has_child_id && |
| - prerender_contents->GetRouteId(&route_id); |
| - |
| - if (has_child_id && has_route_id && |
| - child_id == child_route_id_pair.first && |
| - route_id == child_route_id_pair.second) { |
| - is_valid_prerender = true; |
| - break; |
| - } |
| - } |
| + bool is_valid_prerender = |
| + (FindPrerenderContentsForChildRouteIdPair(child_route_id_pair) != |
| + prerender_list_.end()); |
| // If not, we could check to see if the RenderViewHost specified by the |
| // child_route_id_pair exists and if so just start prerendering, as this |
| @@ -306,6 +319,44 @@ void PrerenderManager::AddPendingPreload( |
| it->second.push_back(PendingContentsData(url, referrer)); |
| } |
| +std::list<PrerenderManager::PrerenderContentsData>::iterator |
| + PrerenderManager::FindPrerenderContentsForChildRouteIdPair( |
| + const std::pair<int, int>& child_route_id_pair) { |
| + std::list<PrerenderContentsData>::iterator it = prerender_list_.begin(); |
| + for (; it != prerender_list_.end(); ++it) { |
| + PrerenderContents* prerender_contents = it->contents_; |
| + |
| + int child_id; |
| + int route_id; |
| + bool has_child_id = prerender_contents->GetChildId(&child_id); |
| + bool has_route_id = has_child_id && |
| + prerender_contents->GetRouteId(&route_id); |
| + |
| + if (has_child_id && has_route_id && |
| + child_id == child_route_id_pair.first && |
| + route_id == child_route_id_pair.second) { |
| + break; |
| + } |
| + } |
| + return it; |
| +} |
| + |
| +void PrerenderManager::DestroyPreloadForChildRouteIdPair( |
| + const std::pair<int, int>& child_route_id_pair, |
| + FinalStatus final_status) { |
| + DCHECK(CalledOnValidThread()); |
| + std::list<PrerenderContentsData>::iterator it = |
| + FindPrerenderContentsForChildRouteIdPair(child_route_id_pair); |
| + if (it != prerender_list_.end()) { |
| + PrerenderContents* prerender_contents = it->contents_; |
| + prerender_contents->set_final_status(final_status); |
| + RemovePendingPreload(prerender_contents); |
| + |
| + delete prerender_contents; |
| + prerender_list_.erase(it); |
| + } |
| +} |
| + |
| void PrerenderManager::DeleteOldEntries() { |
| DCHECK(CalledOnValidThread()); |
| while (!prerender_list_.empty()) { |