Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3165)

Unified Diff: chrome/renderer/prerender/prerender_dispatcher.cc

Issue 10918189: Add PrerenderStatusEvent on Prerenders (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebase to trunk, remove some unrelated fixes... Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/prerender/prerender_dispatcher.cc
diff --git a/chrome/renderer/prerender/prerender_dispatcher.cc b/chrome/renderer/prerender/prerender_dispatcher.cc
index a3f72ec5798c2a26acdfbeb7a92d96bb2664a472..1ebd6f0c12fc6b29825c3803bca482ae9f8e4eb5 100644
--- a/chrome/renderer/prerender/prerender_dispatcher.cc
+++ b/chrome/renderer/prerender/prerender_dispatcher.cc
@@ -7,80 +7,116 @@
#include "base/logging.h"
#include "chrome/common/prerender_messages.h"
#include "chrome/renderer/prerender/prerender_extra_data.h"
+#include "content/public/common/referrer.h"
#include "content/public/renderer/render_thread.h"
+#include "content/public/renderer/render_view.h"
#include "googleurl/src/gurl.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
+#include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebPrerenderingSupport.h"
namespace prerender {
+using WebKit::WebPrerender;
+using WebKit::WebPrerenderingSupport;
+
PrerenderDispatcher::PrerenderDispatcher() {
- WebKit::WebPrerenderingSupport::initialize(this);
+ WebPrerenderingSupport::initialize(this);
}
PrerenderDispatcher::~PrerenderDispatcher() {
- WebKit::WebPrerenderingSupport::shutdown();
+ WebPrerenderingSupport::shutdown();
}
bool PrerenderDispatcher::IsPrerenderURL(const GURL& url) const {
- return prerender_urls_.find(url) != prerender_urls_.end();
-}
-
-void PrerenderDispatcher::OnAddPrerenderURL(const GURL& url) {
- PrerenderMap::iterator it = prerender_urls_.find(url);
- if (it != prerender_urls_.end()) {
- DCHECK_LT(0, it->second);
- it->second += 1;
- } else {
- prerender_urls_[url] = 1;
+ for (std::map<int, WebKit::WebPrerender*>::const_iterator
+ it = prerenders_.begin();
+ it != prerenders_.end(); ++it) {
+ if (it->second->url() == url)
+ return true;
}
-}
-
-void PrerenderDispatcher::OnRemovePrerenderURL(const GURL& url) {
- PrerenderMap::iterator it = prerender_urls_.find(url);
- // This is possible with a spurious remove.
- // TODO(cbentzel): We'd also want to send the map of active prerenders when
- // creating a new render process, so the Add/Remove go relative to that.
- // This may not be that big of a deal in practice, since the newly created tab
- // is unlikely to go to the prerendered page.
- if (it == prerender_urls_.end())
- return;
- DCHECK_LT(0, it->second);
- it->second -= 1;
- if (it->second == 0)
- prerender_urls_.erase(it);
+ for (std::multimap<int, GURL>::const_iterator it = prerender_aliases_.begin();
+ it != prerender_aliases_.end(); ++it) {
+ if (it->second == url)
+ return true;
+ }
+ return false;
}
bool PrerenderDispatcher::OnControlMessageReceived(
const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrerenderDispatcher, message)
- IPC_MESSAGE_HANDLER(PrerenderMsg_AddPrerenderURL, OnAddPrerenderURL)
- IPC_MESSAGE_HANDLER(PrerenderMsg_RemovePrerenderURL, OnRemovePrerenderURL)
+ IPC_MESSAGE_HANDLER(PrerenderMsg_StartedPrerender, OnStartedPrerender)
+ IPC_MESSAGE_HANDLER(PrerenderMsg_AddAliasToPrerender, OnAddAliasToPrerender)
+ IPC_MESSAGE_HANDLER(PrerenderMsg_StoppedPrerender, OnStoppedPrerender)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void PrerenderDispatcher::add(const WebKit::WebPrerender& prerender) {
+void PrerenderDispatcher::OnStartedPrerender(int prerender_id) {
+ running_prerenders_.insert(prerender_id);
+
+ std::map<int, WebPrerender*>::iterator it = prerenders_.find(prerender_id);
+ if (it != prerenders_.end())
+ it->second->didStartPrerender();
+}
+
+void PrerenderDispatcher::OnAddAliasToPrerender(int prerender_id,
+ const GURL& url) {
+ prerender_aliases_.insert(
+ std::multimap<int, GURL>::value_type(prerender_id, url));
+}
+
+void PrerenderDispatcher::OnStoppedPrerender(int prerender_id) {
+ // It's possible we will receive a spurious remove, so we don't crash in that
+ // situation.
+
+ // TODO(cbentzel): We'd also want to send the map of active prerenders when
+ // creating a new render process, so the Add/Remove go relative to that.
+ // This may not be that big of a deal in practice, since the newly created tab
+ // is unlikely to go to the prerendered page.
+
+ running_prerenders_.erase(prerender_id);
+ prerender_aliases_.erase(prerender_id);
+
+ std::map<int, WebPrerender*>::iterator it = prerenders_.find(prerender_id);
+ if (it != prerenders_.end())
+ it->second->didStopPrerender();
+}
+
+void PrerenderDispatcher::add(WebPrerender* prerender) {
const PrerenderExtraData& extra_data =
- PrerenderExtraData::FromPrerender(prerender);
+ PrerenderExtraData::FromPrerender(*prerender);
+ prerenders_.insert(std::map<int, WebPrerender*>::value_type(
+ extra_data.prerender_id(), prerender));
content::RenderThread::Get()->Send(new PrerenderHostMsg_AddLinkRelPrerender(
- extra_data.prerender_id(), GURL(prerender.url()),
- content::Referrer(GURL(prerender.referrer()), prerender.referrerPolicy()),
+ extra_data.prerender_id(), GURL(prerender->url()),
+ content::Referrer(GURL(prerender->referrer()),
+ prerender->referrerPolicy()),
extra_data.size(), extra_data.render_view_route_id()));
}
-void PrerenderDispatcher::cancel(const WebKit::WebPrerender& prerender) {
+void PrerenderDispatcher::cancel(WebPrerender* prerender) {
const PrerenderExtraData& extra_data =
- PrerenderExtraData::FromPrerender(prerender);
+ PrerenderExtraData::FromPrerender(*prerender);
+ std::map<int, WebPrerender*>::iterator it =
+ prerenders_.find(extra_data.prerender_id());
+ if (it != prerenders_.end())
+ prerenders_.erase(it);
content::RenderThread::Get()->Send(
new PrerenderHostMsg_CancelLinkRelPrerender(extra_data.prerender_id()));
}
-void PrerenderDispatcher::abandon(const WebKit::WebPrerender& prerender) {
+void PrerenderDispatcher::abandon(WebPrerender* prerender) {
const PrerenderExtraData& extra_data =
- PrerenderExtraData::FromPrerender(prerender);
+ PrerenderExtraData::FromPrerender(*prerender);
+ std::map<int, WebPrerender*>::iterator it =
+ prerenders_.find(extra_data.prerender_id());
+ if (it != prerenders_.end())
+ prerenders_.erase(it);
content::RenderThread::Get()->Send(
new PrerenderHostMsg_AbandonLinkRelPrerender(extra_data.prerender_id()));
}
« no previous file with comments | « chrome/renderer/prerender/prerender_dispatcher.h ('k') | chrome/renderer/prerender/prerender_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698