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

Side by Side Diff: content/browser/download/download_request_model.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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MODEL_H_
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MODEL_H_
7
8 #include "base/callback_forward.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/timer/timer.h"
12 #include "content/public/browser/download_interrupt_reasons.h"
13 #include "content/public/browser/download_save_info.h"
14 #include "content/public/common/page_transition_types.h"
15 #include "net/url_request/url_request.h"
16
17 class GURL;
18
19 namespace net {
20 class IOBuffer;
21 class URLRequestStatus;
22 }
23
24 namespace content {
25
26 class ByteStreamWriter;
27 struct DownloadCreateInfo;
28 struct DownloadSaveInfo;
29 class DownloadUrlParameters;
30
31 class DownloadRequestModel {
32 public:
33 enum ReadState {
34 READY_TO_READ,
35 WAIT_FOR_RESUME
36 };
37
38 // Size of the buffer used between the DownloadResourceHandler and the
39 // downstream receiver of its output.
40 static const int kDownloadByteStreamSize;
41
42 typedef base::Closure ResumeRequestCallback;
43
44 DownloadRequestModel(net::URLRequest* request,
45 scoped_ptr<DownloadSaveInfo> save_info);
46 ~DownloadRequestModel();
47
48 static scoped_ptr<net::URLRequest> CreateRequest(
49 const DownloadUrlParameters& parameters,
50 net::URLRequest::Delegate* delegate);
51
52 static bool IsRequestAllowed(const GURL& url, int child_process_id);
53
54 // Assumes that the request is allowed.
55 void OnRequestRedirected(const GURL& url);
56
57 // The response data for the request is available. Returns a
58 // DownloadCreateInfo which can be used to construct a DownloadItem.
59 // |resume_callback| is invoked when the internal ByteStream is ready to
60 // accept more data. See OnReadCompleted. |resume_callback| is guaranteed to
61 // not be invoked after DownloadRequestModel has been deleted.
62 scoped_ptr<DownloadCreateInfo> OnResponseStarted(
63 const std::string& sniffed_mime_type,
64 bool has_user_gesture,
65 PageTransition page_transition,
66 const ResumeRequestCallback& resume_callback);
67
68 void OnWillRead(net::IOBuffer** buf, int* buf_size, int min_size);
69 ReadState OnReadCompleted(int bytes_read);
70 DownloadInterruptReason OnResponseCompleted();
71 void OnPauseRequest();
72 ReadState OnResumeRequest();
73 void OnDownloadInterrupted(DownloadInterruptReason reason);
74
75 std::string DebugString() const;
76
77 net::URLRequest* request() { return request_; }
78
79 private:
80 ReadState read_state() const;
81
82 net::URLRequest* request_;
83
84 scoped_ptr<DownloadSaveInfo> save_info_;
85
86 // Data flow
87 scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest.
88 scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system.
89
90 // The following are used to collect stats.
91 base::TimeTicks download_start_time_;
92 base::TimeTicks last_read_time_;
93 base::TimeTicks last_stream_pause_time_;
94 base::TimeDelta total_pause_time_;
95 size_t last_buffer_size_;
96 int64 bytes_read_;
97
98 int pause_count_;
99 DownloadInterruptReason last_interrupt_reason_;
100
101 static const int kReadBufSize = 32768; // bytes
102 static const int kThrottleTimeMs = 200; // milliseconds
103 };
104
105 } // namespace content
106
107 #endif
OLDNEW
« no previous file with comments | « content/browser/download/download_request_handle.cc ('k') | content/browser/download/download_request_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698