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"
15 class SaveFileManager
;
17 // Forwards data to the save thread.
18 class SaveFileResourceHandler
: public ResourceHandler
{
20 SaveFileResourceHandler(int render_process_host_id
,
23 SaveFileManager
* manager
);
24 virtual ~SaveFileResourceHandler();
26 // ResourceHandler Implementation:
27 virtual bool OnUploadProgress(int request_id
,
29 uint64 size
) OVERRIDE
;
31 // Saves the redirected URL to final_url_, we need to use the original
32 // URL to match original request.
33 virtual bool OnRequestRedirected(int request_id
,
35 ResourceResponse
* response
,
36 bool* defer
) OVERRIDE
;
38 // Sends the download creation information to the download thread.
39 virtual bool OnResponseStarted(int request_id
,
40 ResourceResponse
* response
,
41 bool* defer
) OVERRIDE
;
43 // Pass-through implementation.
44 virtual bool OnWillStart(int request_id
,
46 bool* defer
) OVERRIDE
;
48 // Pass-through implementation.
49 virtual bool OnBeforeNetworkStart(int request_id
,
51 bool* defer
) OVERRIDE
;
53 // Creates a new buffer, which will be handed to the download thread for file
54 // writing and deletion.
55 virtual bool OnWillRead(int request_id
,
56 scoped_refptr
<net::IOBuffer
>* buf
,
58 int min_size
) OVERRIDE
;
60 // Passes the buffer to the download file writer.
61 virtual bool OnReadCompleted(int request_id
, int bytes_read
,
62 bool* defer
) OVERRIDE
;
64 virtual void OnResponseCompleted(int request_id
,
65 const net::URLRequestStatus
& status
,
66 const std::string
& security_info
,
67 bool* defer
) OVERRIDE
;
69 // N/A to this flavor of SaveFileResourceHandler.
70 virtual void OnDataDownloaded(int request_id
, int bytes_downloaded
) OVERRIDE
;
72 // If the content-length header is not present (or contains something other
73 // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and
74 // is handled correctly by the SaveManager.
75 void set_content_length(const std::string
& content_length
);
77 void set_content_disposition(const std::string
& content_disposition
) {
78 content_disposition_
= content_disposition
;
83 int render_process_id_
;
85 scoped_refptr
<net::IOBuffer
> read_buffer_
;
86 std::string content_disposition_
;
89 int64 content_length_
;
90 SaveFileManager
* save_manager_
;
92 static const int kReadBufSize
= 32768; // bytes
94 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler
);
97 } // namespace content
99 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_