OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/connect_interceptor.h" | 5 #include "chrome/browser/net/connect_interceptor.h" |
6 | 6 |
7 #include "chrome/browser/net/predictor_api.h" | 7 #include "chrome/browser/net/predictor_api.h" |
| 8 #include "net/base/load_flags.h" |
8 | 9 |
9 namespace chrome_browser_net { | 10 namespace chrome_browser_net { |
10 | 11 |
11 ConnectInterceptor::ConnectInterceptor() { | 12 ConnectInterceptor::ConnectInterceptor() { |
12 URLRequest::RegisterRequestInterceptor(this); | 13 URLRequest::RegisterRequestInterceptor(this); |
13 } | 14 } |
14 | 15 |
15 ConnectInterceptor::~ConnectInterceptor() { | 16 ConnectInterceptor::~ConnectInterceptor() { |
16 URLRequest::UnregisterRequestInterceptor(this); | 17 URLRequest::UnregisterRequestInterceptor(this); |
17 } | 18 } |
18 | 19 |
19 URLRequestJob* ConnectInterceptor::MaybeIntercept(URLRequest* request) { | 20 URLRequestJob* ConnectInterceptor::MaybeIntercept(URLRequest* request) { |
20 if (!request->referrer().empty()) { | 21 bool is_subresource = !(request->load_flags() & net::LOAD_MAIN_FRAME); |
| 22 if (is_subresource && !request->referrer().empty()) { |
21 // Learn about our referring URL, for use in the future. | 23 // Learn about our referring URL, for use in the future. |
22 GURL referring_url(GURL(request->referrer()).GetWithEmptyPath()); | 24 GURL referring_url(request->referrer()); |
23 // TODO(jar): Only call if we think this was part of a frame load, and not a | 25 LearnFromNavigation(referring_url.GetWithEmptyPath(), |
24 // link navigation. For now, we'll "learn" that to preconnect when a user | 26 request->url().GetWithEmptyPath()); |
25 // actually does a click... which will probably waste space in our referrers | |
26 // table (since it probably won't be that deterministic). | |
27 LearnFromNavigation(referring_url, request->url().GetWithEmptyPath()); | |
28 } | 27 } |
| 28 bool is_frame = 0 != (request->load_flags() & (net::LOAD_SUB_FRAME | |
| 29 net::LOAD_MAIN_FRAME)); |
29 // Now we use previous learning and setup for our subresources. | 30 // Now we use previous learning and setup for our subresources. |
30 if (request->was_fetched_via_proxy()) | 31 if (is_frame && !request->was_fetched_via_proxy()) |
31 return NULL; | 32 PredictFrameSubresources(request->url().GetWithEmptyPath()); |
32 // TODO(jar): Only call if we believe this is a frame, and might have | |
33 // subresources. We could "guess" by looking at path extensions (such as | |
34 // foo.jpg or goo.gif etc.), but better would be to get this info from webkit | |
35 // and have it add the info to the request (we currently only set the | |
36 // priority, but we could record whether it was a frame). | |
37 PredictFrameSubresources(request->url().GetWithEmptyPath()); | |
38 return NULL; | 33 return NULL; |
39 } | 34 } |
40 | 35 |
41 } // namespace chrome_browser_net | 36 } // namespace chrome_browser_net |
OLD | NEW |