| 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 <string> | 10 #include <string> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 namespace content { | 26 namespace content { |
| 27 class ByteStreamReader; | 27 class ByteStreamReader; |
| 28 class ByteStreamWriter; | 28 class ByteStreamWriter; |
| 29 class DownloadRequestHandle; | 29 class DownloadRequestHandle; |
| 30 class PowerSaveBlocker; | 30 class PowerSaveBlocker; |
| 31 struct DownloadCreateInfo; | 31 struct DownloadCreateInfo; |
| 32 | 32 |
| 33 // Forwards data to the download thread. | 33 // Forwards data to the download thread. |
| 34 class CONTENT_EXPORT DownloadResourceHandler | 34 class CONTENT_EXPORT DownloadResourceHandler |
| 35 : public ResourceHandler, | 35 : public ResourceHandler, |
| 36 public DownloadRequestCore::Delegate, |
| 36 public base::SupportsWeakPtr<DownloadResourceHandler> { | 37 public base::SupportsWeakPtr<DownloadResourceHandler> { |
| 37 public: | 38 public: |
| 38 struct DownloadTabInfo; | 39 struct DownloadTabInfo; |
| 39 | 40 |
| 40 // started_cb will be called exactly once on the UI thread. | 41 // started_cb will be called exactly once on the UI thread. |
| 41 // |id| should be invalid if the id should be automatically assigned. | 42 // |id| should be invalid if the id should be automatically assigned. |
| 42 DownloadResourceHandler( | 43 DownloadResourceHandler(net::URLRequest* request); |
| 43 uint32_t id, | |
| 44 net::URLRequest* request, | |
| 45 const DownloadUrlParameters::OnStartedCallback& started_cb, | |
| 46 scoped_ptr<DownloadSaveInfo> save_info); | |
| 47 | 44 |
| 48 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 45 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 49 ResourceResponse* response, | 46 ResourceResponse* response, |
| 50 bool* defer) override; | 47 bool* defer) override; |
| 51 | 48 |
| 52 // Send the download creation information to the download thread. | 49 // Send the download creation information to the download thread. |
| 53 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; | 50 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 54 | 51 |
| 55 // Pass-through implementation. | 52 // Pass-through implementation. |
| 56 bool OnWillStart(const GURL& url, bool* defer) override; | 53 bool OnWillStart(const GURL& url, bool* defer) override; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 void ResumeRequest(); | 74 void ResumeRequest(); |
| 78 | 75 |
| 79 // May result in this object being deleted by its owner. | 76 // May result in this object being deleted by its owner. |
| 80 void CancelRequest(); | 77 void CancelRequest(); |
| 81 | 78 |
| 82 std::string DebugString() const; | 79 std::string DebugString() const; |
| 83 | 80 |
| 84 private: | 81 private: |
| 85 ~DownloadResourceHandler() override; | 82 ~DownloadResourceHandler() override; |
| 86 | 83 |
| 87 // Arrange for started_cb_ to be called on the UI thread with the | 84 // DownloadRequestCore::Delegate |
| 88 // below values, nulling out started_cb_. Should only be called | 85 void OnStart( |
| 89 // on the IO thread. | 86 scoped_ptr<DownloadCreateInfo> download_create_info, |
| 90 void CallStartedCB(DownloadInterruptReason interrupt_reason); | 87 scoped_ptr<ByteStreamReader> stream_reader, |
| 91 | 88 const DownloadUrlParameters::OnStartedCallback& callback) override; |
| 92 void OnCoreReadyToRead(); | 89 void OnReadyToRead() override; |
| 93 | |
| 94 uint32_t download_id_; | |
| 95 | |
| 96 // This is read only on the IO thread, but may only | |
| 97 // be called on the UI thread. | |
| 98 DownloadUrlParameters::OnStartedCallback started_cb_; | |
| 99 | 90 |
| 100 // Stores information about the download that must be acquired on the UI | 91 // Stores information about the download that must be acquired on the UI |
| 101 // thread before StartOnUIThread is called. | 92 // thread before StartOnUIThread is called. |
| 102 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds | 93 // Created on IO thread, but only accessed on UI thread. |tab_info_| holds |
| 103 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. | 94 // the pointer until we pass it off to StartOnUIThread or DeleteSoon. |
| 104 // Marked as a scoped_ptr<> to indicate ownership of the structure, but | 95 // Marked as a scoped_ptr<> to indicate ownership of the structure, but |
| 105 // deletion must occur on the IO thread. | 96 // deletion must occur on the IO thread. |
| 106 scoped_ptr<DownloadTabInfo> tab_info_; | 97 scoped_ptr<DownloadTabInfo> tab_info_; |
| 107 | 98 |
| 108 DownloadRequestCore core_; | 99 DownloadRequestCore core_; |
| 100 std::string original_mime_type_; |
| 109 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 101 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 110 }; | 102 }; |
| 111 | 103 |
| 112 } // namespace content | 104 } // namespace content |
| 113 | 105 |
| 114 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 106 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |