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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
6 #define CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/callback.h"
12 #include "chrome/browser/prerender/prerender_manager.h"
13 #include "chrome/browser/renderer_host/resource_handler.h"
14
15 class ChromeURLRequestContext;
16 namespace net {
17 class URLRequest;
18 }
19
20 // The PrerenderResourceHandler initiates prerendering of web pages
21 // under the following conditions:
22 // - The profile which initiated the request allows prerendering.
23 // - The initial request is a GET for a PREFETCH resource type.
24 // - The final URL (after redirects) has a scheme of http or https.
25 // - The response status code is a 200.
26 // - The MIME type of the response (sniffed or explicit) is text/html.
27 // - The resource will not need to revalidate within 30 seconds. This prevents
28 // no-cache or very quickly refreshing resources from being prerendered.
29 class PrerenderResourceHandler : public ResourceHandler {
30 public:
31 typedef base::Time (*GetCurrentTimeFunction)();
32
33 // Creates a new PrerenderResourceHandler if appropriate for the
34 // given |request| and |context|, otherwise NULL is returned. The
35 // caller is resposible for deleting the returned handler.
36 //
37 // |next_handler| is the backup handler that this handler delegates to
38 // for the majority of the commands, and must be non-NULL.
39 static PrerenderResourceHandler* MaybeCreate(
40 const net::URLRequest& request,
41 ChromeURLRequestContext* context,
42 ResourceHandler* next_handler);
43
44 // OnResponseStarted will ask the |prerender_manager_| to start
45 // prerendering the requested resource if it is of an appropriate
46 // content type. The next handler is still invoked.
47 virtual bool OnResponseStarted(int request_id,
48 ResourceResponse* response);
49
50 // The following methods simply delegate to the next_handler.
51 virtual bool OnUploadProgress(int request_id,
52 uint64 position,
53 uint64 size);
54 virtual bool OnRequestRedirected(int request_id, const GURL& url,
55 ResourceResponse* response,
56 bool* defer);
57 virtual bool OnWillStart(int request_id, const GURL& url, bool* defer);
58
59 virtual bool OnWillRead(int request_id,
60 net::IOBuffer** buf,
61 int* buf_size,
62 int min_size);
63
64 virtual bool OnReadCompleted(int request_id, int* bytes_read);
65
66 virtual bool OnResponseCompleted(int request_id,
67 const net::URLRequestStatus& status,
68 const std::string& security_info);
69
70 virtual void OnRequestClosed();
71
72 private:
73 friend class PrerenderResourceHandlerTest;
74 typedef Callback1<const GURL&>::Type PrerenderCallback;
75
76 static const int kDefaultPrerenderDurationSeconds;
77
78 PrerenderResourceHandler(ResourceHandler* next_handler,
79 PrerenderManager* prerender_manager);
80 PrerenderResourceHandler(ResourceHandler* next_handler,
81 PrerenderCallback* callback);
82 virtual ~PrerenderResourceHandler();
83
84 void RunCallbackFromUIThread(const GURL& url);
85 void StartPrerender(const GURL& url);
86 void set_prerender_duration(base::TimeDelta prerender_duration);
87 void set_get_current_time_function(GetCurrentTimeFunction get_current_time);
88
89 GURL url_;
90 scoped_refptr<ResourceHandler> next_handler_;
91 scoped_refptr<PrerenderManager> prerender_manager_;
92 scoped_ptr<PrerenderCallback> prerender_callback_;
93 base::TimeDelta prerender_duration_;
94 GetCurrentTimeFunction get_current_time_;
95
96 DISALLOW_COPY_AND_ASSIGN(PrerenderResourceHandler);
97 };
98
99 #endif // CHROME_BROWSER_PRERENDER_PRERENDER_RESOURCE_HANDLER_H_
OLDNEW
« 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