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 SaveFileManager; | 23 class SaveFileManager; |
24 | 24 |
25 // Forwards data to the save thread. | 25 // Forwards data to the save thread. |
26 class SaveFileResourceHandler : public ResourceHandler { | 26 class SaveFileResourceHandler : public ResourceHandler { |
27 public: | 27 public: |
| 28 // Unauthorized requests are cancelled from OnWillStart callback. |
| 29 // |
| 30 // This way of handling unauthorized requests allows unified handling of all |
| 31 // SaveFile requests - communicating the failure to OnResponseCompleted |
| 32 // happens in a generic, typical way, reusing common infrastructure code |
| 33 // (rather than forcing an ad-hoc, Save-File-specific call to |
| 34 // OnResponseCompleted from ResourceDispatcherHostImpl::BeginSaveFile). |
| 35 enum class AuthorizationState { |
| 36 AUTHORIZED, |
| 37 NOT_AUTHORIZED, |
| 38 }; |
| 39 |
28 SaveFileResourceHandler(net::URLRequest* request, | 40 SaveFileResourceHandler(net::URLRequest* request, |
29 SaveItemId save_item_id, | 41 SaveItemId save_item_id, |
30 SavePackageId save_package_id, | 42 SavePackageId save_package_id, |
31 int render_process_host_id, | 43 int render_process_host_id, |
32 int render_frame_routing_id, | 44 int render_frame_routing_id, |
33 const GURL& url, | 45 const GURL& url, |
34 SaveFileManager* manager); | 46 SaveFileManager* manager, |
| 47 AuthorizationState authorization_state); |
35 ~SaveFileResourceHandler() override; | 48 ~SaveFileResourceHandler() override; |
36 | 49 |
37 // ResourceHandler Implementation: | 50 // ResourceHandler Implementation: |
38 | 51 |
39 // 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 |
40 // URL to match original request. | 53 // URL to match original request. |
41 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 54 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
42 ResourceResponse* response, | 55 ResourceResponse* response, |
43 bool* defer) override; | 56 bool* defer) override; |
44 | 57 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 SavePackageId save_package_id_; | 91 SavePackageId save_package_id_; |
79 int render_process_id_; | 92 int render_process_id_; |
80 int render_frame_routing_id_; | 93 int render_frame_routing_id_; |
81 scoped_refptr<net::IOBuffer> read_buffer_; | 94 scoped_refptr<net::IOBuffer> read_buffer_; |
82 std::string content_disposition_; | 95 std::string content_disposition_; |
83 GURL url_; | 96 GURL url_; |
84 GURL final_url_; | 97 GURL final_url_; |
85 int64_t content_length_; | 98 int64_t content_length_; |
86 SaveFileManager* save_manager_; | 99 SaveFileManager* save_manager_; |
87 | 100 |
| 101 AuthorizationState authorization_state_; |
| 102 |
88 static const int kReadBufSize = 32768; // bytes | 103 static const int kReadBufSize = 32768; // bytes |
89 | 104 |
90 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler); | 105 DISALLOW_COPY_AND_ASSIGN(SaveFileResourceHandler); |
91 }; | 106 }; |
92 | 107 |
93 } // namespace content | 108 } // namespace content |
94 | 109 |
95 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ | 110 #endif // CONTENT_BROWSER_DOWNLOAD_SAVE_FILE_RESOURCE_HANDLER_H_ |
OLD | NEW |