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

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

Issue 2390313002: Make SyncLoad result handling pluggable (Closed)
Patch Set: +#include "b/m/ref_counted.h" Created 4 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
« no previous file with comments | « content/browser/loader/sync_resource_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/callback_helpers.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "content/browser/loader/netlog_observer.h" 9 #include "content/browser/loader/netlog_observer.h"
9 #include "content/browser/loader/resource_dispatcher_host_impl.h" 10 #include "content/browser/loader/resource_dispatcher_host_impl.h"
10 #include "content/browser/loader/resource_message_filter.h" 11 #include "content/browser/loader/resource_message_filter.h"
11 #include "content/browser/loader/resource_request_info_impl.h" 12 #include "content/browser/loader/resource_request_info_impl.h"
12 #include "content/common/resource_messages.h" 13 #include "content/common/resource_messages.h"
13 #include "content/public/browser/resource_dispatcher_host_delegate.h" 14 #include "content/public/browser/resource_dispatcher_host_delegate.h"
14 #include "content/public/browser/resource_request_info.h" 15 #include "content/public/browser/resource_request_info.h"
15 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
16 #include "net/http/http_response_headers.h" 17 #include "net/http/http_response_headers.h"
17 #include "net/url_request/redirect_info.h" 18 #include "net/url_request/redirect_info.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 SyncResourceHandler::SyncResourceHandler( 22 SyncResourceHandler::SyncResourceHandler(
22 net::URLRequest* request, 23 net::URLRequest* request,
23 IPC::Message* result_message, 24 const SyncLoadResultCallback& result_handler,
24 ResourceDispatcherHostImpl* resource_dispatcher_host) 25 ResourceDispatcherHostImpl* resource_dispatcher_host)
25 : ResourceHandler(request), 26 : ResourceHandler(request),
26 read_buffer_(new net::IOBuffer(kReadBufSize)), 27 read_buffer_(new net::IOBuffer(kReadBufSize)),
27 result_message_(result_message), 28 result_handler_(result_handler),
28 rdh_(resource_dispatcher_host), 29 rdh_(resource_dispatcher_host),
29 total_transfer_size_(0) { 30 total_transfer_size_(0) {
30 result_.final_url = request->url(); 31 result_.final_url = request->url();
31 } 32 }
32 33
33 SyncResourceHandler::~SyncResourceHandler() { 34 SyncResourceHandler::~SyncResourceHandler() {
34 if (result_message_) { 35 if (result_handler_)
35 result_message_->set_reply_error(); 36 result_handler_.Run(nullptr);
36 ResourceMessageFilter* filter = GetFilter();
37 // If the filter doesn't exist at this point, the process has died and isn't
38 // waiting for the result message anymore.
39 if (filter)
40 filter->Send(result_message_);
41 }
42 } 37 }
43 38
44 bool SyncResourceHandler::OnRequestRedirected( 39 bool SyncResourceHandler::OnRequestRedirected(
45 const net::RedirectInfo& redirect_info, 40 const net::RedirectInfo& redirect_info,
46 ResourceResponse* response, 41 ResourceResponse* response,
47 bool* defer) { 42 bool* defer) {
48 if (rdh_->delegate()) { 43 if (rdh_->delegate()) {
49 rdh_->delegate()->OnRequestRedirected( 44 rdh_->delegate()->OnRequestRedirected(
50 redirect_info.new_url, request(), GetRequestInfo()->GetContext(), 45 redirect_info.new_url, request(), GetRequestInfo()->GetContext(),
51 response); 46 response);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 bool SyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) { 102 bool SyncResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
108 if (!bytes_read) 103 if (!bytes_read)
109 return true; 104 return true;
110 result_.data.append(read_buffer_->data(), bytes_read); 105 result_.data.append(read_buffer_->data(), bytes_read);
111 return true; 106 return true;
112 } 107 }
113 108
114 void SyncResourceHandler::OnResponseCompleted( 109 void SyncResourceHandler::OnResponseCompleted(
115 const net::URLRequestStatus& status, 110 const net::URLRequestStatus& status,
116 bool* defer) { 111 bool* defer) {
117 ResourceMessageFilter* filter = GetFilter();
118 if (!filter)
119 return;
120
121 result_.error_code = status.error(); 112 result_.error_code = status.error();
122 113
123 int total_transfer_size = request()->GetTotalReceivedBytes(); 114 int total_transfer_size = request()->GetTotalReceivedBytes();
124 result_.encoded_data_length = total_transfer_size_ + total_transfer_size; 115 result_.encoded_data_length = total_transfer_size_ + total_transfer_size;
125 result_.encoded_body_length = request()->GetRawBodyBytes(); 116 result_.encoded_body_length = request()->GetRawBodyBytes();
126 117
127 ResourceHostMsg_SyncLoad::WriteReplyParams(result_message_, result_); 118 base::ResetAndReturn(&result_handler_).Run(&result_);
128 filter->Send(result_message_);
129 result_message_ = NULL;
130 return;
131 } 119 }
132 120
133 void SyncResourceHandler::OnDataDownloaded(int bytes_downloaded) { 121 void SyncResourceHandler::OnDataDownloaded(int bytes_downloaded) {
134 // Sync requests don't involve ResourceMsg_DataDownloaded messages 122 // Sync requests don't involve ResourceMsg_DataDownloaded messages
135 // being sent back to renderers as progress is made. 123 // being sent back to renderers as progress is made.
136 } 124 }
137 125
138 } // namespace content 126 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/sync_resource_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698