Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: content/browser/download/download_request_handle.h

Issue 8399001: Use a DownloadRequestHandle pointer in construction to allow mocking for tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to TOT. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/download/download_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/compiler_specific.h"
11 #include "content/common/content_export.h" 12 #include "content/common/content_export.h"
12 13
13 class DownloadManager; 14 class DownloadManager;
14 class ResourceDispatcherHost; 15 class ResourceDispatcherHost;
15 class TabContents; 16 class TabContents;
16 17
17 // 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
18 // or objects conditional on it (e.g. TabContents). 19 // or objects conditional on it (e.g. TabContents).
19 // This class needs to be copyable, so we can pass it across threads and not 20 // This class needs to be copyable, so we can pass it across threads and not
20 // worry about lifetime or const-ness. 21 // worry about lifetime or const-ness.
21 class CONTENT_EXPORT DownloadRequestHandle { 22 //
23 // DownloadRequestHandleInterface is defined for mocking purposes.
24 class CONTENT_EXPORT DownloadRequestHandleInterface {
25 public:
26 virtual ~DownloadRequestHandleInterface() {}
27
28 // These functions must be called on the UI thread.
29 virtual TabContents* GetTabContents() const = 0;
30 virtual DownloadManager* GetDownloadManager() const = 0;
31
32 // Pause or resume the matching URL request.
33 virtual void PauseRequest() const = 0;
34 virtual void ResumeRequest() const = 0;
35
36 // Cancel the request.
37 virtual void CancelRequest() const = 0;
38
39 // Describe the object.
40 virtual std::string DebugString() const = 0;
41 };
42
43
44 class CONTENT_EXPORT DownloadRequestHandle
45 : public DownloadRequestHandleInterface {
22 public: 46 public:
23 // Create a null DownloadRequestHandle: getters will return null, and 47 // Create a null DownloadRequestHandle: getters will return null, and
24 // all actions are no-ops. 48 // all actions are no-ops.
25 // TODO(rdsmith): Ideally, actions would be forbidden rather than 49 // TODO(rdsmith): Ideally, actions would be forbidden rather than
26 // no-ops, to confirm that no non-testing code actually uses 50 // no-ops, to confirm that no non-testing code actually uses
27 // a null DownloadRequestHandle. But for now, we need the no-op 51 // a null DownloadRequestHandle. But for now, we need the no-op
28 // behavior for unit tests. Long-term, this should be fixed by 52 // behavior for unit tests. Long-term, this should be fixed by
29 // allowing mocking of ResourceDispatcherHost in unit tests. 53 // allowing mocking of ResourceDispatcherHost in unit tests.
30 DownloadRequestHandle(); 54 DownloadRequestHandle();
31 55
32 // Note that |rdh| is required to be non-null. 56 // Note that |rdh| is required to be non-null.
33 DownloadRequestHandle(ResourceDispatcherHost* rdh, 57 DownloadRequestHandle(ResourceDispatcherHost* rdh,
34 int child_id, 58 int child_id,
35 int render_view_id, 59 int render_view_id,
36 int request_id); 60 int request_id);
37 61
38 // These functions must be called on the UI thread. 62 // Implement DownloadRequestHandleInterface interface.
39 TabContents* GetTabContents() const; 63 virtual TabContents* GetTabContents() const OVERRIDE;
40 DownloadManager* GetDownloadManager() const; 64 virtual DownloadManager* GetDownloadManager() const OVERRIDE;
41 65 virtual void PauseRequest() const OVERRIDE;
42 // Pause or resume the matching URL request. 66 virtual void ResumeRequest() const OVERRIDE;
43 void PauseRequest() const; 67 virtual void CancelRequest() const OVERRIDE;
44 void ResumeRequest() const; 68 virtual std::string DebugString() const OVERRIDE;
45
46 // Cancel the request
47 void CancelRequest() const;
48
49 std::string DebugString() const;
50 69
51 private: 70 private:
52 // The resource dispatcher host. 71 // The resource dispatcher host.
53 ResourceDispatcherHost* rdh_; 72 ResourceDispatcherHost* rdh_;
54 73
55 // The ID of the child process that started the download. 74 // The ID of the child process that started the download.
56 int child_id_; 75 int child_id_;
57 76
58 // The ID of the render view that started the download. 77 // The ID of the render view that started the download.
59 int render_view_id_; 78 int render_view_id_;
60 79
61 // The ID associated with the request used for the download. 80 // The ID associated with the request used for the download.
62 int request_id_; 81 int request_id_;
63 }; 82 };
64 83
65 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ 84 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
OLDNEW
« no previous file with comments | « content/browser/download/download_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698