[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / download / save_file_resource_handler.h
blob42851346c319723a81caaec1e47a51bc6e234d36
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_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "content/browser/loader/resource_handler.h"
12 #include "url/gurl.h"
14 namespace net {
15 class URLRequest;
18 namespace content {
19 class SaveFileManager;
21 // Forwards data to the save thread.
22 class SaveFileResourceHandler : public ResourceHandler {
23 public:
24 SaveFileResourceHandler(net::URLRequest* request,
25 int render_process_host_id,
26 int render_frame_id,
27 const GURL& url,
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,
51 int* buf_size,
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;
73 private:
74 int save_id_;
75 int render_process_id_;
76 int render_frame_id_;
77 scoped_refptr<net::IOBuffer> read_buffer_;
78 std::string content_disposition_;
79 GURL url_;
80 GURL final_url_;
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_