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

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

Issue 23496076: WIP - Refactor programmatic downloads Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h"
12 #include "base/timer/timer.h" 13 #include "base/timer/timer.h"
14 #include "content/browser/download/download_request_model.h"
13 #include "content/browser/loader/resource_handler.h" 15 #include "content/browser/loader/resource_handler.h"
14 #include "content/public/browser/download_manager.h" 16 #include "content/public/browser/download_manager.h"
15 #include "content/public/browser/download_save_info.h" 17 #include "content/public/browser/download_save_info.h"
16 #include "content/public/browser/download_url_parameters.h" 18 #include "content/public/browser/download_url_parameters.h"
17 #include "content/public/browser/global_request_id.h" 19 #include "content/public/browser/global_request_id.h"
18 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
19 21
20
21 namespace net { 22 namespace net {
22 class URLRequest; 23 class URLRequest;
23 } // namespace net 24 } // namespace net
24 25
25 namespace content { 26 namespace content {
26 class ByteStreamWriter; 27 class ByteStreamWriter;
27 class ByteStreamReader; 28 class ByteStreamReader;
28 class DownloadRequestHandle; 29 class DownloadRequestHandle;
29 struct DownloadCreateInfo; 30 struct DownloadCreateInfo;
30 31
31 // Forwards data to the download thread. 32 // Forwards data to the download thread.
32 class CONTENT_EXPORT DownloadResourceHandler 33 class CONTENT_EXPORT DownloadResourceHandler
33 : public ResourceHandler, 34 : public ResourceHandler,
34 public base::SupportsWeakPtr<DownloadResourceHandler> { 35 public base::SupportsWeakPtr<DownloadResourceHandler> {
35 public: 36 public:
36 // Size of the buffer used between the DownloadResourceHandler and the 37 explicit DownloadResourceHandler(net::URLRequest* request);
37 // downstream receiver of its output.
38 static const int kDownloadByteStreamSize;
39
40 // started_cb will be called exactly once on the UI thread.
41 // |id| should be invalid if the id should be automatically assigned.
42 DownloadResourceHandler(
43 uint32 id,
44 net::URLRequest* request,
45 const DownloadUrlParameters::OnStartedCallback& started_cb,
46 scoped_ptr<DownloadSaveInfo> save_info);
47 38
48 virtual bool OnUploadProgress(int request_id, 39 virtual bool OnUploadProgress(int request_id,
49 uint64 position, 40 uint64 position,
50 uint64 size) OVERRIDE; 41 uint64 size) OVERRIDE;
51 42
52 virtual bool OnRequestRedirected(int request_id, 43 virtual bool OnRequestRedirected(int request_id,
53 const GURL& url, 44 const GURL& url,
54 ResourceResponse* response, 45 ResourceResponse* response,
55 bool* defer) OVERRIDE; 46 bool* defer) OVERRIDE;
56 47
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 std::string DebugString() const; 79 std::string DebugString() const;
89 80
90 private: 81 private:
91 virtual ~DownloadResourceHandler(); 82 virtual ~DownloadResourceHandler();
92 83
93 // Arrange for started_cb_ to be called on the UI thread with the 84 // Arrange for started_cb_ to be called on the UI thread with the
94 // below values, nulling out started_cb_. Should only be called 85 // below values, nulling out started_cb_. Should only be called
95 // on the IO thread. 86 // on the IO thread.
96 void CallStartedCB(DownloadItem* item, net::Error error); 87 void CallStartedCB(DownloadItem* item, net::Error error);
97 88
98 // If the content-length header is not present (or contains something other 89 DownloadRequestModel request_model_;
99 // than numbers), the incoming content_length is -1 (unknown size).
100 // Set the content length to 0 to indicate unknown size to DownloadManager.
101 void SetContentLength(const int64& content_length);
102 90
103 void SetContentDisposition(const std::string& content_disposition);
104
105 uint32 download_id_;
106 GlobalRequestID global_id_; 91 GlobalRequestID global_id_;
107 int render_view_id_; 92 int render_view_id_;
108 std::string content_disposition_; 93 bool did_defer_request_;
109 int64 content_length_;
110 net::URLRequest* request_;
111 // This is read only on the IO thread, but may only
112 // be called on the UI thread.
113 DownloadUrlParameters::OnStartedCallback started_cb_;
114 scoped_ptr<DownloadSaveInfo> save_info_;
115
116 // Data flow
117 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
118 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system.
119
120 // The following are used to collect stats.
121 base::TimeTicks download_start_time_;
122 base::TimeTicks last_read_time_;
123 base::TimeTicks last_stream_pause_time_;
124 base::TimeDelta total_pause_time_;
125 size_t last_buffer_size_;
126 int64 bytes_read_;
127 std::string accept_ranges_;
128 std::string etag_;
129
130 int pause_count_;
131 bool was_deferred_;
132 94
133 // For DCHECKing 95 // For DCHECKing
134 bool on_response_started_called_; 96 bool on_response_started_called_;
135 97
136 static const int kReadBufSize = 32768; // bytes
137 static const int kThrottleTimeMs = 200; // milliseconds
138
139 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); 98 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
140 }; 99 };
141 100
142 } // namespace content 101 } // namespace content
143 102
144 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 103 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_request_model.cc ('k') | content/browser/download/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698