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

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

Issue 10074001: Initial implementation of the ByteStream refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 DataLoanIOBuffer;
21 class DownloadFileManager; 22 class DownloadFileManager;
22 class DownloadRequestHandle; 23 class DownloadRequestHandle;
23 struct DownloadCreateInfo; 24 struct DownloadCreateInfo;
24 25
25 namespace content { 26 namespace content {
26 class DownloadBuffer; 27 class ByteStream;
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,
107 const DownloadRequestHandle& handle); 103 const DownloadRequestHandle& handle);
108 void set_download_id(content::DownloadId id); 104 void set_download_id(content::DownloadId id);
109 105
106 // Pause or resume the associated request as indicated by the output_pipe_.
107 void ThrottleRequest();
108
110 content::DownloadId download_id_; 109 content::DownloadId download_id_;
111 content::GlobalRequestID global_id_; 110 content::GlobalRequestID global_id_;
112 int render_view_id_; 111 int render_view_id_;
113 scoped_refptr<net::IOBuffer> read_buffer_;
114 std::string content_disposition_; 112 std::string content_disposition_;
115 int64 content_length_; 113 int64 content_length_;
116 DownloadFileManager* download_file_manager_; 114 DownloadFileManager* download_file_manager_;
117 net::URLRequest* request_; 115 net::URLRequest* request_;
118 // This is used only on the UI thread. 116 // This is used only on the UI thread.
119 OnStartedCallback started_cb_; 117 OnStartedCallback started_cb_;
120 content::DownloadSaveInfo save_info_; 118 content::DownloadSaveInfo save_info_;
121 scoped_refptr<content::DownloadBuffer> buffer_; 119 base::OneShotTimer<DownloadResourceHandler> pause_timer_;
120
121 // Data flow
122 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
123 scoped_refptr<content::ByteStream> output_pipe_; // To rest of system.
122 bool is_paused_; 124 bool is_paused_;
123 base::OneShotTimer<DownloadResourceHandler> pause_timer_;
124 125
125 // The following are used to collect stats. 126 // The following are used to collect stats.
126 base::TimeTicks download_start_time_; 127 base::TimeTicks download_start_time_;
127 base::TimeTicks last_read_time_; 128 base::TimeTicks last_read_time_;
128 size_t last_buffer_size_; 129 size_t last_buffer_size_;
129 int64 bytes_read_; 130 int64 bytes_read_;
130 std::string accept_ranges_; 131 std::string accept_ranges_;
131 132
133 base::WeakPtrFactory<DownloadResourceHandler> weak_factory_;
134
132 static const int kReadBufSize = 32768; // bytes 135 static const int kReadBufSize = 32768; // bytes
133 static const int kThrottleTimeMs = 200; // milliseconds 136 static const int kThrottleTimeMs = 200; // milliseconds
134 137
135 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); 138 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
136 }; 139 };
137 140
138 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 141 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698