| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 static const int kDownloadByteStreamSize; | 39 static const int kDownloadByteStreamSize; |
| 40 | 40 |
| 41 // started_cb will be called exactly once on the UI thread. | 41 // started_cb will be called exactly once on the UI thread. |
| 42 // |id| should be invalid if the id should be automatically assigned. | 42 // |id| should be invalid if the id should be automatically assigned. |
| 43 DownloadResourceHandler( | 43 DownloadResourceHandler( |
| 44 uint32 id, | 44 uint32 id, |
| 45 net::URLRequest* request, | 45 net::URLRequest* request, |
| 46 const DownloadUrlParameters::OnStartedCallback& started_cb, | 46 const DownloadUrlParameters::OnStartedCallback& started_cb, |
| 47 scoped_ptr<DownloadSaveInfo> save_info); | 47 scoped_ptr<DownloadSaveInfo> save_info); |
| 48 | 48 |
| 49 virtual bool OnUploadProgress(uint64 position, uint64 size) override; | 49 bool OnUploadProgress(uint64 position, uint64 size) override; |
| 50 | 50 |
| 51 virtual bool OnRequestRedirected(const net::RedirectInfo& redirect_info, | 51 bool OnRequestRedirected(const net::RedirectInfo& redirect_info, |
| 52 ResourceResponse* response, | 52 ResourceResponse* response, |
| 53 bool* defer) override; | 53 bool* defer) override; |
| 54 | 54 |
| 55 // Send the download creation information to the download thread. | 55 // Send the download creation information to the download thread. |
| 56 virtual bool OnResponseStarted(ResourceResponse* response, | 56 bool OnResponseStarted(ResourceResponse* response, bool* defer) override; |
| 57 bool* defer) override; | |
| 58 | 57 |
| 59 // Pass-through implementation. | 58 // Pass-through implementation. |
| 60 virtual bool OnWillStart(const GURL& url, bool* defer) override; | 59 bool OnWillStart(const GURL& url, bool* defer) override; |
| 61 | 60 |
| 62 // Pass-through implementation. | 61 // Pass-through implementation. |
| 63 virtual bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; | 62 bool OnBeforeNetworkStart(const GURL& url, bool* defer) override; |
| 64 | 63 |
| 65 // Create a new buffer, which will be handed to the download thread for file | 64 // Create a new buffer, which will be handed to the download thread for file |
| 66 // writing and deletion. | 65 // writing and deletion. |
| 67 virtual bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 66 bool OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 68 int* buf_size, | 67 int* buf_size, |
| 69 int min_size) override; | 68 int min_size) override; |
| 70 | 69 |
| 71 virtual bool OnReadCompleted(int bytes_read, bool* defer) override; | 70 bool OnReadCompleted(int bytes_read, bool* defer) override; |
| 72 | 71 |
| 73 virtual void OnResponseCompleted(const net::URLRequestStatus& status, | 72 void OnResponseCompleted(const net::URLRequestStatus& status, |
| 74 const std::string& security_info, | 73 const std::string& security_info, |
| 75 bool* defer) override; | 74 bool* defer) override; |
| 76 | 75 |
| 77 // N/A to this flavor of DownloadHandler. | 76 // N/A to this flavor of DownloadHandler. |
| 78 virtual void OnDataDownloaded(int bytes_downloaded) override; | 77 void OnDataDownloaded(int bytes_downloaded) override; |
| 79 | 78 |
| 80 void PauseRequest(); | 79 void PauseRequest(); |
| 81 void ResumeRequest(); | 80 void ResumeRequest(); |
| 82 | 81 |
| 83 // May result in this object being deleted by its owner. | 82 // May result in this object being deleted by its owner. |
| 84 void CancelRequest(); | 83 void CancelRequest(); |
| 85 | 84 |
| 86 std::string DebugString() const; | 85 std::string DebugString() const; |
| 87 | 86 |
| 88 private: | 87 private: |
| 89 virtual ~DownloadResourceHandler(); | 88 ~DownloadResourceHandler() override; |
| 90 | 89 |
| 91 // Arrange for started_cb_ to be called on the UI thread with the | 90 // Arrange for started_cb_ to be called on the UI thread with the |
| 92 // below values, nulling out started_cb_. Should only be called | 91 // below values, nulling out started_cb_. Should only be called |
| 93 // on the IO thread. | 92 // on the IO thread. |
| 94 void CallStartedCB(DownloadItem* item, | 93 void CallStartedCB(DownloadItem* item, |
| 95 DownloadInterruptReason interrupt_reason); | 94 DownloadInterruptReason interrupt_reason); |
| 96 | 95 |
| 97 uint32 download_id_; | 96 uint32 download_id_; |
| 98 // This is read only on the IO thread, but may only | 97 // This is read only on the IO thread, but may only |
| 99 // be called on the UI thread. | 98 // be called on the UI thread. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 130 |
| 132 static const int kReadBufSize = 32768; // bytes | 131 static const int kReadBufSize = 32768; // bytes |
| 133 static const int kThrottleTimeMs = 200; // milliseconds | 132 static const int kThrottleTimeMs = 200; // milliseconds |
| 134 | 133 |
| 135 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); | 134 DISALLOW_COPY_AND_ASSIGN(DownloadResourceHandler); |
| 136 }; | 135 }; |
| 137 | 136 |
| 138 } // namespace content | 137 } // namespace content |
| 139 | 138 |
| 140 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ | 139 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_RESOURCE_HANDLER_H_ |
| OLD | NEW |