Index: content/browser/download/download_request_model.h |
diff --git a/content/browser/download/download_request_model.h b/content/browser/download/download_request_model.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..305d7d7b64f57b632f0805b5938ced2a72915d3c |
--- /dev/null |
+++ b/content/browser/download/download_request_model.h |
@@ -0,0 +1,107 @@ |
+// Copyright 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MODEL_H_ |
+#define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_MODEL_H_ |
+ |
+#include "base/callback_forward.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/weak_ptr.h" |
+#include "base/timer/timer.h" |
+#include "content/public/browser/download_interrupt_reasons.h" |
+#include "content/public/browser/download_save_info.h" |
+#include "content/public/common/page_transition_types.h" |
+#include "net/url_request/url_request.h" |
+ |
+class GURL; |
+ |
+namespace net { |
+class IOBuffer; |
+class URLRequestStatus; |
+} |
+ |
+namespace content { |
+ |
+class ByteStreamWriter; |
+struct DownloadCreateInfo; |
+struct DownloadSaveInfo; |
+class DownloadUrlParameters; |
+ |
+class DownloadRequestModel { |
+ public: |
+ enum ReadState { |
+ READY_TO_READ, |
+ WAIT_FOR_RESUME |
+ }; |
+ |
+ // Size of the buffer used between the DownloadResourceHandler and the |
+ // downstream receiver of its output. |
+ static const int kDownloadByteStreamSize; |
+ |
+ typedef base::Closure ResumeRequestCallback; |
+ |
+ DownloadRequestModel(net::URLRequest* request, |
+ scoped_ptr<DownloadSaveInfo> save_info); |
+ ~DownloadRequestModel(); |
+ |
+ static scoped_ptr<net::URLRequest> CreateRequest( |
+ const DownloadUrlParameters& parameters, |
+ net::URLRequest::Delegate* delegate); |
+ |
+ static bool IsRequestAllowed(const GURL& url, int child_process_id); |
+ |
+ // Assumes that the request is allowed. |
+ void OnRequestRedirected(const GURL& url); |
+ |
+ // The response data for the request is available. Returns a |
+ // DownloadCreateInfo which can be used to construct a DownloadItem. |
+ // |resume_callback| is invoked when the internal ByteStream is ready to |
+ // accept more data. See OnReadCompleted. |resume_callback| is guaranteed to |
+ // not be invoked after DownloadRequestModel has been deleted. |
+ scoped_ptr<DownloadCreateInfo> OnResponseStarted( |
+ const std::string& sniffed_mime_type, |
+ bool has_user_gesture, |
+ PageTransition page_transition, |
+ const ResumeRequestCallback& resume_callback); |
+ |
+ void OnWillRead(net::IOBuffer** buf, int* buf_size, int min_size); |
+ ReadState OnReadCompleted(int bytes_read); |
+ DownloadInterruptReason OnResponseCompleted(); |
+ void OnPauseRequest(); |
+ ReadState OnResumeRequest(); |
+ void OnDownloadInterrupted(DownloadInterruptReason reason); |
+ |
+ std::string DebugString() const; |
+ |
+ net::URLRequest* request() { return request_; } |
+ |
+ private: |
+ ReadState read_state() const; |
+ |
+ net::URLRequest* request_; |
+ |
+ scoped_ptr<DownloadSaveInfo> save_info_; |
+ |
+ // Data flow |
+ scoped_refptr<net::IOBuffer> read_buffer_; // From URLRequest. |
+ scoped_ptr<ByteStreamWriter> stream_writer_; // To rest of system. |
+ |
+ // The following are used to collect stats. |
+ base::TimeTicks download_start_time_; |
+ base::TimeTicks last_read_time_; |
+ base::TimeTicks last_stream_pause_time_; |
+ base::TimeDelta total_pause_time_; |
+ size_t last_buffer_size_; |
+ int64 bytes_read_; |
+ |
+ int pause_count_; |
+ DownloadInterruptReason last_interrupt_reason_; |
+ |
+ static const int kReadBufSize = 32768; // bytes |
+ static const int kThrottleTimeMs = 200; // milliseconds |
+}; |
+ |
+} // namespace content |
+ |
+#endif |