| 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_REQUEST_HANDLE_H_ | 5 #ifndef CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ |
| 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ | 6 #define CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/browser/download/download_resource_handler.h" | |
| 13 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/public/browser/download_interrupt_reasons.h" |
| 14 | 14 |
| 15 namespace content { | 15 namespace content { |
| 16 class DownloadManager; | 16 struct DownloadCreateInfo; |
| 17 class WebContents; | |
| 18 | 17 |
| 19 // A handle used by the download system for operations on the URLRequest | 18 // A handle used by the download system for operations on the URLRequest. |
| 20 // or objects conditional on it (e.g. WebContentsImpl). | 19 class CONTENT_EXPORT DownloadRequestHandle { |
| 21 // This class needs to be copyable, so we can pass it across threads and not | |
| 22 // worry about lifetime or const-ness. | |
| 23 // | |
| 24 // DownloadRequestHandleInterface is defined for mocking purposes. | |
| 25 class CONTENT_EXPORT DownloadRequestHandleInterface { | |
| 26 public: | 20 public: |
| 27 virtual ~DownloadRequestHandleInterface() {} | 21 typedef base::Callback< |
| 22 void(DownloadInterruptReason, scoped_ptr<DownloadCreateInfo>)> |
| 23 RequestStartedCallback; |
| 28 | 24 |
| 29 // These functions must be called on the UI thread. | 25 virtual ~DownloadRequestHandle(); |
| 30 virtual WebContents* GetWebContents() const = 0; | |
| 31 virtual DownloadManager* GetDownloadManager() const = 0; | |
| 32 | 26 |
| 33 // Pauses or resumes the matching URL request. | 27 // Start the request. |
| 28 virtual void Start(const RequestStartedCallback& callback) = 0; |
| 29 |
| 30 // Pauses or resumes the matching URL request. Every call to PauseRequest() |
| 31 // should be balanced with a call to ResumeRequest(). |
| 34 virtual void PauseRequest() const = 0; | 32 virtual void PauseRequest() const = 0; |
| 35 virtual void ResumeRequest() const = 0; | 33 virtual void ResumeRequest() const = 0; |
| 36 | 34 |
| 37 // Cancels the request. | 35 // Cancels the request. |
| 38 virtual void CancelRequest() const = 0; | 36 virtual void CancelRequest() const = 0; |
| 39 | 37 |
| 40 // Describes the object. | 38 // Describes the object. |
| 41 virtual std::string DebugString() const = 0; | 39 virtual std::string DebugString() const = 0; |
| 42 }; | 40 }; |
| 43 | 41 |
| 44 | |
| 45 class CONTENT_EXPORT DownloadRequestHandle | |
| 46 : public DownloadRequestHandleInterface { | |
| 47 public: | |
| 48 virtual ~DownloadRequestHandle(); | |
| 49 | |
| 50 // Create a null DownloadRequestHandle: getters will return null, and | |
| 51 // all actions are no-ops. | |
| 52 // TODO(rdsmith): Ideally, actions would be forbidden rather than | |
| 53 // no-ops, to confirm that no non-testing code actually uses | |
| 54 // a null DownloadRequestHandle. But for now, we need the no-op | |
| 55 // behavior for unit tests. Long-term, this should be fixed by | |
| 56 // allowing mocking of ResourceDispatcherHost in unit tests. | |
| 57 DownloadRequestHandle(); | |
| 58 | |
| 59 // Note that |rdh| is required to be non-null. | |
| 60 DownloadRequestHandle(const base::WeakPtr<DownloadResourceHandler>& handler, | |
| 61 int child_id, | |
| 62 int render_view_id, | |
| 63 int request_id); | |
| 64 | |
| 65 // Implement DownloadRequestHandleInterface interface. | |
| 66 virtual WebContents* GetWebContents() const OVERRIDE; | |
| 67 virtual DownloadManager* GetDownloadManager() const OVERRIDE; | |
| 68 virtual void PauseRequest() const OVERRIDE; | |
| 69 virtual void ResumeRequest() const OVERRIDE; | |
| 70 virtual void CancelRequest() const OVERRIDE; | |
| 71 virtual std::string DebugString() const OVERRIDE; | |
| 72 | |
| 73 private: | |
| 74 base::WeakPtr<DownloadResourceHandler> handler_; | |
| 75 | |
| 76 // The ID of the child process that started the download. | |
| 77 int child_id_; | |
| 78 | |
| 79 // The ID of the render view that started the download. | |
| 80 int render_view_id_; | |
| 81 | |
| 82 // The ID associated with the request used for the download. | |
| 83 int request_id_; | |
| 84 }; | |
| 85 | |
| 86 } // namespace content | 42 } // namespace content |
| 87 | 43 |
| 88 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ | 44 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ |
| OLD | NEW |