blob: 9237cc52c8dc276592e6f2f39203291d77524fa5 [file] [log] [blame]
[email protected]e3c404b2008-12-23 01:07:321// Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_
6#define CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_
7
8#include <string>
9
10#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
11#include "chrome/browser/renderer_host/resource_handler.h"
12
13struct DownloadBuffer;
14
15// Forwards data to the download thread.
16class DownloadResourceHandler : public ResourceHandler {
17 public:
18 DownloadResourceHandler(ResourceDispatcherHost* rdh,
19 int render_process_host_id,
20 int render_view_id,
21 int request_id,
[email protected]f6b48532009-02-12 01:56:3222 const GURL& url,
[email protected]e3c404b2008-12-23 01:07:3223 DownloadFileManager* manager,
24 URLRequest* request,
25 bool save_as);
26
27 // Not needed, as this event handler ought to be the final resource.
[email protected]6568a9e32009-07-30 18:01:3928 bool OnRequestRedirected(int request_id, const GURL& url,
29 ResourceResponse* response, bool* defer);
[email protected]e3c404b2008-12-23 01:07:3230
31 // Send the download creation information to the download thread.
32 bool OnResponseStarted(int request_id, ResourceResponse* response);
33
34 // Create a new buffer, which will be handed to the download thread for file
35 // writing and deletion.
[email protected]9dea9e1f2009-01-29 00:30:4736 bool OnWillRead(int request_id, net::IOBuffer** buf, int* buf_size,
37 int min_size);
[email protected]e3c404b2008-12-23 01:07:3238
39 bool OnReadCompleted(int request_id, int* bytes_read);
40
[email protected]c4891b32009-03-08 07:41:3141 bool OnResponseCompleted(int request_id,
42 const URLRequestStatus& status,
43 const std::string& security_info);
[email protected]e3c404b2008-12-23 01:07:3244
45 // If the content-length header is not present (or contains something other
46 // than numbers), the incoming content_length is -1 (unknown size).
47 // Set the content length to 0 to indicate unknown size to DownloadManager.
48 void set_content_length(const int64& content_length);
49
50 void set_content_disposition(const std::string& content_disposition);
51
52 void CheckWriteProgress();
53
54 private:
[email protected]84bbb2b52009-11-07 00:23:1455 ~DownloadResourceHandler() {}
56
[email protected]e3c404b2008-12-23 01:07:3257 void StartPauseTimer();
58
59 int download_id_;
60 ResourceDispatcherHost::GlobalRequestID global_id_;
61 int render_view_id_;
[email protected]9dea9e1f2009-01-29 00:30:4762 scoped_refptr<net::IOBuffer> read_buffer_;
[email protected]e3c404b2008-12-23 01:07:3263 std::string content_disposition_;
[email protected]f6b48532009-02-12 01:56:3264 GURL url_;
[email protected]e3c404b2008-12-23 01:07:3265 int64 content_length_;
66 DownloadFileManager* download_manager_;
67 URLRequest* request_;
68 bool save_as_; // Request was initiated via "Save As" by the user.
69 DownloadBuffer* buffer_;
70 ResourceDispatcherHost* rdh_;
71 bool is_paused_;
72 base::OneShotTimer<DownloadResourceHandler> pause_timer_;
73
74 static const int kReadBufSize = 32768; // bytes
[email protected]3c2fe4e2009-01-08 12:07:2375 static const size_t kLoadsToWrite = 100; // number of data buffers queued
[email protected]e3c404b2008-12-23 01:07:3276 static const int kThrottleTimeMs = 200; // milliseconds
77
78 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler);
79};
80
81#endif // CHROME_BROWSER_RENDERER_HOST_DOWNLOAD_RESOURCE_HANDLER_H_