| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "content/browser/download/save_types.h" | 14 #include "content/browser/download/save_types.h" |
| 15 #include "content/browser/loader/resource_handler.h" | 15 #include "content/browser/loader/resource_handler.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class URLRequest; | 19 class URLRequest; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 class ResourceController; |
| 23 class SaveFileManager; | 24 class SaveFileManager; |
| 24 | 25 |
| 25 // Forwards data to the save thread. | 26 // Forwards data to the save thread. |
| 26 class SaveFileResourceHandler : public ResourceHandler { | 27 class SaveFileResourceHandler : public ResourceHandler { |
| 27 public: | 28 public: |
| 28 // Unauthorized requests are cancelled from OnWillStart callback. | 29 // Unauthorized requests are cancelled from OnWillStart callback. |
| 29 // | 30 // |
| 30 // This way of handling unauthorized requests allows unified handling of all | 31 // This way of handling unauthorized requests allows unified handling of all |
| 31 // SaveFile requests - communicating the failure to OnResponseCompleted | 32 // SaveFile requests - communicating the failure to OnResponseCompleted |
| 32 // happens in a generic, typical way, reusing common infrastructure code | 33 // happens in a generic, typical way, reusing common infrastructure code |
| (...skipping 10 matching lines...) Expand all Loading... |
| 43 int render_process_host_id, | 44 int render_process_host_id, |
| 44 int render_frame_routing_id, | 45 int render_frame_routing_id, |
| 45 const GURL& url, | 46 const GURL& url, |
| 46 AuthorizationState authorization_state); | 47 AuthorizationState authorization_state); |
| 47 ~SaveFileResourceHandler() override; | 48 ~SaveFileResourceHandler() override; |
| 48 | 49 |
| 49 // ResourceHandler Implementation: | 50 // ResourceHandler Implementation: |
| 50 | 51 |
| 51 // Saves the redirected URL to final_url_, we need to use the original | 52 // Saves the redirected URL to final_url_, we need to use the original |
| 52 // URL to match original request. | 53 // URL to match original request. |
| 53 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 54 void OnRequestRedirected( |
| 54 ResourceResponse* response, | 55 const net::RedirectInfo& redirect_info, |
| 55 bool* defer) override; | 56 ResourceResponse* response, |
| 57 std::unique_ptr<ResourceController> controller) override; |
| 56 | 58 |
| 57 // Sends the download creation information to the download thread. | 59 // Sends the download creation information to the download thread. |
| 58 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 60 void OnResponseStarted( |
| 61 ResourceResponse* response, |
| 62 std::unique_ptr<ResourceController> controller) override; |
| 59 | 63 |
| 60 // Pass-through implementation. | 64 // Pass-through implementation. |
| 61 bool OnWillStart(const GURL& url, bool* defer) override; | 65 void OnWillStart(const GURL& url, |
| 66 std::unique_ptr<ResourceController> controller) override; |
| 62 | 67 |
| 63 // Creates a new buffer, which will be handed to the download thread for file | 68 // Creates a new buffer, which will be handed to the download thread for file |
| 64 // writing and deletion. | 69 // writing and deletion. |
| 65 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 70 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 66 int* buf_size, | 71 int* buf_size, |
| 67 int min_size) override; | 72 int min_size) override; |
| 68 | 73 |
| 69 // Passes the buffer to the download file writer. | 74 // Passes the buffer to the download file writer. |
| 70 bool OnReadCompleted(int bytes_read, bool* defer) override; | 75 void OnReadCompleted(int bytes_read, |
| 76 std::unique_ptr<ResourceController> controller) override; |
| 71 | 77 |
| 72 void OnResponseCompleted(const net::URLRequestStatus& status, | 78 void OnResponseCompleted( |
| 73 bool* defer) override; | 79 const net::URLRequestStatus& status, |
| 80 std::unique_ptr<ResourceController> controller) override; |
| 74 | 81 |
| 75 // N/A to this flavor of SaveFileResourceHandler. | 82 // N/A to this flavor of SaveFileResourceHandler. |
| 76 void OnDataDownloaded(int bytes_downloaded) override; | 83 void OnDataDownloaded(int bytes_downloaded) override; |
| 77 | 84 |
| 78 // If the content-length header is not present (or contains something other | 85 // If the content-length header is not present (or contains something other |
| 79 // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and | 86 // than numbers), StringToInt64 returns 0, which indicates 'unknown size' and |
| 80 // is handled correctly by the SaveManager. | 87 // is handled correctly by the SaveManager. |
| 81 void set_content_length(const std::string& content_length); | 88 void set_content_length(const std::string& content_length); |
| 82 | 89 |
| 83 void set_content_disposition(const std::string& content_disposition) { | 90 void set_content_disposition(const std::string& content_disposition) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 99 AuthorizationState authorization_state_; | 106 AuthorizationState authorization_state_; |
| 100 | 107 |
| 101 static const int kReadBufSize = 32768; // bytes | 108 static const int kReadBufSize = 32768; // bytes |
| 102 | 109 |
| 103 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler); | 110 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler); |
| 104 }; | 111 }; |
| 105 | 112 |
| 106 } // namespace content | 113 } // namespace content |
| 107 | 114 |
| 108 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ | 115 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ |
| OLD | NEW |