OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "content/browser/renderer_host/async_resource_handler.h" | 5 #include "content/browser/renderer_host/async_resource_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "content/browser/debugger/devtools_netlog_observer.h" | 13 #include "content/browser/debugger/devtools_netlog_observer.h" |
14 #include "content/browser/host_zoom_map.h" | 14 #include "content/browser/host_zoom_map.h" |
15 #include "content/browser/renderer_host/global_request_id.h" | 15 #include "content/browser/renderer_host/global_request_id.h" |
16 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 16 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
17 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" | 17 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
18 #include "content/browser/renderer_host/resource_message_filter.h" | 18 #include "content/browser/renderer_host/resource_message_filter.h" |
19 #include "content/browser/resource_context.h" | 19 #include "content/browser/resource_context.h" |
20 #include "content/common/resource_messages.h" | 20 #include "content/common/resource_messages.h" |
21 #include "content/common/view_messages.h" | 21 #include "content/common/view_messages.h" |
22 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 22 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
23 #include "content/public/common/resource_response.h" | 23 #include "content/public/common/resource_response.h" |
24 #include "net/base/io_buffer.h" | 24 #include "net/base/io_buffer.h" |
25 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
26 #include "net/base/net_log.h" | 26 #include "net/base/net_log.h" |
27 #include "webkit/glue/resource_loader_bridge.h" | 27 #include "webkit/glue/resource_loader_bridge.h" |
28 | 28 |
29 using base::Time; | |
30 using base::TimeTicks; | 29 using base::TimeTicks; |
31 | 30 |
32 namespace { | 31 namespace { |
33 | 32 |
34 // When reading, we don't know if we are going to get EOF (0 bytes read), so | 33 // When reading, we don't know if we are going to get EOF (0 bytes read), so |
35 // we typically have a buffer that we allocated but did not use. We keep | 34 // we typically have a buffer that we allocated but did not use. We keep |
36 // this buffer around for the next read as a small optimization. | 35 // this buffer around for the next read as a small optimization. |
37 SharedIOBuffer* g_spare_read_buffer = NULL; | 36 SharedIOBuffer* g_spare_read_buffer = NULL; |
38 | 37 |
39 // The initial size of the shared memory buffer. (32 kilobytes). | 38 // The initial size of the shared memory buffer. (32 kilobytes). |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 const GURL& new_url, | 102 const GURL& new_url, |
104 content::ResourceResponse* response, | 103 content::ResourceResponse* response, |
105 bool* defer) { | 104 bool* defer) { |
106 *defer = true; | 105 *defer = true; |
107 net::URLRequest* request = rdh_->GetURLRequest( | 106 net::URLRequest* request = rdh_->GetURLRequest( |
108 GlobalRequestID(filter_->child_id(), request_id)); | 107 GlobalRequestID(filter_->child_id(), request_id)); |
109 if (rdh_->delegate()) | 108 if (rdh_->delegate()) |
110 rdh_->delegate()->OnRequestRedirected(request, response, filter_); | 109 rdh_->delegate()->OnRequestRedirected(request, response, filter_); |
111 | 110 |
112 DevToolsNetLogObserver::PopulateResponseInfo(request, response); | 111 DevToolsNetLogObserver::PopulateResponseInfo(request, response); |
| 112 response->request_start = request->creation_time(); |
| 113 response->response_start = TimeTicks::Now(); |
113 return filter_->Send(new ResourceMsg_ReceivedRedirect( | 114 return filter_->Send(new ResourceMsg_ReceivedRedirect( |
114 routing_id_, request_id, new_url, *response)); | 115 routing_id_, request_id, new_url, *response)); |
115 } | 116 } |
116 | 117 |
117 bool AsyncResourceHandler::OnResponseStarted( | 118 bool AsyncResourceHandler::OnResponseStarted( |
118 int request_id, | 119 int request_id, |
119 content::ResourceResponse* response) { | 120 content::ResourceResponse* response) { |
120 // For changes to the main frame, inform the renderer of the new URL's | 121 // For changes to the main frame, inform the renderer of the new URL's |
121 // per-host settings before the request actually commits. This way the | 122 // per-host settings before the request actually commits. This way the |
122 // renderer will be able to set these precisely at the time the | 123 // renderer will be able to set these precisely at the time the |
(...skipping 13 matching lines...) Expand all Loading... |
136 | 137 |
137 ResourceDispatcherHostRequestInfo* info = rdh_->InfoForRequest(request); | 138 ResourceDispatcherHostRequestInfo* info = rdh_->InfoForRequest(request); |
138 if (info->resource_type() == ResourceType::MAIN_FRAME && host_zoom_map) { | 139 if (info->resource_type() == ResourceType::MAIN_FRAME && host_zoom_map) { |
139 GURL request_url(request->url()); | 140 GURL request_url(request->url()); |
140 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( | 141 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL( |
141 info->route_id(), | 142 info->route_id(), |
142 request_url, host_zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL( | 143 request_url, host_zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL( |
143 request_url)))); | 144 request_url)))); |
144 } | 145 } |
145 | 146 |
| 147 response->request_start = request->creation_time(); |
| 148 response->response_start = TimeTicks::Now(); |
146 filter_->Send(new ResourceMsg_ReceivedResponse( | 149 filter_->Send(new ResourceMsg_ReceivedResponse( |
147 routing_id_, request_id, *response)); | 150 routing_id_, request_id, *response)); |
148 | 151 |
149 if (request->response_info().metadata) { | 152 if (request->response_info().metadata) { |
150 std::vector<char> copy(request->response_info().metadata->data(), | 153 std::vector<char> copy(request->response_info().metadata->data(), |
151 request->response_info().metadata->data() + | 154 request->response_info().metadata->data() + |
152 request->response_info().metadata->size()); | 155 request->response_info().metadata->size()); |
153 filter_->Send(new ResourceMsg_ReceivedCachedMetadata( | 156 filter_->Send(new ResourceMsg_ReceivedCachedMetadata( |
154 routing_id_, request_id, copy)); | 157 routing_id_, request_id, copy)); |
155 } | 158 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 void AsyncResourceHandler::OnDataDownloaded( | 237 void AsyncResourceHandler::OnDataDownloaded( |
235 int request_id, int bytes_downloaded) { | 238 int request_id, int bytes_downloaded) { |
236 filter_->Send(new ResourceMsg_DataDownloaded( | 239 filter_->Send(new ResourceMsg_DataDownloaded( |
237 routing_id_, request_id, bytes_downloaded)); | 240 routing_id_, request_id, bytes_downloaded)); |
238 } | 241 } |
239 | 242 |
240 bool AsyncResourceHandler::OnResponseCompleted( | 243 bool AsyncResourceHandler::OnResponseCompleted( |
241 int request_id, | 244 int request_id, |
242 const net::URLRequestStatus& status, | 245 const net::URLRequestStatus& status, |
243 const std::string& security_info) { | 246 const std::string& security_info) { |
244 Time completion_time = Time::Now(); | 247 TimeTicks completion_time = TimeTicks::Now(); |
245 filter_->Send(new ResourceMsg_RequestComplete(routing_id_, | 248 filter_->Send(new ResourceMsg_RequestComplete(routing_id_, |
246 request_id, | 249 request_id, |
247 status, | 250 status, |
248 security_info, | 251 security_info, |
249 completion_time)); | 252 completion_time)); |
250 | 253 |
251 // If we still have a read buffer, then see about caching it for later... | 254 // If we still have a read buffer, then see about caching it for later... |
252 // Note that we have to make sure the buffer is not still being used, so we | 255 // Note that we have to make sure the buffer is not still being used, so we |
253 // have to perform an explicit check on the status code. | 256 // have to perform an explicit check on the status code. |
254 if (g_spare_read_buffer || | 257 if (g_spare_read_buffer || |
(...skipping 11 matching lines...) Expand all Loading... |
266 | 269 |
267 // static | 270 // static |
268 void AsyncResourceHandler::GlobalCleanup() { | 271 void AsyncResourceHandler::GlobalCleanup() { |
269 if (g_spare_read_buffer) { | 272 if (g_spare_read_buffer) { |
270 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer(). | 273 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer(). |
271 SharedIOBuffer* tmp = g_spare_read_buffer; | 274 SharedIOBuffer* tmp = g_spare_read_buffer; |
272 g_spare_read_buffer = NULL; | 275 g_spare_read_buffer = NULL; |
273 tmp->Release(); | 276 tmp->Release(); |
274 } | 277 } |
275 } | 278 } |
OLD | NEW |