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

Side by Side Diff: content/browser/download/download_request_core.h

Issue 1544603003: [Downloads] Do not store error responses during resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify-downloader-core
Patch Set: Created 4 years, 11 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
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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "content/browser/loader/resource_handler.h" 17 #include "content/browser/loader/resource_handler.h"
18 #include "content/public/browser/download_interrupt_reasons.h" 18 #include "content/public/browser/download_interrupt_reasons.h"
19 #include "content/public/browser/download_save_info.h" 19 #include "content/public/browser/download_save_info.h"
20 #include "content/public/browser/download_url_parameters.h" 20 #include "content/public/browser/download_url_parameters.h"
21 21
22 namespace net { 22 namespace net {
23 class HttpResponseHeaders;
23 class URLRequest; 24 class URLRequest;
25 class URLRequestStatus;
24 } // namespace net 26 } // namespace net
25 27
26 namespace content { 28 namespace content {
27 class DownloadManagerImpl; 29 class DownloadManagerImpl;
28 class ByteStreamReader; 30 class ByteStreamReader;
29 class ByteStreamWriter; 31 class ByteStreamWriter;
30 class PowerSaveBlocker; 32 class PowerSaveBlocker;
31 struct DownloadCreateInfo; 33 struct DownloadCreateInfo;
32 34
33 // This class encapsulates the core logic for reading data from a URLRequest and 35 // This class encapsulates the core logic for reading data from a URLRequest and
(...skipping 18 matching lines...) Expand all
52 scoped_ptr<DownloadSaveInfo> save_info, 54 scoped_ptr<DownloadSaveInfo> save_info,
53 const base::Closure& on_ready_to_read_callback); 55 const base::Closure& on_ready_to_read_callback);
54 ~DownloadRequestCore(); 56 ~DownloadRequestCore();
55 57
56 // Should be called when the URLRequest::Delegate receives OnResponseStarted. 58 // Should be called when the URLRequest::Delegate receives OnResponseStarted.
57 // Constructs a DownloadCreateInfo and a ByteStreamReader that should be 59 // Constructs a DownloadCreateInfo and a ByteStreamReader that should be
58 // passed into DownloadManagerImpl::StartDownload(). 60 // passed into DownloadManagerImpl::StartDownload().
59 // 61 //
60 // Only populates the response derived fields of DownloadCreateInfo, with the 62 // Only populates the response derived fields of DownloadCreateInfo, with the
61 // exception of |save_info|. 63 // exception of |save_info|.
62 void OnResponseStarted(scoped_ptr<DownloadCreateInfo>* info, 64 //
63 scoped_ptr<ByteStreamReader>* stream_reader); 65 // If the return value is not DOWNLOAD_INTERRUPT_REASON_NONE, then |info| and
66 // |stream_reader| will remain unchanged. In this case, the request isn't
67 // expected to continue.
68 DownloadInterruptReason OnResponseStarted(
69 scoped_ptr<DownloadCreateInfo>* info,
70 scoped_ptr<ByteStreamReader>* stream_reader) WARN_UNUSED_RESULT;
71
72 // Should be called to handle a redirect. The caller should only allow the
73 // redirect to be followed if the returned interrupt reason is NONE.
74 DownloadInterruptReason OnRequestRedirected(
75 const net::RedirectInfo& redirect_info);
64 76
65 // Starts a read cycle. Creates a new IOBuffer which can be passed into 77 // Starts a read cycle. Creates a new IOBuffer which can be passed into
66 // URLRequest::Read(). Call OnReadCompleted() when the Read operation 78 // URLRequest::Read(). Call OnReadCompleted() when the Read operation
67 // completes. 79 // completes.
68 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, 80 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf,
69 int* buf_size, 81 int* buf_size,
70 int min_size); 82 int min_size);
71 83
72 // Should be called when the Read() operation completes. |defer| will be set 84 // Should be called when the Read() operation completes. |defer| will be set
73 // to true if reading is to be suspended. In the latter case, once more data 85 // to true if reading is to be suspended. In the latter case, once more data
(...skipping 21 matching lines...) Expand all
95 // DownloadRequestCore will invoke the |on_ready_to_read_callback| to signal 107 // DownloadRequestCore will invoke the |on_ready_to_read_callback| to signal
96 // to the caller that the read cycles should commence. 108 // to the caller that the read cycles should commence.
97 void ResumeRequest(); 109 void ResumeRequest();
98 110
99 std::string DebugString() const; 111 std::string DebugString() const;
100 112
101 protected: 113 protected:
102 net::URLRequest* request() const { return request_; } 114 net::URLRequest* request() const { return request_; }
103 115
104 private: 116 private:
117 static DownloadInterruptReason HandleRequestStatus(
118 const net::URLRequestStatus& status);
119
120 static DownloadInterruptReason HandleSuccessfulServerResponse(
121 const net::HttpResponseHeaders& http_headers,
122 DownloadSaveInfo* save_info);
123
105 base::Closure on_ready_to_read_callback_; 124 base::Closure on_ready_to_read_callback_;
106 net::URLRequest* request_; 125 net::URLRequest* request_;
107 scoped_ptr<DownloadSaveInfo> save_info_; 126 scoped_ptr<DownloadSaveInfo> save_info_;
108 127
109 // Data flow 128 // Data flow
110 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. 129 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
111 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system. 130 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system.
112 131
113 // Keeps the system from sleeping while this is alive. If the 132 // Keeps the system from sleeping while this is alive. If the
114 // system enters power saving mode while a request is alive, it can cause the 133 // system enters power saving mode while a request is alive, it can cause the
115 // request to fail and the associated download will be interrupted. 134 // request to fail and the associated download will be interrupted.
116 scoped_ptr<PowerSaveBlocker> power_save_blocker_; 135 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
117 136
118 // The following are used to collect stats. 137 // The following are used to collect stats.
119 base::TimeTicks download_start_time_; 138 base::TimeTicks download_start_time_;
120 base::TimeTicks last_read_time_; 139 base::TimeTicks last_read_time_;
121 base::TimeTicks last_stream_pause_time_; 140 base::TimeTicks last_stream_pause_time_;
122 base::TimeDelta total_pause_time_; 141 base::TimeDelta total_pause_time_;
123 size_t last_buffer_size_; 142 size_t last_buffer_size_;
124 int64_t bytes_read_; 143 int64_t bytes_read_;
125 144
126 int pause_count_; 145 int pause_count_;
127 bool was_deferred_; 146 bool was_deferred_;
147 bool is_resumption_request_;
128 148
129 // Each successful OnWillRead will yield a buffer of this size. 149 // Each successful OnWillRead will yield a buffer of this size.
130 static const int kReadBufSize = 32768; // bytes 150 static const int kReadBufSize = 32768; // bytes
131 151
132 DISALLOW_COPY_AND_ASSIGN(DownloadRequestCore); 152 DISALLOW_COPY_AND_ASSIGN(DownloadRequestCore);
133 }; 153 };
134 154
135 } // namespace content 155 } // namespace content
136 156
137 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_ 157 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_CORE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698