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

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

Issue 9875026: **NOTFORLANDING** New link rel=prerender API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch sets 3-7 against trunk, for combined browsing 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_message_filter.cc
diff --git a/chrome/browser/prerender/prerender_message_filter.cc b/chrome/browser/prerender/prerender_message_filter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b272e88934192b13c8c75101f807e994e4f30ecc
--- /dev/null
+++ b/chrome/browser/prerender/prerender_message_filter.cc
@@ -0,0 +1,103 @@
+// 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_message_filter.h"
+
+#include "base/bind.h"
+#include "chrome/browser/prerender/prerender_link_manager.h"
+#include "chrome/browser/prerender/prerender_link_manager_factory.h"
+#include "chrome/common/prerender_messages.h"
+#include "content/public/browser/browser_thread.h"
+
+using content::BrowserThread;
+
+namespace {
+
+void OnChannelClosingInUIThread(Profile* profile, int render_process_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ prerender::PrerenderLinkManager* prerender_link_manager =
+ prerender::PrerenderLinkManagerFactory::GetForProfile(profile);
+ if (!prerender_link_manager)
+ return;
+ prerender_link_manager->OnChannelClosing(render_process_id);
+}
+
+}
+
+namespace prerender {
+
+PrerenderMessageFilter::PrerenderMessageFilter(int render_process_id,
+ Profile* profile)
+ : render_process_id_(render_process_id),
+ profile_(profile)
+{
cbentzel 2012/04/24 15:42:59 Nit: move this up with profile_
gavinp 2012/04/26 23:55:39 Done. NitFromMeToTheUniverse: WebKit and chrome h
+}
+
+bool PrerenderMessageFilter::OnMessageReceived(const IPC::Message& message,
+ bool* message_was_ok) {
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(PrerenderMessageFilter, message, *message_was_ok)
+ IPC_MESSAGE_HANDLER(PrerenderHostMsg_AddPrerender, OnAddPrerender)
+ IPC_MESSAGE_HANDLER(PrerenderHostMsg_CancelPrerender, OnCancelPrerender)
+ IPC_MESSAGE_HANDLER(PrerenderHostMsg_AbandonPrerender, OnAbandonPrerender)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+
+ return handled;
+}
+
+void PrerenderMessageFilter::OverrideThreadForMessage(
+ const IPC::Message& message, content::BrowserThread::ID* thread) {
+ if (message.type() == PrerenderHostMsg_AddPrerender::ID ||
cbentzel 2012/04/24 15:42:59 What are the lifetime guarantees for both Prerende
gavinp 2012/04/26 23:55:39 At creation, the PrerenderMessageFilter is placed
+ message.type() == PrerenderHostMsg_CancelPrerender::ID ||
+ message.type() == PrerenderHostMsg_AbandonPrerender::ID) {
+ *thread = BrowserThread::UI;
+ }
+}
+
+void PrerenderMessageFilter::OnAddPrerender(
+ int prerender_id,
+ const GURL& url,
+ const content::Referrer& referrer,
+ const gfx::Size& size,
+ int render_view_route_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ PrerenderLinkManager* prerender_link_manager =
+ PrerenderLinkManagerFactory::GetForProfile(profile_);
+ if (!prerender_link_manager)
+ return;
+ prerender_link_manager->OnAddPrerender(
+ prerender_id, render_process_id_,
+ url, referrer, size, render_view_route_id);
+}
+
+void PrerenderMessageFilter::OnCancelPrerender(
+ int prerender_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ PrerenderLinkManager* prerender_link_manager =
+ PrerenderLinkManagerFactory::GetForProfile(profile_);
+ if (!prerender_link_manager)
+ return;
+ prerender_link_manager->OnCancelPrerender(
+ prerender_id, render_process_id_);
+}
+
+void PrerenderMessageFilter::OnAbandonPrerender(
+ int prerender_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ PrerenderLinkManager* prerender_link_manager =
+ PrerenderLinkManagerFactory::GetForProfile(profile_);
+ if (!prerender_link_manager)
+ return;
+ prerender_link_manager->OnAbandonPrerender(
+ prerender_id, render_process_id_);
+}
+
+void PrerenderMessageFilter::OnChannelClosing() {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&OnChannelClosingInUIThread, profile_, render_process_id_));
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698