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_DOWNLOAD_RESOURCE_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "content/browser/download/download_request_core.h" | 15 #include "content/browser/download/download_request_core.h" |
16 #include "content/browser/loader/resource_handler.h" | 16 #include "content/browser/loader/resource_handler.h" |
17 #include "content/public/browser/download_interrupt_reasons.h" | 17 #include "content/public/browser/download_interrupt_reasons.h" |
18 #include "content/public/browser/download_manager.h" | 18 #include "content/public/browser/download_manager.h" |
19 #include "content/public/browser/download_save_info.h" | 19 #include "content/public/browser/download_save_info.h" |
20 #include "content/public/browser/download_url_parameters.h" | 20 #include "content/public/browser/download_url_parameters.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 class URLRequest; | 23 class URLRequest; |
24 } // namespace net | 24 } // namespace net |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 class ByteStreamReader; | 27 class ByteStreamReader; |
28 struct DownloadCreateInfo; | 28 struct DownloadCreateInfo; |
| 29 class ResourceController; |
29 | 30 |
30 // Forwards data to the download thread. | 31 // Forwards data to the download thread. |
31 class CONTENT_EXPORT DownloadResourceHandler | 32 class CONTENT_EXPORT DownloadResourceHandler |
32 : public ResourceHandler, | 33 : public ResourceHandler, |
33 public DownloadRequestCore::Delegate, | 34 public DownloadRequestCore::Delegate, |
34 public base::SupportsWeakPtr<DownloadResourceHandler> { | 35 public base::SupportsWeakPtr<DownloadResourceHandler> { |
35 public: | 36 public: |
36 struct DownloadTabInfo; | 37 struct DownloadTabInfo; |
37 | 38 |
38 // started_cb will be called exactly once on the UI thread. | 39 // started_cb will be called exactly once on the UI thread. |
39 // |id| should be invalid if the id should be automatically assigned. | 40 // |id| should be invalid if the id should be automatically assigned. |
40 DownloadResourceHandler(net::URLRequest* request); | 41 DownloadResourceHandler(net::URLRequest* request); |
41 | 42 |
42 // static | 43 // static |
43 // This function is passed into ResourceDispatcherHostImpl during its | 44 // This function is passed into ResourceDispatcherHostImpl during its |
44 // creation and is used to create instances of DownloadResourceHandler as | 45 // creation and is used to create instances of DownloadResourceHandler as |
45 // needed. | 46 // needed. |
46 // TODO(ananta) | 47 // TODO(ananta) |
47 // Find a better way to achieve this. Ideally we want to move the logic of | 48 // Find a better way to achieve this. Ideally we want to move the logic of |
48 // creating DownloadResourceHandler instances out of | 49 // creating DownloadResourceHandler instances out of |
49 // ResourceDispatcherHostImpl. | 50 // ResourceDispatcherHostImpl. |
50 static std::unique_ptr<ResourceHandler> Create(net::URLRequest* request); | 51 static std::unique_ptr<ResourceHandler> Create(net::URLRequest* request); |
51 | 52 |
52 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 53 void OnRequestRedirected( |
53 ResourceResponse* response, | 54 const net::RedirectInfo& redirect_info, |
54 bool* defer) override; | 55 ResourceResponse* response, |
| 56 std::unique_ptr<ResourceController> controller) override; |
55 | 57 |
56 // Send the download creation information to the download thread. | 58 // Send the download creation information to the download thread. |
57 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 59 void OnResponseStarted( |
| 60 ResourceResponse* response, |
| 61 std::unique_ptr<ResourceController> controller) override; |
58 | 62 |
59 // Pass-through implementation. | 63 // Pass-through implementation. |
60 bool OnWillStart(const GURL& url, bool* defer) override; | 64 void OnWillStart(const GURL& url, |
| 65 std::unique_ptr<ResourceController> controller) override; |
61 | 66 |
62 // Create a new buffer, which will be handed to the download thread for file | 67 // Create a new buffer, which will be handed to the download thread for file |
63 // writing and deletion. | 68 // writing and deletion. |
64 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 69 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
65 int* buf_size, | 70 int* buf_size, |
66 int min_size) override; | 71 int min_size) override; |
67 | 72 |
68 bool OnReadCompleted(int bytes_read, bool* defer) override; | 73 void OnReadCompleted(int bytes_read, |
| 74 std::unique_ptr<ResourceController> controller) override; |
69 | 75 |
70 void OnResponseCompleted(const net::URLRequestStatus& status, | 76 void OnResponseCompleted( |
71 bool* defer) override; | 77 const net::URLRequestStatus& status, |
| 78 std::unique_ptr<ResourceController> controller) override; |
72 | 79 |
73 // N/A to this flavor of DownloadHandler. | 80 // N/A to this flavor of DownloadHandler. |
74 void OnDataDownloaded(int bytes_downloaded) override; | 81 void OnDataDownloaded(int bytes_downloaded) override; |
75 | 82 |
76 void PauseRequest(); | 83 void PauseRequest(); |
77 void ResumeRequest(); | 84 void ResumeRequest(); |
78 | 85 |
79 // May result in this object being deleted by its owner. | 86 // May result in this object being deleted by its owner. |
80 void CancelRequest(); | 87 void CancelRequest(); |
81 | 88 |
(...skipping 11 matching lines...) Expand all Loading... |
93 | 100 |
94 // Stores information about the download that must be acquired on the UI | 101 // Stores information about the download that must be acquired on the UI |
95 // thread before StartOnUIThread is called. | 102 // thread before StartOnUIThread is called. |
96 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds | 103 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds |
97 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. | 104 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. |
98 // Marked as a std::unique_ptr<> to indicate ownership of the structure, but | 105 // Marked as a std::unique_ptr<> to indicate ownership of the structure, but |
99 // deletion must occur on the IO thread. | 106 // deletion must occur on the IO thread. |
100 std::unique_ptr<DownloadTabInfo> tab_info_; | 107 std::unique_ptr<DownloadTabInfo> tab_info_; |
101 | 108 |
102 DownloadRequestCore core_; | 109 DownloadRequestCore core_; |
| 110 |
103 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 111 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
104 }; | 112 }; |
105 | 113 |
106 } // namespace content | 114 } // namespace content |
107 | 115 |
108 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 116 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
OLD | NEW |