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

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: Fixed compile error. 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
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"
12
11 class DownloadManager; 13 class DownloadManager;
12 class ResourceDispatcherHost; 14 class ResourceDispatcherHost;
13 class TabContents; 15 class TabContents;
14 16
15 // A handle used by the download system for operations on the URLRequest 17 // A handle used by the download system for operations on the URLRequest
16 // or objects conditional on it (e.g. TabContents). 18 // or objects conditional on it (e.g. TabContents).
17 // This class needs to be copyable, so we can pass it across threads and not 19 // This class needs to be copyable, so we can pass it across threads and not
18 // worry about lifetime or const-ness. 20 // worry about lifetime or const-ness.
19 class DownloadRequestHandle { 21 //
22 // DownloadRequestHandleInterface is defined for mocking purposes.
23 class DownloadRequestHandleInterface {
cbentzel 2011/10/27 17:20:39 I haven't seen the "Interface" suffix used too hea
Randy Smith (Not in Mondays) 2011/10/27 18:21:22 Well, that's actually precisely why I *didn't* go
cbentzel 2011/10/27 18:45:34 Maybe it's me, but it doesn't look like the curren
24 public:
25 virtual ~DownloadRequestHandleInterface() {}
26
27 // These functions must be called on the UI thread.
28 virtual TabContents* GetTabContents() const = 0;
29 virtual DownloadManager* GetDownloadManager() const = 0;
30
31 // Pause or resume the matching URL request.
cbentzel 2011/10/27 17:20:39 Do these also need to be called on the UI thread?
Randy Smith (Not in Mondays) 2011/10/27 18:21:22 Nope; they're ok to call anywhere.
32 virtual void PauseRequest() const = 0;
33 virtual void ResumeRequest() const = 0;
34
35 // Cancel the request.
36 virtual void CancelRequest() const = 0;
37
38 // Describe the object.
39 virtual std::string DebugString() const = 0;
40 };
41
42
43 class DownloadRequestHandle : public DownloadRequestHandleInterface {
cbentzel 2011/10/27 17:20:39 Do you want to move this into a separate header? P
Randy Smith (Not in Mondays) 2011/10/27 18:21:22 I'm neutral on it--happy to move it if you want, b
cbentzel 2011/10/27 18:45:34 Not too concerned. I'll revisit after you add the
20 public: 44 public:
21 // Create a null DownloadRequestHandle: getters will return null, and 45 // Create a null DownloadRequestHandle: getters will return null, and
22 // all actions are no-ops. 46 // all actions are no-ops.
23 // TODO(rdsmith): Ideally, actions would be forbidden rather than 47 // TODO(rdsmith): Ideally, actions would be forbidden rather than
24 // no-ops, to confirm that no non-testing code actually uses 48 // no-ops, to confirm that no non-testing code actually uses
25 // a null DownloadRequestHandle. But for now, we need the no-op 49 // a null DownloadRequestHandle. But for now, we need the no-op
26 // behavior for unit tests. Long-term, this should be fixed by 50 // behavior for unit tests. Long-term, this should be fixed by
27 // allowing mocking of ResourceDispatcherHost in unit tests. 51 // allowing mocking of ResourceDispatcherHost in unit tests.
28 DownloadRequestHandle(); 52 DownloadRequestHandle();
29 53
30 // Note that |rdh| is required to be non-null. 54 // Note that |rdh| is required to be non-null.
31 DownloadRequestHandle(ResourceDispatcherHost* rdh, 55 DownloadRequestHandle(ResourceDispatcherHost* rdh,
32 int child_id, 56 int child_id,
33 int render_view_id, 57 int render_view_id,
34 int request_id); 58 int request_id);
35 59
36 // These functions must be called on the UI thread. 60 // Implement DownloadRequestHandleInterface interface.
37 TabContents* GetTabContents() const; 61 virtual TabContents* GetTabContents() const OVERRIDE;
cbentzel 2011/10/27 17:20:39 The OVERRIDE isn't completely needed here because
Randy Smith (Not in Mondays) 2011/10/27 18:21:22 Done.
38 DownloadManager* GetDownloadManager() const; 62 virtual DownloadManager* GetDownloadManager() const OVERRIDE;
39 63 virtual void PauseRequest() const OVERRIDE;
40 // Pause or resume the matching URL request. 64 virtual void ResumeRequest() const OVERRIDE;
41 void PauseRequest() const; 65 virtual void CancelRequest() const OVERRIDE;
42 void ResumeRequest() const; 66 virtual std::string DebugString() const OVERRIDE;
43
44 // Cancel the request
45 void CancelRequest() const;
46
47 std::string DebugString() const;
48 67
49 private: 68 private:
50 // The resource dispatcher host. 69 // The resource dispatcher host.
51 ResourceDispatcherHost* rdh_; 70 ResourceDispatcherHost* rdh_;
52 71
53 // The ID of the child process that started the download. 72 // The ID of the child process that started the download.
54 int child_id_; 73 int child_id_;
55 74
56 // The ID of the render view that started the download. 75 // The ID of the render view that started the download.
57 int render_view_id_; 76 int render_view_id_;
58 77
59 // The ID associated with the request used for the download. 78 // The ID associated with the request used for the download.
60 int request_id_; 79 int request_id_;
61 }; 80 };
62 81
63 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_ 82 #endif // CONTENT_BROWSER_DOWNLOAD_DOWNLOAD_REQUEST_HANDLE_H_
OLDNEW
« content/browser/download/download_item.cc ('K') | « content/browser/download/download_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698