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

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

Issue 25772002: Allows prefetch requests to live beyond the renderer by delaying (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added DetachableType function for generality. 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/loader/detached_resource_handler.h"
6
7 #include <algorithm>
8 #include <vector>
9
10 #include "base/debug/alias.h"
11 #include "base/strings/string_util.h"
12 #include "content/browser/devtools/devtools_netlog_observer.h"
13 #include "content/browser/loader/resource_dispatcher_host_impl.h"
14 #include "content/browser/loader/resource_message_filter.h"
15 #include "content/browser/loader/resource_request_info_impl.h"
16 #include "content/common/resource_messages.h"
17 #include "content/public/browser/resource_dispatcher_host_delegate.h"
18 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h"
20 #include "net/url_request/url_request.h"
21
22 using base::TimeTicks;
23
24 namespace content {
25
26 DetachedResourceHandler::DetachedResourceHandler(
27 net::URLRequest* request, ResourceDispatcherHostImpl* rdh)
28 : request_(request),
29 rdh_(rdh),
30 read_buffer_(new net::IOBuffer(kReadBufSize)) {}
mmenke 2013/10/11 16:39:07 Reading may be delayed by the ResourceThrottle. T
jkarlin2 2013/10/11 18:37:04 Done.
31
32 DetachedResourceHandler::~DetachedResourceHandler() {}
33
34 bool DetachedResourceHandler::OnResponseCompleted(
35 int request_id, const net::URLRequestStatus& status,
36 const std::string& security_info) {
37 const ResourceRequestInfoImpl* info =
38 ResourceRequestInfoImpl::ForRequest(request_);
39 if (!info->filter()) return false;
mmenke 2013/10/11 16:39:07 Put return false on next line.
mmenke 2013/10/11 16:39:07 Should we be returning true? Looks like that's wh
jkarlin2 2013/10/11 18:37:04 My auto-google-formatter did that. Done.
jkarlin2 2013/10/11 18:37:04 You're right. Done.
40
41 // If we crash here, figure out what URL the renderer was requesting.
42 // http://crbug.com/107692
43 char url_buf[128];
44 base::strlcpy(url_buf, request_->url().spec().c_str(), arraysize(url_buf));
45 base::debug::Alias(url_buf);
mmenke 2013/10/11 16:39:07 The referenced bug was long since fixed. Do we ne
jkarlin2 2013/10/11 18:37:04 Done.
46
47 TimeTicks completion_time = TimeTicks::Now();
48
49 int error_code = status.error();
50
51 bool was_ignored_by_handler = info->WasIgnoredByHandler();
52
53 DCHECK(status.status() != net::URLRequestStatus::IO_PENDING);
54 // If this check fails, then we're in an inconsistent state because all
55 // requests ignored by the handler should be canceled (which should result in
56 // the ERR_ABORTED error code).
57 DCHECK(!was_ignored_by_handler || error_code == net::ERR_ABORTED);
58
59 // TODO(mkosiba): Fix up cases where we create a URLRequestStatus
60 // with a status() != SUCCESS and an error_code() == net::OK.
61 if (status.status() == net::URLRequestStatus::CANCELED &&
62 error_code == net::OK) {
63 error_code = net::ERR_ABORTED;
64 } else if (status.status() == net::URLRequestStatus::FAILED &&
65 error_code == net::OK) {
66 error_code = net::ERR_FAILED;
67 }
68
69 info->filter()->Send(new ResourceMsg_RequestComplete(
70 request_id, error_code, was_ignored_by_handler, security_info,
71 completion_time));
72 return true;
73 }
74
75 bool DetachedResourceHandler::OnUploadProgress(int request_id, uint64 position,
76 uint64 size) {
77 const ResourceRequestInfoImpl* info =
78 ResourceRequestInfoImpl::ForRequest(request_);
79 if (!info->filter()) return true;
mmenke 2013/10/11 16:39:07 nit: Move return onto another line.
jkarlin2 2013/10/11 18:37:04 Auto formatter again. Done.
80 info->filter()->Send(
81 new ResourceMsg_UploadProgress(request_id, position, size));
82 return true;
83 }
84
85 bool DetachedResourceHandler::OnResponseStarted(int request_id,
86 ResourceResponse* response,
87 bool* defer) {
88 const ResourceRequestInfoImpl* info =
89 ResourceRequestInfoImpl::ForRequest(request_);
90
91 if (!info->filter()) return true;
mmenke 2013/10/11 16:39:07 nit: Move return onto another line.
jkarlin2 2013/10/11 18:37:04 Done.
92
93 if (rdh_->delegate()) {
94 rdh_->delegate()->OnResponseStarted(request_, info->GetContext(), response,
95 info->filter());
mmenke 2013/10/11 16:39:07 Hmm...Wonder about some of the stuff this does, li
jkarlin2 2013/10/11 18:37:04 This seems to be an existing issue with prefetch a
96 }
97
98 DevToolsNetLogObserver::PopulateResponseInfo(request_, response);
99
100 response->head.request_start = request_->creation_time();
101 response->head.response_start = TimeTicks::Now();
102 info->filter()->Send(
103 new ResourceMsg_ReceivedResponse(request_id, response->head));
104
105 if (request_->response_info().metadata.get()) {
106 std::vector<char> copy(request_->response_info().metadata->data(),
107 request_->response_info().metadata->data() +
108 request_->response_info().metadata->size());
109 info->filter()->Send(
110 new ResourceMsg_ReceivedCachedMetadata(request_id, copy));
111 }
112
113 return true;
114 }
115
116 bool DetachedResourceHandler::OnWillStart(int request_id, const GURL& url,
117 bool* defer) {
118 return true;
119 }
120
121 bool DetachedResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
122 int* buf_size, int min_size) {
123 // Give the loader something to write its data to, but we'll never read it.
mmenke 2013/10/11 16:39:07 nit: Don't use "we" in comments, since it's ambig
jkarlin2 2013/10/11 18:37:04 Done.
124 *buf = read_buffer_.get();
125 *buf_size = kReadBufSize;
126 return true;
127 }
128
129 bool DetachedResourceHandler::OnReadCompleted(int request_id, int bytes_read,
130 bool* defer) {
131 return true;
132 }
133
134 bool DetachedResourceHandler::OnRequestRedirected(int request_id,
135 const GURL& new_url,
136 ResourceResponse* response,
137 bool* defer) {
138 return true;
139 }
140
141 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698