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

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

Issue 1533583002: [Downloads] Factor out request handling logic between DRH and UD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and change .Pass() -> std::move(...) per PRESUBMIT check Created 5 years 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_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 "content/browser/download/download_request_core.h"
12 #include "content/browser/loader/resource_handler.h" 13 #include "content/browser/loader/resource_handler.h"
13 #include "content/public/browser/download_interrupt_reasons.h" 14 #include "content/public/browser/download_interrupt_reasons.h"
14 #include "content/public/browser/download_manager.h" 15 #include "content/public/browser/download_manager.h"
15 #include "content/public/browser/download_save_info.h" 16 #include "content/public/browser/download_save_info.h"
16 #include "content/public/browser/download_url_parameters.h" 17 #include "content/public/browser/download_url_parameters.h"
17 18
18 namespace net { 19 namespace net {
19 class URLRequest; 20 class URLRequest;
20 } // namespace net 21 } // namespace net
21 22
22 namespace content { 23 namespace content {
23 class ByteStreamReader; 24 class ByteStreamReader;
24 class ByteStreamWriter; 25 class ByteStreamWriter;
25 class DownloadRequestHandle; 26 class DownloadRequestHandle;
26 class PowerSaveBlocker; 27 class PowerSaveBlocker;
27 struct DownloadCreateInfo; 28 struct DownloadCreateInfo;
28 29
29 // Forwards data to the download thread. 30 // Forwards data to the download thread.
30 class CONTENT_EXPORT DownloadResourceHandler 31 class CONTENT_EXPORT DownloadResourceHandler
31 : public ResourceHandler, 32 : public ResourceHandler,
32 public base::SupportsWeakPtr<DownloadResourceHandler> { 33 public base::SupportsWeakPtr<DownloadResourceHandler> {
33 public: 34 public:
34 struct DownloadTabInfo; 35 struct DownloadTabInfo;
35 36
36 // Size of the buffer used between the DownloadResourceHandler and the
37 // downstream receiver of its output.
38 static const int kDownloadByteStreamSize;
39
40 // started_cb will be called exactly once on the UI thread. 37 // started_cb will be called exactly once on the UI thread.
41 // |id| should be invalid if the id should be automatically assigned. 38 // |id| should be invalid if the id should be automatically assigned.
42 DownloadResourceHandler( 39 DownloadResourceHandler(
43 uint32 id, 40 uint32 id,
44 net::URLRequest* request, 41 net::URLRequest* request,
45 const DownloadUrlParameters::OnStartedCallback& started_cb, 42 const DownloadUrlParameters::OnStartedCallback& started_cb,
46 scoped_ptr<DownloadSaveInfo> save_info); 43 scoped_ptr<DownloadSaveInfo> save_info);
47 44
48 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, 45 bool OnRequestRedirected(const net::RedirectInfo& redirect_info,
49 ResourceResponse* response, 46 ResourceResponse* response,
(...skipping 30 matching lines...) Expand all
80 void CancelRequest(); 77 void CancelRequest();
81 78
82 std::string DebugString() const; 79 std::string DebugString() const;
83 80
84 private: 81 private:
85 ~DownloadResourceHandler() override; 82 ~DownloadResourceHandler() override;
86 83
87 // 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
88 // below values, nulling out started_cb_. Should only be called 85 // below values, nulling out started_cb_. Should only be called
89 // on the IO thread. 86 // on the IO thread.
90 void CallStartedCB(DownloadItem* item, 87 void CallStartedCB(DownloadInterruptReason interrupt_reason);
91 DownloadInterruptReason interrupt_reason); 88
89 void OnCoreReadyToRead();
92 90
93 uint32 download_id_; 91 uint32 download_id_;
92
94 // This is read only on the IO thread, but may only 93 // This is read only on the IO thread, but may only
95 // be called on the UI thread. 94 // be called on the UI thread.
96 DownloadUrlParameters::OnStartedCallback started_cb_; 95 DownloadUrlParameters::OnStartedCallback started_cb_;
97 scoped_ptr<DownloadSaveInfo> save_info_;
98 96
99 // Stores information about the download that must be acquired on the UI 97 // Stores information about the download that must be acquired on the UI
100 // thread before StartOnUIThread is called. 98 // thread before StartOnUIThread is called.
101 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds 99 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds
102 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. 100 // the pointer until we pass it off to StartOnUIThread or DeleteSoon.
103 // Marked as a scoped_ptr<> to indicate ownership of the structure, but 101 // Marked as a scoped_ptr<> to indicate ownership of the structure, but
104 // deletion must occur on the IO thread. 102 // deletion must occur on the IO thread.
105 scoped_ptr<DownloadTabInfo> tab_info_; 103 scoped_ptr<DownloadTabInfo> tab_info_;
106 104
107 // Data flow 105 DownloadRequestCore core_;
108 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
109 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system.
110
111 // Keeps the system from sleeping while this ResourceHandler is alive. If the
112 // system enters power saving mode while a request is alive, it can cause the
113 // request to fail and the associated download will be interrupted.
114 scoped_ptr<PowerSaveBlocker> power_save_blocker_;
115
116 // The following are used to collect stats.
117 base::TimeTicks download_start_time_;
118 base::TimeTicks last_read_time_;
119 base::TimeTicks last_stream_pause_time_;
120 base::TimeDelta total_pause_time_;
121 size_t last_buffer_size_;
122 int64 bytes_read_;
123
124 int pause_count_;
125 bool was_deferred_;
126
127 // For DCHECKing
128 bool on_response_started_called_;
129
130 static const int kReadBufSize = 32768; // bytes
131 static const int kThrottleTimeMs = 200; // milliseconds
132
133 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); 106 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
134 }; 107 };
135 108
136 } // namespace content 109 } // namespace content
137 110
138 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ 111 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_request_handle.cc ('k') | content/browser/download/download_resource_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698