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

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

Issue 10392111: Use ByteStream in downloads system to decouple source and sink. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments and fixed tests. Created 8 years, 7 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/timer.h" 13 #include "base/timer.h"
14 #include "content/browser/renderer_host/resource_handler.h" 14 #include "content/browser/renderer_host/resource_handler.h"
15 #include "content/public/browser/download_id.h" 15 #include "content/public/browser/download_id.h"
16 #include "content/public/browser/download_manager.h" 16 #include "content/public/browser/download_manager.h"
17 #include "content/public/browser/download_save_info.h" 17 #include "content/public/browser/download_save_info.h"
18 #include "content/public/browser/download_url_parameters.h" 18 #include "content/public/browser/download_url_parameters.h"
19 #include "content/public/browser/global_request_id.h" 19 #include "content/public/browser/global_request_id.h"
20 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
21 21
22 class DownloadFileManager; 22 class DownloadFileManager;
23 class DownloadRequestHandle; 23 class DownloadRequestHandle;
24 struct DownloadCreateInfo; 24 struct DownloadCreateInfo;
25 25
26 namespace content { 26 namespace content {
27 class DownloadBuffer; 27 class ByteStreamInput;
28 class ByteStreamOutput;
28 } 29 }
29 30
30 namespace net { 31 namespace net {
31 class URLRequest; 32 class URLRequest;
32 } // namespace net 33 } // namespace net
33 34
34 // Forwards data to the download thread. 35 // Forwards data to the download thread.
35 class DownloadResourceHandler : public ResourceHandler { 36 class DownloadResourceHandler : public ResourceHandler {
36 public: 37 public:
37 typedef content::DownloadUrlParameters::OnStartedCallback OnStartedCallback; 38 typedef content::DownloadUrlParameters::OnStartedCallback OnStartedCallback;
38 39
39 static const size_t kLoadsToWrite = 100; // number of data buffers queued
40
41 // started_cb will be called exactly once on the UI thread. 40 // started_cb will be called exactly once on the UI thread.
42 DownloadResourceHandler(int render_process_host_id, 41 DownloadResourceHandler(int render_process_host_id,
43 int render_view_id, 42 int render_view_id,
44 int request_id, 43 int request_id,
45 const GURL& url, 44 const GURL& url,
46 DownloadFileManager* download_file_manager, 45 DownloadFileManager* download_file_manager,
47 net::URLRequest* request, 46 net::URLRequest* request,
48 const OnStartedCallback& started_cb, 47 const OnStartedCallback& started_cb,
49 const content::DownloadSaveInfo& save_info); 48 const content::DownloadSaveInfo& save_info);
50 49
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 84
86 void PauseRequest(); 85 void PauseRequest();
87 void ResumeRequest(); 86 void ResumeRequest();
88 void CancelRequest(); 87 void CancelRequest();
89 88
90 std::string DebugString() const; 89 std::string DebugString() const;
91 90
92 private: 91 private:
93 virtual ~DownloadResourceHandler(); 92 virtual ~DownloadResourceHandler();
94 93
95 void OnResponseCompletedInternal(int request_id, 94 // Arrange for started_cb_ to be called on the UI thread with the
96 const net::URLRequestStatus& status, 95 // below values, nulling out started_cb_. Should only be called
97 const std::string& security_info, 96 // on the IO thread.
98 int response_code);
99
100 void CheckWriteProgressLater();
101 void CheckWriteProgress();
102 void MaybeResumeRequest();
103 void CallStartedCB(content::DownloadId id, net::Error error); 97 void CallStartedCB(content::DownloadId id, net::Error error);
104 98
105 // Generates a DownloadId and calls DownloadFileManager.
106 void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info,
107 const DownloadRequestHandle& handle);
108 void SetDownloadID(content::DownloadId id);
109
110 // If the content-length header is not present (or contains something other 99 // If the content-length header is not present (or contains something other
111 // than numbers), the incoming content_length is -1 (unknown size). 100 // than numbers), the incoming content_length is -1 (unknown size).
112 // Set the content length to 0 to indicate unknown size to DownloadManager. 101 // Set the content length to 0 to indicate unknown size to DownloadManager.
113 void SetContentLength(const int64& content_length); 102 void SetContentLength(const int64& content_length);
114 103
115 void SetContentDisposition(const std::string& content_disposition); 104 void SetContentDisposition(const std::string& content_disposition);
116 105
117 content::DownloadId download_id_;
118 content::GlobalRequestID global_id_; 106 content::GlobalRequestID global_id_;
119 int render_view_id_; 107 int render_view_id_;
120 scoped_refptr<net::IOBuffer> read_buffer_;
121 std::string content_disposition_; 108 std::string content_disposition_;
122 int64 content_length_; 109 int64 content_length_;
123 DownloadFileManager* download_file_manager_; 110 DownloadFileManager* download_file_manager_;
124 net::URLRequest* request_; 111 net::URLRequest* request_;
125 // This is used only on the UI thread. 112 // This is read only on the IO thread, but may only
113 // be called on the UI thread.
126 OnStartedCallback started_cb_; 114 OnStartedCallback started_cb_;
127 content::DownloadSaveInfo save_info_; 115 content::DownloadSaveInfo save_info_;
128 scoped_refptr<content::DownloadBuffer> buffer_; 116
129 base::OneShotTimer<DownloadResourceHandler> check_write_progress_timer_; 117 // Data flow
118 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
119 scoped_ptr<content::ByteStreamInput> stream_writer_; // To rest of system.
130 120
131 // The following are used to collect stats. 121 // The following are used to collect stats.
132 base::TimeTicks download_start_time_; 122 base::TimeTicks download_start_time_;
133 base::TimeTicks last_read_time_; 123 base::TimeTicks last_read_time_;
124 base::TimeTicks last_pipe_pause_time_;
125 base::TimeDelta total_pause_time_;
134 size_t last_buffer_size_; 126 size_t last_buffer_size_;
135 int64 bytes_read_; 127 int64 bytes_read_;
136 std::string accept_ranges_; 128 std::string accept_ranges_;
137 129
138 int pause_count_; 130 int pause_count_;
139 bool was_deferred_; 131 bool was_deferred_;
140 132
133 // For DCHECKing
134 bool on_response_started_called_;
135
141 static const int kReadBufSize = 32768; // bytes 136 static const int kReadBufSize = 32768; // bytes
142 static const int kThrottleTimeMs = 200; // milliseconds 137 static const int kThrottleTimeMs = 200; // milliseconds
143 138
144 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); 139 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
145 }; 140 };
146 141
147 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 142 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698