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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_
6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_
10 #include "base/memory/ref_counted.h"
11 #include "content/browser/loader/resource_handler.h"
19 class SaveFileManager
;
21 // Forwards data to the save thread.
22 class SaveFileResourceHandler
: public ResourceHandler
{
24 SaveFileResourceHandler(net::URLRequest
* request
,
25 int render_process_host_id
,
28 SaveFileManager
* manager
);
29 ~SaveFileResourceHandler() override
;
31 // ResourceHandler Implementation:
33 // Saves the redirected URL to final_url_, we need to use the original
34 // URL to match original request.
35 bool OnRequestRedirected(const net::RedirectInfo
& redirect_info
,
36 ResourceResponse
* response
,
37 bool* defer
) override
;
39 // Sends the download creation information to the download thread.
40 bool OnResponseStarted(ResourceResponse
* response
, bool* defer
) override
;
42 // Pass-through implementation.
43 bool OnWillStart(const GURL
& url
, bool* defer
) override
;
45 // Pass-through implementation.
46 bool OnBeforeNetworkStart(const GURL
& url
, bool* defer
) override
;
48 // Creates a new buffer, which will be handed to the download thread for file
49 // writing and deletion.
50 bool OnWillRead(scoped_refptr
<net::IOBuffer
>* buf
,
52 int min_size
) override
;
54 // Passes the buffer to the download file writer.
55 bool OnReadCompleted(int bytes_read
, bool* defer
) override
;
57 void OnResponseCompleted(const net::URLRequestStatus
& status
,
58 const std::string
& security_info
,
59 bool* defer
) override
;
61 // N/A to this flavor of SaveFileResourceHandler.
62 void OnDataDownloaded(int bytes_downloaded
) override
;
64 // If the content-length header is not present (or contains something other
65 // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and
66 // is handled correctly by the SaveManager.
67 void set_content_length(const std::string
& content_length
);
69 void set_content_disposition(const std::string
& content_disposition
) {
70 content_disposition_
= content_disposition
;
75 int render_process_id_
;
77 scoped_refptr
<net::IOBuffer
> read_buffer_
;
78 std::string content_disposition_
;
81 int64 content_length_
;
82 SaveFileManager
* save_manager_
;
84 static const int kReadBufSize
= 32768; // bytes
86 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler
);
89 } // namespace content
91 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_