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

Side by Side Diff: chrome/browser/prerender/prerender_interceptor.cc

Issue 6111010: Remove PrerenderInterceptor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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) 2010 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 #include "chrome/browser/prerender/prerender_interceptor.h"
6
7 #include <string>
8
9 #include "base/logging.h"
10 #include "chrome/browser/browser_thread.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/io_thread.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/base/load_flags.h"
15
16 DISABLE_RUNNABLE_METHOD_REFCOUNT(PrerenderInterceptor);
17
18 PrerenderInterceptor::PrerenderInterceptor()
19 : ALLOW_THIS_IN_INITIALIZER_LIST(
20 callback_(NewCallback(this,
21 &PrerenderInterceptor::PrerenderDispatch))) {
22 net::URLRequest::RegisterRequestInterceptor(this);
23 }
24
25 PrerenderInterceptor::PrerenderInterceptor(
26 PrerenderInterceptorCallback* callback)
27 : callback_(callback) {
28 net::URLRequest::RegisterRequestInterceptor(this);
29 }
30
31 PrerenderInterceptor::~PrerenderInterceptor() {
32 net::URLRequest::UnregisterRequestInterceptor(this);
33 }
34
35 net::URLRequestJob* PrerenderInterceptor::MaybeIntercept(
36 net::URLRequest* request) {
37 return NULL;
38 }
39
40 net::URLRequestJob* PrerenderInterceptor::MaybeInterceptResponse(
41 net::URLRequest* request) {
42 // TODO(gavinp): unfortunately, we can't figure out the origin
43 // of this request here on systems where the referrer is blocked by
44 // configuration.
45
46 // TODO(gavinp): note that the response still might be intercepted
47 // by a later interceptor. Should we write an interposing delegate
48 // and only prerender dispatch on requests that aren't intercepted?
49 // Or is this a slippery slope?
50
51 if (request->load_flags() & net::LOAD_PREFETCH) {
52 std::string mime_type;
53 request->GetMimeType(&mime_type);
54 if (mime_type == "text/html")
55 BrowserThread::PostTask(
56 BrowserThread::UI,
57 FROM_HERE,
58 NewRunnableMethod(this,
59 &PrerenderInterceptor::RunCallbackFromUIThread,
60 request->url()));
61 }
62 return NULL;
63 }
64
65 void PrerenderInterceptor::RunCallbackFromUIThread(const GURL& url) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
67 callback_->Run(url);
68 }
69
70 void PrerenderInterceptor::PrerenderDispatch(
71 const GURL& url) {
72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
73 DVLOG(2) << "PrerenderDispatchOnUIThread: url=" << url;
74 }
75
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_interceptor.h ('k') | chrome/browser/prerender/prerender_interceptor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698