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

Side by Side Diff: content/browser/renderer_host/async_resource_handler.cc

Issue 6628035: Move resource related IPCs to their own file in content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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
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 "chrome/browser/debugger/devtools_netlog_observer.h" 13 #include "chrome/browser/debugger/devtools_netlog_observer.h"
14 #include "chrome/browser/net/chrome_url_request_context.h" 14 #include "chrome/browser/net/chrome_url_request_context.h"
15 #include "chrome/browser/net/load_timing_observer.h" 15 #include "chrome/browser/net/load_timing_observer.h"
16 #include "chrome/common/render_messages.h" 16 #include "chrome/common/render_messages.h"
17 #include "chrome/common/resource_response.h"
18 #include "content/browser/renderer_host/global_request_id.h" 17 #include "content/browser/renderer_host/global_request_id.h"
19 #include "content/browser/renderer_host/resource_dispatcher_host.h" 18 #include "content/browser/renderer_host/resource_dispatcher_host.h"
20 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" 19 #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h"
21 #include "content/browser/renderer_host/resource_message_filter.h" 20 #include "content/browser/renderer_host/resource_message_filter.h"
21 #include "content/common/resource_response.h"
22 #include "content/common/resource_messages.h"
22 #include "net/base/io_buffer.h" 23 #include "net/base/io_buffer.h"
23 #include "net/base/load_flags.h" 24 #include "net/base/load_flags.h"
24 #include "net/base/net_log.h" 25 #include "net/base/net_log.h"
25 #include "webkit/glue/resource_loader_bridge.h" 26 #include "webkit/glue/resource_loader_bridge.h"
26 27
27 using base::Time; 28 using base::Time;
28 using base::TimeTicks; 29 using base::TimeTicks;
29 30
30 namespace { 31 namespace {
31 32
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 rdh_(resource_dispatcher_host), 85 rdh_(resource_dispatcher_host),
85 next_buffer_size_(kInitialReadBufSize) { 86 next_buffer_size_(kInitialReadBufSize) {
86 } 87 }
87 88
88 AsyncResourceHandler::~AsyncResourceHandler() { 89 AsyncResourceHandler::~AsyncResourceHandler() {
89 } 90 }
90 91
91 bool AsyncResourceHandler::OnUploadProgress(int request_id, 92 bool AsyncResourceHandler::OnUploadProgress(int request_id,
92 uint64 position, 93 uint64 position,
93 uint64 size) { 94 uint64 size) {
94 return filter_->Send(new ViewMsg_Resource_UploadProgress(routing_id_, 95 return filter_->Send(new ResourceMsg_UploadProgress(routing_id_, request_id,
95 request_id, 96 position, size));
96 position, size));
97 } 97 }
98 98
99 bool AsyncResourceHandler::OnRequestRedirected(int request_id, 99 bool AsyncResourceHandler::OnRequestRedirected(int request_id,
100 const GURL& new_url, 100 const GURL& new_url,
101 ResourceResponse* response, 101 ResourceResponse* response,
102 bool* defer) { 102 bool* defer) {
103 *defer = true; 103 *defer = true;
104 net::URLRequest* request = rdh_->GetURLRequest( 104 net::URLRequest* request = rdh_->GetURLRequest(
105 GlobalRequestID(filter_->child_id(), request_id)); 105 GlobalRequestID(filter_->child_id(), request_id));
106 LoadTimingObserver::PopulateTimingInfo(request, response); 106 LoadTimingObserver::PopulateTimingInfo(request, response);
107 DevToolsNetLogObserver::PopulateResponseInfo(request, response); 107 DevToolsNetLogObserver::PopulateResponseInfo(request, response);
108 return filter_->Send(new ViewMsg_Resource_ReceivedRedirect( 108 return filter_->Send(new ResourceMsg_ReceivedRedirect(
109 routing_id_, request_id, new_url, response->response_head)); 109 routing_id_, request_id, new_url, response->response_head));
110 } 110 }
111 111
112 bool AsyncResourceHandler::OnResponseStarted(int request_id, 112 bool AsyncResourceHandler::OnResponseStarted(int request_id,
113 ResourceResponse* response) { 113 ResourceResponse* response) {
114 // For changes to the main frame, inform the renderer of the new URL's 114 // For changes to the main frame, inform the renderer of the new URL's
115 // per-host settings before the request actually commits. This way the 115 // per-host settings before the request actually commits. This way the
116 // renderer will be able to set these precisely at the time the 116 // renderer will be able to set these precisely at the time the
117 // request commits, avoiding the possibility of e.g. zooming the old content 117 // request commits, avoiding the possibility of e.g. zooming the old content
118 // or of having to layout the new content twice. 118 // or of having to layout the new content twice.
(...skipping 11 matching lines...) Expand all
130 if (context) { 130 if (context) {
131 filter_->Send(new ViewMsg_SetContentSettingsForLoadingURL( 131 filter_->Send(new ViewMsg_SetContentSettingsForLoadingURL(
132 info->route_id(), request_url, 132 info->route_id(), request_url,
133 context->host_content_settings_map()->GetContentSettings( 133 context->host_content_settings_map()->GetContentSettings(
134 request_url))); 134 request_url)));
135 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL(info->route_id(), 135 filter_->Send(new ViewMsg_SetZoomLevelForLoadingURL(info->route_id(),
136 request_url, context->host_zoom_map()->GetZoomLevel(request_url))); 136 request_url, context->host_zoom_map()->GetZoomLevel(request_url)));
137 } 137 }
138 } 138 }
139 139
140 filter_->Send(new ViewMsg_Resource_ReceivedResponse( 140 filter_->Send(new ResourceMsg_ReceivedResponse(
141 routing_id_, request_id, response->response_head)); 141 routing_id_, request_id, response->response_head));
142 142
143 if (request->response_info().metadata) { 143 if (request->response_info().metadata) {
144 std::vector<char> copy(request->response_info().metadata->data(), 144 std::vector<char> copy(request->response_info().metadata->data(),
145 request->response_info().metadata->data() + 145 request->response_info().metadata->data() +
146 request->response_info().metadata->size()); 146 request->response_info().metadata->size());
147 filter_->Send(new ViewMsg_Resource_ReceivedCachedMetadata( 147 filter_->Send(new ResourceMsg_ReceivedCachedMetadata(
148 routing_id_, request_id, copy)); 148 routing_id_, request_id, copy));
149 } 149 }
150 150
151 return true; 151 return true;
152 } 152 }
153 153
154 bool AsyncResourceHandler::OnWillStart(int request_id, 154 bool AsyncResourceHandler::OnWillStart(int request_id,
155 const GURL& url, 155 const GURL& url,
156 bool* defer) { 156 bool* defer) {
157 return true; 157 return true;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // it's killing our read_buffer_, and we don't want that when we pause 208 // it's killing our read_buffer_, and we don't want that when we pause
209 // the request. 209 // the request.
210 rdh_->DataReceivedACK(filter_->child_id(), request_id); 210 rdh_->DataReceivedACK(filter_->child_id(), request_id);
211 // We just unmapped the memory. 211 // We just unmapped the memory.
212 read_buffer_ = NULL; 212 read_buffer_ = NULL;
213 return false; 213 return false;
214 } 214 }
215 // We just unmapped the memory. 215 // We just unmapped the memory.
216 read_buffer_ = NULL; 216 read_buffer_ = NULL;
217 217
218 filter_->Send(new ViewMsg_Resource_DataReceived( 218 filter_->Send(new ResourceMsg_DataReceived(
219 routing_id_, request_id, handle, *bytes_read)); 219 routing_id_, request_id, handle, *bytes_read));
220 220
221 return true; 221 return true;
222 } 222 }
223 223
224 void AsyncResourceHandler::OnDataDownloaded( 224 void AsyncResourceHandler::OnDataDownloaded(
225 int request_id, int bytes_downloaded) { 225 int request_id, int bytes_downloaded) {
226 filter_->Send(new ViewMsg_Resource_DataDownloaded( 226 filter_->Send(new ResourceMsg_DataDownloaded(
227 routing_id_, request_id, bytes_downloaded)); 227 routing_id_, request_id, bytes_downloaded));
228 } 228 }
229 229
230 bool AsyncResourceHandler::OnResponseCompleted( 230 bool AsyncResourceHandler::OnResponseCompleted(
231 int request_id, 231 int request_id,
232 const net::URLRequestStatus& status, 232 const net::URLRequestStatus& status,
233 const std::string& security_info) { 233 const std::string& security_info) {
234 Time completion_time = Time::Now(); 234 Time completion_time = Time::Now();
235 filter_->Send(new ViewMsg_Resource_RequestComplete(routing_id_, 235 filter_->Send(new ResourceMsg_RequestComplete(routing_id_,
236 request_id, 236 request_id,
237 status, 237 status,
238 security_info, 238 security_info,
239 completion_time)); 239 completion_time));
240 240
241 // If we still have a read buffer, then see about caching it for later... 241 // If we still have a read buffer, then see about caching it for later...
242 // Note that we have to make sure the buffer is not still being used, so we 242 // Note that we have to make sure the buffer is not still being used, so we
243 // have to perform an explicit check on the status code. 243 // have to perform an explicit check on the status code.
244 if (g_spare_read_buffer || 244 if (g_spare_read_buffer ||
245 net::URLRequestStatus::SUCCESS != status.status()) { 245 net::URLRequestStatus::SUCCESS != status.status()) {
246 read_buffer_ = NULL; 246 read_buffer_ = NULL;
247 } else if (read_buffer_.get()) { 247 } else if (read_buffer_.get()) {
248 DCHECK(read_buffer_->data()); 248 DCHECK(read_buffer_->data());
249 read_buffer_.swap(&g_spare_read_buffer); 249 read_buffer_.swap(&g_spare_read_buffer);
250 } 250 }
251 return true; 251 return true;
252 } 252 }
253 253
254 void AsyncResourceHandler::OnRequestClosed() { 254 void AsyncResourceHandler::OnRequestClosed() {
255 } 255 }
256 256
257 // static 257 // static
258 void AsyncResourceHandler::GlobalCleanup() { 258 void AsyncResourceHandler::GlobalCleanup() {
259 if (g_spare_read_buffer) { 259 if (g_spare_read_buffer) {
260 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer(). 260 // Avoid the CHECK in SharedIOBuffer::~SharedIOBuffer().
261 SharedIOBuffer* tmp = g_spare_read_buffer; 261 SharedIOBuffer* tmp = g_spare_read_buffer;
262 g_spare_read_buffer = NULL; 262 g_spare_read_buffer = NULL;
263 tmp->Release(); 263 tmp->Release();
264 } 264 }
265 } 265 }
OLDNEW
« no previous file with comments | « content/browser/plugin_process_host.cc ('k') | content/browser/renderer_host/buffered_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698