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

Side by Side Diff: content/browser/loader/sync_resource_handler.cc

Issue 25536005: Clean up ResourceHandler API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/loader/sync_resource_handler.h" 5 #include "content/browser/loader/sync_resource_handler.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/browser/devtools/devtools_netlog_observer.h" 8 #include "content/browser/devtools/devtools_netlog_observer.h"
9 #include "content/browser/loader/resource_dispatcher_host_impl.h" 9 #include "content/browser/loader/resource_dispatcher_host_impl.h"
10 #include "content/browser/loader/resource_message_filter.h" 10 #include "content/browser/loader/resource_message_filter.h"
11 #include "content/browser/loader/resource_request_info_impl.h" 11 #include "content/browser/loader/resource_request_info_impl.h"
12 #include "content/common/resource_messages.h" 12 #include "content/common/resource_messages.h"
13 #include "content/public/browser/global_request_id.h" 13 #include "content/public/browser/global_request_id.h"
14 #include "content/public/browser/resource_dispatcher_host_delegate.h" 14 #include "content/public/browser/resource_dispatcher_host_delegate.h"
15 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
18 18
19 namespace content { 19 namespace content {
20 20
21 SyncResourceHandler::SyncResourceHandler( 21 SyncResourceHandler::SyncResourceHandler(
22 net::URLRequest* request, 22 net::URLRequest* request,
23 IPC::Message* result_message, 23 IPC::Message* result_message,
24 ResourceDispatcherHostImpl* resource_dispatcher_host) 24 ResourceDispatcherHostImpl* resource_dispatcher_host)
25 : read_buffer_(new net::IOBuffer(kReadBufSize)), 25 : ResourceHandler(request),
26 request_(request), 26 read_buffer_(new net::IOBuffer(kReadBufSize)),
27 result_message_(result_message), 27 result_message_(result_message),
28 rdh_(resource_dispatcher_host) { 28 rdh_(resource_dispatcher_host) {
29 result_.final_url = request_->url(); 29 result_.final_url = request->url();
30 } 30 }
31 31
32 SyncResourceHandler::~SyncResourceHandler() { 32 SyncResourceHandler::~SyncResourceHandler() {
33 if (result_message_) { 33 if (result_message_) {
34 result_message_->set_reply_error(); 34 result_message_->set_reply_error();
35 const ResourceRequestInfoImpl* info = 35 ResourceMessageFilter* filter = GetFilter();
36 ResourceRequestInfoImpl::ForRequest(request_);
37 // If the filter doesn't exist at this point, the process has died and isn't 36 // If the filter doesn't exist at this point, the process has died and isn't
38 // waiting for the result message anymore. 37 // waiting for the result message anymore.
39 if (info->filter()) 38 if (filter)
40 info->filter()->Send(result_message_); 39 filter->Send(result_message_);
41 } 40 }
42 } 41 }
43 42
44 bool SyncResourceHandler::OnUploadProgress(int request_id, 43 bool SyncResourceHandler::OnUploadProgress(int request_id,
45 uint64 position, 44 uint64 position,
46 uint64 size) { 45 uint64 size) {
47 return true; 46 return true;
48 } 47 }
49 48
50 bool SyncResourceHandler::OnRequestRedirected( 49 bool SyncResourceHandler::OnRequestRedirected(
51 int request_id, 50 int request_id,
52 const GURL& new_url, 51 const GURL& new_url,
53 ResourceResponse* response, 52 ResourceResponse* response,
54 bool* defer) { 53 bool* defer) {
55 if (rdh_->delegate()) { 54 if (rdh_->delegate()) {
56 const ResourceRequestInfoImpl* info =
57 ResourceRequestInfoImpl::ForRequest(request_);
58 rdh_->delegate()->OnRequestRedirected( 55 rdh_->delegate()->OnRequestRedirected(
59 new_url, request_, info->GetContext(), response); 56 new_url, request(), GetRequestInfo()->GetContext(), response);
60 } 57 }
61 58
62 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); 59 DevToolsNetLogObserver::PopulateResponseInfo(request(), response);
63 // TODO(darin): It would be much better if this could live in WebCore, but 60 // TODO(darin): It would be much better if this could live in WebCore, but
64 // doing so requires API changes at all levels. Similar code exists in 61 // doing so requires API changes at all levels. Similar code exists in
65 // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-( 62 // WebCore/platform/network/cf/ResourceHandleCFNet.cpp :-(
66 if (new_url.GetOrigin() != result_.final_url.GetOrigin()) { 63 if (new_url.GetOrigin() != result_.final_url.GetOrigin()) {
67 LOG(ERROR) << "Cross origin redirect denied"; 64 LOG(ERROR) << "Cross origin redirect denied";
68 return false; 65 return false;
69 } 66 }
70 result_.final_url = new_url; 67 result_.final_url = new_url;
71 return true; 68 return true;
72 } 69 }
73 70
74 bool SyncResourceHandler::OnResponseStarted( 71 bool SyncResourceHandler::OnResponseStarted(
75 int request_id, 72 int request_id,
76 ResourceResponse* response, 73 ResourceResponse* response,
77 bool* defer) { 74 bool* defer) {
78 const ResourceRequestInfoImpl* info = 75 const ResourceRequestInfoImpl* info = GetRequestInfo();
79 ResourceRequestInfoImpl::ForRequest(request_);
80 if (!info->filter()) 76 if (!info->filter())
81 return false; 77 return false;
82 78
83 if (rdh_->delegate()) { 79 if (rdh_->delegate()) {
84 rdh_->delegate()->OnResponseStarted( 80 rdh_->delegate()->OnResponseStarted(
85 request_, info->GetContext(), response, info->filter()); 81 request(), info->GetContext(), response, info->filter());
86 } 82 }
87 83
88 DevToolsNetLogObserver::PopulateResponseInfo(request_, response); 84 DevToolsNetLogObserver::PopulateResponseInfo(request(), response);
89 85
90 // We don't care about copying the status here. 86 // We don't care about copying the status here.
91 result_.headers = response->head.headers; 87 result_.headers = response->head.headers;
92 result_.mime_type = response->head.mime_type; 88 result_.mime_type = response->head.mime_type;
93 result_.charset = response->head.charset; 89 result_.charset = response->head.charset;
94 result_.download_file_path = response->head.download_file_path; 90 result_.download_file_path = response->head.download_file_path;
95 result_.request_time = response->head.request_time; 91 result_.request_time = response->head.request_time;
96 result_.response_time = response->head.response_time; 92 result_.response_time = response->head.response_time;
97 result_.load_timing = response->head.load_timing; 93 result_.load_timing = response->head.load_timing;
98 result_.devtools_info = response->head.devtools_info; 94 result_.devtools_info = response->head.devtools_info;
99 return true; 95 return true;
100 } 96 }
101 97
102 bool SyncResourceHandler::OnWillStart(int request_id, 98 bool SyncResourceHandler::OnWillStart(int request_id,
103 const GURL& url, 99 const GURL& url,
104 bool* defer) { 100 bool* defer) {
105 return true; 101 return true;
106 } 102 }
107 103
108 bool SyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, 104 bool SyncResourceHandler::OnWillRead(int request_id,
109 int* buf_size, int min_size) { 105 scoped_refptr<net::IOBuffer>* buf,
106 int* buf_size,
107 int min_size) {
110 DCHECK(min_size == -1); 108 DCHECK(min_size == -1);
111 *buf = read_buffer_.get(); 109 *buf = read_buffer_.get();
112 *buf_size = kReadBufSize; 110 *buf_size = kReadBufSize;
113 return true; 111 return true;
114 } 112 }
115 113
116 bool SyncResourceHandler::OnReadCompleted(int request_id, int bytes_read, 114 bool SyncResourceHandler::OnReadCompleted(int request_id, int bytes_read,
117 bool* defer) { 115 bool* defer) {
118 if (!bytes_read) 116 if (!bytes_read)
119 return true; 117 return true;
120 result_.data.append(read_buffer_->data(), bytes_read); 118 result_.data.append(read_buffer_->data(), bytes_read);
121 return true; 119 return true;
122 } 120 }
123 121
124 bool SyncResourceHandler::OnResponseCompleted( 122 bool SyncResourceHandler::OnResponseCompleted(
125 int request_id, 123 int request_id,
126 const net::URLRequestStatus& status, 124 const net::URLRequestStatus& status,
127 const std::string& security_info) { 125 const std::string& security_info) {
128 const ResourceRequestInfoImpl* info = 126 ResourceMessageFilter* filter = GetFilter();
129 ResourceRequestInfoImpl::ForRequest(request_); 127 if (!filter)
130 if (!info->filter())
131 return false; 128 return false;
132 129
133 result_.error_code = status.error(); 130 result_.error_code = status.error();
134 131
135 result_.encoded_data_length = 132 result_.encoded_data_length =
136 DevToolsNetLogObserver::GetAndResetEncodedDataLength(request_); 133 DevToolsNetLogObserver::GetAndResetEncodedDataLength(request());
137 134
138 ResourceHostMsg_SyncLoad::WriteReplyParams(result_message_, result_); 135 ResourceHostMsg_SyncLoad::WriteReplyParams(result_message_, result_);
139 info->filter()->Send(result_message_); 136 filter->Send(result_message_);
140 result_message_ = NULL; 137 result_message_ = NULL;
141 return true; 138 return true;
142 } 139 }
143 140
144 void SyncResourceHandler::OnDataDownloaded( 141 void SyncResourceHandler::OnDataDownloaded(
145 int request_id, 142 int request_id,
146 int bytes_downloaded) { 143 int bytes_downloaded) {
147 // Sync requests don't involve ResourceMsg_DataDownloaded messages 144 // Sync requests don't involve ResourceMsg_DataDownloaded messages
148 // being sent back to renderers as progress is made. 145 // being sent back to renderers as progress is made.
149 } 146 }
150 147
151 } // namespace content 148 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/sync_resource_handler.h ('k') | content/browser/loader/throttling_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698