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

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: Added some histogram statistics. 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_manager.h" 15 #include "content/public/browser/download_manager.h"
16 #include "content/public/browser/download_id.h" 16 #include "content/public/browser/download_id.h"
17 #include "content/public/browser/download_save_info.h" 17 #include "content/public/browser/download_save_info.h"
18 #include "content/public/browser/global_request_id.h" 18 #include "content/public/browser/global_request_id.h"
19 #include "net/base/net_errors.h" 19 #include "net/base/net_errors.h"
20 20
21 class DownloadFileManager; 21 class DownloadFileManager;
22 class DownloadRequestHandle; 22 class DownloadRequestHandle;
23 struct DownloadCreateInfo; 23 struct DownloadCreateInfo;
24 24
25 namespace content { 25 namespace content {
26 class DownloadBuffer; 26 class ByteStreamInput;
27 class ByteStreamOutput;
27 } 28 }
28 29
29 namespace net { 30 namespace net {
30 class URLRequest; 31 class URLRequest;
31 } // namespace net 32 } // namespace net
32 33
33 // Forwards data to the download thread. 34 // Forwards data to the download thread.
34 class DownloadResourceHandler : public ResourceHandler { 35 class DownloadResourceHandler : public ResourceHandler {
35 public: 36 public:
36 typedef content::DownloadManager::OnStartedCallback OnStartedCallback; 37 typedef content::DownloadManager::OnStartedCallback OnStartedCallback;
37 38
38 static const size_t kLoadsToWrite = 100; // number of data buffers queued
39
40 // started_cb will be called exactly once on the UI thread. 39 // started_cb will be called exactly once on the UI thread.
41 DownloadResourceHandler(int render_process_host_id, 40 DownloadResourceHandler(int render_process_host_id,
42 int render_view_id, 41 int render_view_id,
43 int request_id, 42 int request_id,
44 const GURL& url, 43 const GURL& url,
45 DownloadFileManager* download_file_manager, 44 DownloadFileManager* download_file_manager,
46 net::URLRequest* request, 45 net::URLRequest* request,
47 const OnStartedCallback& started_cb, 46 const OnStartedCallback& started_cb,
48 const content::DownloadSaveInfo& save_info); 47 const content::DownloadSaveInfo& save_info);
49 48
(...skipping 30 matching lines...) Expand all
80 const std::string& security_info) OVERRIDE; 79 const std::string& security_info) OVERRIDE;
81 virtual void OnRequestClosed() OVERRIDE; 80 virtual void OnRequestClosed() OVERRIDE;
82 81
83 // If the content-length header is not present (or contains something other 82 // If the content-length header is not present (or contains something other
84 // than numbers), the incoming content_length is -1 (unknown size). 83 // than numbers), the incoming content_length is -1 (unknown size).
85 // Set the content length to 0 to indicate unknown size to DownloadManager. 84 // Set the content length to 0 to indicate unknown size to DownloadManager.
86 void set_content_length(const int64& content_length); 85 void set_content_length(const int64& content_length);
87 86
88 void set_content_disposition(const std::string& content_disposition); 87 void set_content_disposition(const std::string& content_disposition);
89 88
90 void CheckWriteProgress();
91
92 std::string DebugString() const; 89 std::string DebugString() const;
93 90
94 private: 91 private:
95 virtual ~DownloadResourceHandler(); 92 virtual ~DownloadResourceHandler();
96 93
97 void OnResponseCompletedInternal(int request_id, 94 void OnResponseCompletedInternal(int request_id,
98 const net::URLRequestStatus& status, 95 const net::URLRequestStatus& status,
99 const std::string& security_info, 96 const std::string& security_info,
100 int response_code); 97 int response_code);
101 98
102 void StartPauseTimer();
103 void CallStartedCB(content::DownloadId id, net::Error error); 99 void CallStartedCB(content::DownloadId id, net::Error error);
104 100
105 // Generates a DownloadId and calls DownloadFileManager. 101 // Generates a DownloadId and calls DownloadFileManager.
106 void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info, 102 void StartOnUIThread(scoped_ptr<DownloadCreateInfo> info,
103 scoped_ptr<content::ByteStreamOutput> pipe,
107 const DownloadRequestHandle& handle); 104 const DownloadRequestHandle& handle);
108 void set_download_id(content::DownloadId id); 105 void set_download_id(content::DownloadId id);
109 106
107 // Resume requests paused in OnReadCompleted()
108 void ResumeRequest();
109
110 content::DownloadId download_id_; 110 content::DownloadId download_id_;
111 content::GlobalRequestID global_id_; 111 content::GlobalRequestID global_id_;
112 int render_view_id_; 112 int render_view_id_;
113 scoped_refptr<net::IOBuffer> read_buffer_;
114 std::string content_disposition_; 113 std::string content_disposition_;
115 int64 content_length_; 114 int64 content_length_;
116 DownloadFileManager* download_file_manager_; 115 DownloadFileManager* download_file_manager_;
117 net::URLRequest* request_; 116 net::URLRequest* request_;
118 // This is used only on the UI thread. 117 // This is used only on the UI thread.
119 OnStartedCallback started_cb_; 118 OnStartedCallback started_cb_;
120 content::DownloadSaveInfo save_info_; 119 content::DownloadSaveInfo save_info_;
121 scoped_refptr<content::DownloadBuffer> buffer_; 120
122 bool is_paused_; 121 // Data flow
123 base::OneShotTimer<DownloadResourceHandler> pause_timer_; 122 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
123 scoped_ptr<content::ByteStreamInput> pipe_input_; // To rest of system.
124 124
125 // The following are used to collect stats. 125 // The following are used to collect stats.
126 base::TimeTicks download_start_time_; 126 base::TimeTicks download_start_time_;
127 base::TimeTicks last_read_time_; 127 base::TimeTicks last_read_time_;
128 base::TimeTicks last_pause_time_;
129 base::TimeDelta total_pause_time_;
128 size_t last_buffer_size_; 130 size_t last_buffer_size_;
129 int64 bytes_read_; 131 int64 bytes_read_;
130 std::string accept_ranges_; 132 std::string accept_ranges_;
131 133
132 static const int kReadBufSize = 32768; // bytes 134 static const int kReadBufSize = 32768; // bytes
133 static const int kThrottleTimeMs = 200; // milliseconds 135 static const int kThrottleTimeMs = 200; // milliseconds
134 136
135 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); 137 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
136 }; 138 };
137 139
138 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698