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

Unified Diff: chrome/browser/prerender/prerender_resource_handler.h

Issue 5912001: Add PrerenderResourceHandler and hook it into the ResourceDispatcherHost.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Another merge with trunk Created 9 years, 11 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_resource_handler.h
diff --git a/chrome/browser/prerender/prerender_resource_handler.h b/chrome/browser/prerender/prerender_resource_handler.h
new file mode 100644
index 0000000000000000000000000000000000000000..db825e76f59e9d6ac6ba9c7131b56bb8ff86a752
--- /dev/null
+++ b/chrome/browser/prerender/prerender_resource_handler.h
@@ -0,0 +1,99 @@
+// Copyright (c) 2011 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.
+
+#ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
+#define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
+#pragma once
+
+#include <string>
+
+#include "base/callback.h"
+#include "chrome/browser/prerender/prerender_manager.h"
+#include "chrome/browser/renderer_host/resource_handler.h"
+
+class ChromeURLRequestContext;
+namespace net {
+class URLRequest;
+}
+
+// The PrerenderResourceHandler initiates prerendering of web pages
+// under the following conditions:
+// - The profile which initiated the request allows prerendering.
+// - The initial request is a GET for a PREFETCH resource type.
+// - The final URL (after redirects) has a scheme of http or https.
+// - The response status code is a 200.
+// - The MIME type of the response (sniffed or explicit) is text/html.
+// - The resource will not need to revalidate within 30 seconds. This prevents
+// no-cache or very quickly refreshing resources from being prerendered.
+class PrerenderResourceHandler : public ResourceHandler {
+ public:
+ typedef base::Time (*GetCurrentTimeFunction)();
+
+ // Creates a new PrerenderResourceHandler if appropriate for the
+ // given |request| and |context|, otherwise NULL is returned. The
+ // caller is resposible for deleting the returned handler.
+ //
+ // |next_handler| is the backup handler that this handler delegates to
+ // for the majority of the commands, and must be non-NULL.
+ static PrerenderResourceHandler* MaybeCreate(
+ const net::URLRequest& request,
+ ChromeURLRequestContext* context,
+ ResourceHandler* next_handler);
+
+ // OnResponseStarted will ask the |prerender_manager_| to start
+ // prerendering the requested resource if it is of an appropriate
+ // content type. The next handler is still invoked.
+ virtual bool OnResponseStarted(int request_id,
+ ResourceResponse* response);
+
+ // The following methods simply delegate to the next_handler.
+ virtual bool OnUploadProgress(int request_id,
+ uint64 position,
+ uint64 size);
+ virtual bool OnRequestRedirected(int request_id, const GURL& url,
+ ResourceResponse* response,
+ bool* defer);
+ virtual bool OnWillStart(int request_id, const GURL& url, bool* defer);
+
+ virtual bool OnWillRead(int request_id,
+ net::IOBuffer** buf,
+ int* buf_size,
+ int min_size);
+
+ virtual bool OnReadCompleted(int request_id, int* bytes_read);
+
+ virtual bool OnResponseCompleted(int request_id,
+ const net::URLRequestStatus& status,
+ const std::string& security_info);
+
+ virtual void OnRequestClosed();
+
+ private:
+ friend class PrerenderResourceHandlerTest;
+ typedef Callback1<const GURL&>::Type PrerenderCallback;
+
+ static const int kDefaultPrerenderDurationSeconds;
+
+ PrerenderResourceHandler(ResourceHandler* next_handler,
+ PrerenderManager* prerender_manager);
+ PrerenderResourceHandler(ResourceHandler* next_handler,
+ PrerenderCallback* callback);
+ virtual ~PrerenderResourceHandler();
+
+ void RunCallbackFromUIThread(const GURL& url);
+ void StartPrerender(const GURL& url);
+ void set_prerender_duration(base::TimeDelta prerender_duration);
+ void set_get_current_time_function(GetCurrentTimeFunction get_current_time);
+
+ GURL url_;
+ scoped_refptr<ResourceHandler> next_handler_;
+ scoped_refptr<PrerenderManager> prerender_manager_;
+ scoped_ptr<PrerenderCallback> prerender_callback_;
+ base::TimeDelta prerender_duration_;
+ GetCurrentTimeFunction get_current_time_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrerenderResourceHandler);
+};
+
+#endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
« no previous file with comments | « chrome/browser/prerender/prerender_manager_unittest.cc ('k') | chrome/browser/prerender/prerender_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698