| 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> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/browser/download/download_request_core.h" | 15 #include "content/browser/download/download_request_core.h" |
| 13 #include "content/browser/loader/resource_handler.h" | 16 #include "content/browser/loader/resource_handler.h" |
| 14 #include "content/public/browser/download_interrupt_reasons.h" | 17 #include "content/public/browser/download_interrupt_reasons.h" |
| 15 #include "content/public/browser/download_manager.h" | 18 #include "content/public/browser/download_manager.h" |
| 16 #include "content/public/browser/download_save_info.h" | 19 #include "content/public/browser/download_save_info.h" |
| 17 #include "content/public/browser/download_url_parameters.h" | 20 #include "content/public/browser/download_url_parameters.h" |
| 18 | 21 |
| 19 namespace net { | 22 namespace net { |
| 20 class URLRequest; | 23 class URLRequest; |
| 21 } // namespace net | 24 } // namespace net |
| 22 | 25 |
| 23 namespace content { | 26 namespace content { |
| 24 class ByteStreamReader; | 27 class ByteStreamReader; |
| 25 class ByteStreamWriter; | 28 class ByteStreamWriter; |
| 26 class DownloadRequestHandle; | 29 class DownloadRequestHandle; |
| 27 class PowerSaveBlocker; | 30 class PowerSaveBlocker; |
| 28 struct DownloadCreateInfo; | 31 struct DownloadCreateInfo; |
| 29 | 32 |
| 30 // Forwards data to the download thread. | 33 // Forwards data to the download thread. |
| 31 class CONTENT_EXPORT DownloadResourceHandler | 34 class CONTENT_EXPORT DownloadResourceHandler |
| 32 : public ResourceHandler, | 35 : public ResourceHandler, |
| 33 public base::SupportsWeakPtr<DownloadResourceHandler> { | 36 public base::SupportsWeakPtr<DownloadResourceHandler> { |
| 34 public: | 37 public: |
| 35 struct DownloadTabInfo; | 38 struct DownloadTabInfo; |
| 36 | 39 |
| 37 // started_cb will be called exactly once on the UI thread. | 40 // started_cb will be called exactly once on the UI thread. |
| 38 // |id| should be invalid if the id should be automatically assigned. | 41 // |id| should be invalid if the id should be automatically assigned. |
| 39 DownloadResourceHandler( | 42 DownloadResourceHandler( |
| 40 uint32 id, | 43 uint32_t id, |
| 41 net::URLRequest* request, | 44 net::URLRequest* request, |
| 42 const DownloadUrlParameters::OnStartedCallback& started_cb, | 45 const DownloadUrlParameters::OnStartedCallback& started_cb, |
| 43 scoped_ptr<DownloadSaveInfo> save_info); | 46 scoped_ptr<DownloadSaveInfo> save_info); |
| 44 | 47 |
| 45 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 48 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 46 ResourceResponse* response, | 49 ResourceResponse* response, |
| 47 bool* defer) override; | 50 bool* defer) override; |
| 48 | 51 |
| 49 // Send the download creation information to the download thread. | 52 // Send the download creation information to the download thread. |
| 50 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 53 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 81 private: | 84 private: |
| 82 ~DownloadResourceHandler() override; | 85 ~DownloadResourceHandler() override; |
| 83 | 86 |
| 84 // Arrange for started_cb_ to be called on the UI thread with the | 87 // Arrange for started_cb_ to be called on the UI thread with the |
| 85 // below values, nulling out started_cb_. Should only be called | 88 // below values, nulling out started_cb_. Should only be called |
| 86 // on the IO thread. | 89 // on the IO thread. |
| 87 void CallStartedCB(DownloadInterruptReason interrupt_reason); | 90 void CallStartedCB(DownloadInterruptReason interrupt_reason); |
| 88 | 91 |
| 89 void OnCoreReadyToRead(); | 92 void OnCoreReadyToRead(); |
| 90 | 93 |
| 91 uint32 download_id_; | 94 uint32_t download_id_; |
| 92 | 95 |
| 93 // This is read only on the IO thread, but may only | 96 // This is read only on the IO thread, but may only |
| 94 // be called on the UI thread. | 97 // be called on the UI thread. |
| 95 DownloadUrlParameters::OnStartedCallback started_cb_; | 98 DownloadUrlParameters::OnStartedCallback started_cb_; |
| 96 | 99 |
| 97 // Stores information about the download that must be acquired on the UI | 100 // Stores information about the download that must be acquired on the UI |
| 98 // thread before StartOnUIThread is called. | 101 // thread before StartOnUIThread is called. |
| 99 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds | 102 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds |
| 100 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. | 103 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. |
| 101 // Marked as a scoped_ptr<> to indicate ownership of the structure, but | 104 // Marked as a scoped_ptr<> to indicate ownership of the structure, but |
| 102 // deletion must occur on the IO thread. | 105 // deletion must occur on the IO thread. |
| 103 scoped_ptr<DownloadTabInfo> tab_info_; | 106 scoped_ptr<DownloadTabInfo> tab_info_; |
| 104 | 107 |
| 105 DownloadRequestCore core_; | 108 DownloadRequestCore core_; |
| 106 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 109 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 107 }; | 110 }; |
| 108 | 111 |
| 109 } // namespace content | 112 } // namespace content |
| 110 | 113 |
| 111 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 114 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |