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:
32 bool OnUploadProgress(uint64 position
, uint64 size
) override
;
34 // Saves the redirected URL to final_url_, we need to use the original
35 // URL to match original request.
36 bool OnRequestRedirected(const net::RedirectInfo
& redirect_info
,
37 ResourceResponse
* response
,
38 bool* defer
) override
;
40 // Sends the download creation information to the download thread.
41 bool OnResponseStarted(ResourceResponse
* response
, bool* defer
) override
;
43 // Pass-through implementation.
44 bool OnWillStart(const GURL
& url
, bool* defer
) override
;
46 // Pass-through implementation.
47 bool OnBeforeNetworkStart(const GURL
& url
, bool* defer
) override
;
49 // Creates a new buffer, which will be handed to the download thread for file
50 // writing and deletion.
51 bool OnWillRead(scoped_refptr
<net::IOBuffer
>* buf
,
53 int min_size
) override
;
55 // Passes the buffer to the download file writer.
56 bool OnReadCompleted(int bytes_read
, bool* defer
) override
;
58 void OnResponseCompleted(const net::URLRequestStatus
& status
,
59 const std::string
& security_info
,
60 bool* defer
) override
;
62 // N/A to this flavor of SaveFileResourceHandler.
63 void OnDataDownloaded(int bytes_downloaded
) override
;
65 // If the content-length header is not present (or contains something other
66 // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and
67 // is handled correctly by the SaveManager.
68 void set_content_length(const std::string
& content_length
);
70 void set_content_disposition(const std::string
& content_disposition
) {
71 content_disposition_
= content_disposition
;
76 int render_process_id_
;
78 scoped_refptr
<net::IOBuffer
> read_buffer_
;
79 std::string content_disposition_
;
82 int64 content_length_
;
83 SaveFileManager
* save_manager_
;
85 static const int kReadBufSize
= 32768; // bytes
87 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler
);
90 } // namespace content
92 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_