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

Unified Diff: chrome/browser/prerender/prerender_link_manager.cc

Issue 10198040: New link rel=prerender api, using WebKit::WebPrerenderingPlatform (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the urls_to_id_map_, and follow consequences through. Created 8 years, 8 months 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/browser/prerender/prerender_link_manager.cc
diff --git a/chrome/browser/prerender/prerender_link_manager.cc b/chrome/browser/prerender/prerender_link_manager.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b9f00cc4e57964baaba76af6118b82ed3b247f9b
--- /dev/null
+++ b/chrome/browser/prerender/prerender_link_manager.cc
@@ -0,0 +1,125 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/prerender/prerender_link_manager.h"
+
+#include <limits>
+#include <queue>
+#include <utility>
+
+#include "chrome/browser/prerender/prerender_contents.h"
+#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/browser/prerender/prerender_manager_factory.h"
+#include "chrome/browser/profiles/profile.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/session_storage_namespace.h"
+#include "content/public/common/referrer.h"
+#include "googleurl/src/gurl.h"
+#include "googleurl/src/url_canon.h"
+#include "ui/gfx/size.h"
+
+using content::RenderViewHost;
+using content::SessionStorageNamespace;
+
+namespace prerender {
+
+PrerenderLinkManager::PrerenderLinkManager(PrerenderManager* manager)
+ : manager_(manager) {
+}
+
+PrerenderLinkManager::~PrerenderLinkManager() {
+}
+
+bool PrerenderLinkManager::OnAddPrerender(int child_id,
+ int prerender_id,
+ const GURL& orig_url,
+ const content::Referrer& referrer,
+ const gfx::Size& size,
+ int render_view_route_id) {
+ DVLOG(2) << "OnAddPrerender, child_id = " << child_id
+ << ", prerender_id = " << prerender_id
+ << ", url = " << orig_url.spec();
+ DVLOG(3) << "... render_view_route_id = " << render_view_route_id
+ << ", referrer url = " << referrer.url.spec();
+ // TODO(gavinp): Add tests to insure fragments work, then remove this fragment
dominich 2012/04/29 18:52:55 nit: ensure
gavinp 2012/04/30 11:43:16 Done.
+ // clearing code.
+ url_canon::Replacements<char> replacements;
+ replacements.ClearRef();
+ const GURL url = orig_url.ReplaceComponents(replacements);
+
+ // Unit tests pass in a child_id == -1.
+ RenderViewHost* source_render_view_host = NULL;
+ SessionStorageNamespace* session_storage_namespace = NULL;
+ if (child_id != -1) {
+ source_render_view_host =
+ RenderViewHost::FromID(child_id, render_view_route_id);
+ if (!source_render_view_host || !source_render_view_host->GetView())
+ return false;
+ session_storage_namespace =
+ source_render_view_host->GetSessionStorageNamespace();
+ }
+
+ if (!manager_->AddPrerenderFromLinkRelPrerender(
dominich 2012/04/29 18:52:55 possibly contentious comment: why not move this ma
gavinp 2012/04/30 11:43:16 We don't key on url/sessionstorage though. The ke
dominich 2012/04/30 15:52:05 I believe this will be necessary (or convenient) f
+ child_id, render_view_route_id, url, referrer,
+ size, session_storage_namespace))
+ return false;
+ const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
+ DCHECK(!ids_to_url_map_.count(child_and_prerender_id));
+ ids_to_url_map_.insert(std::make_pair(child_and_prerender_id, url));
+ return true;
+}
+
+void PrerenderLinkManager::OnCancelPrerender(int prerender_id,
+ int child_id) {
+ DVLOG(2) << "OnCancelPrerender, child_id = " << child_id
+ << ", prerender_id = " << prerender_id;
+ const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
+ IdPairToUrlMap::iterator id_url_iter =
+ ids_to_url_map_.find(child_and_prerender_id);
+ if (id_url_iter == ids_to_url_map_.end()) {
+ DVLOG(5) << "... canceling a prerender that doesn't exist.";
+ return;
+ }
+ const GURL url = id_url_iter->second;
+ ids_to_url_map_.erase(id_url_iter);
+ manager_->MaybeCancelPrerender(url);
+}
+
+void PrerenderLinkManager::OnAbandonPrerender(int prerender_id, int child_id) {
+ DVLOG(2) << "OnAbandonPrerender, child_id = " << child_id
+ << ", prerender_id = " << prerender_id;
+ // TODO(gavinp,cbentzel): Implement reasonable behaviour for
+ // navigation away from launcher.
+ const ChildAndPrerenderIdPair child_and_prerender_id(child_id, prerender_id);
+ if (ids_to_url_map_.count(child_and_prerender_id))
+ ids_to_url_map_.erase(child_and_prerender_id);
+}
+
+void PrerenderLinkManager::OnChannelClosing(int child_id) {
+ DVLOG(2) << "OnChannelClosing, child id = " << child_id;
+ const ChildAndPrerenderIdPair child_and_minimum_prerender_id(
+ child_id, std::numeric_limits<int>::min());
+ const ChildAndPrerenderIdPair child_and_maximum_prerender_id(
+ child_id, std::numeric_limits<int>::max());
+ std::queue<int> prerender_ids_to_abandon;
+ for (IdPairToUrlMap::iterator
+ i = ids_to_url_map_.lower_bound(child_and_minimum_prerender_id),
+ e = ids_to_url_map_.upper_bound(child_and_maximum_prerender_id);
+ i != e; ++i) {
+ prerender_ids_to_abandon.push(i->first.second);
+ }
+ while (!prerender_ids_to_abandon.empty()) {
+ DVLOG(4) << "---> abandon prerender_id = "
+ << prerender_ids_to_abandon.front();
+ OnAbandonPrerender(prerender_ids_to_abandon.front(), child_id);
+ prerender_ids_to_abandon.pop();
+ }
+}
+
+bool PrerenderLinkManager::IsEmpty() const {
+ return ids_to_url_map_.empty();
+}
+
+} // namespace prerender
+

Powered by Google App Engine
This is Rietveld 408576698