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 CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 5 #ifndef CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 6 #define CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "content/public/browser/download_item.h" | 13 #include "content/public/browser/download_item.h" |
14 #include "content/public/browser/download_manager.h" | 14 #include "content/public/browser/download_manager.h" |
15 | 15 |
16 // Construction of this class defines a system state, based on some number | 16 // Construction of this class defines a system state, based on some number |
17 // of downloads being seen in a particular state + other events that | 17 // of downloads being seen in a particular state + other events that |
18 // may occur in the download system. That state will be recorded if it | 18 // may occur in the download system. That state will be recorded if it |
19 // occurs at any point after construction. When that state occurs, the class | 19 // occurs at any point after construction. When that state occurs, the class |
20 // is considered finished. Callers may either probe for the finished state, or | 20 // is considered finished. Callers may either probe for the finished state, or |
21 // wait on it. | 21 // wait on it. |
Randy Smith (Not in Mondays)
2012/03/01 21:07:53
You are changing the behavior of this class, so yo
ahendrickson
2012/03/02 17:29:41
Done.
| |
22 // | 22 // |
23 // TODO(rdsmith): Detect manager going down, remove pointer to | 23 // TODO(rdsmith): Detect manager going down, remove pointer to |
ahendrickson
2012/03/02 17:29:41
Does my change fix this issue? I think so, becaus
| |
24 // DownloadManager, transition to finished. (For right now we | 24 // DownloadManager, transition to finished. (For right now we |
25 // just use a scoped_refptr<> to keep it around, but that may cause | 25 // just use a scoped_refptr<> to keep it around, but that may cause |
26 // timeouts on waiting if a DownloadManager::Shutdown() occurs which | 26 // timeouts on waiting if a DownloadManager::Shutdown() occurs which |
27 // cancels our in-progress downloads.) | 27 // cancels our in-progress downloads.) |
28 class DownloadTestObserver : public content::DownloadManager::Observer, | 28 class DownloadTestObserver : public content::DownloadManager::Observer, |
29 public content::DownloadItem::Observer { | 29 public content::DownloadItem::Observer { |
30 public: | 30 public: |
31 // Action an observer should take if a dangerous download is encountered. | 31 // Action an observer should take if a dangerous download is encountered. |
32 enum DangerousDownloadAction { | 32 enum DangerousDownloadAction { |
33 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download | 33 ON_DANGEROUS_DOWNLOAD_ACCEPT, // Accept the download |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE {} | 66 virtual void OnDownloadOpened(content::DownloadItem* download) OVERRIDE {} |
67 | 67 |
68 // content::DownloadManager::Observer | 68 // content::DownloadManager::Observer |
69 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; | 69 virtual void ModelChanged(content::DownloadManager* manager) OVERRIDE; |
70 | 70 |
71 virtual void SelectFileDialogDisplayed( | 71 virtual void SelectFileDialogDisplayed( |
72 content::DownloadManager* manager, int32 id) OVERRIDE; | 72 content::DownloadManager* manager, int32 id) OVERRIDE; |
73 | 73 |
74 size_t NumDangerousDownloadsSeen() const; | 74 size_t NumDangerousDownloadsSeen() const; |
75 | 75 |
76 // If we finish other than because we met the condtions, call this to find | |
77 // out how many rogue downloads there were. | |
78 size_t NumOtherDownloadsSeen() const; | |
Randy Smith (Not in Mondays)
2012/03/01 21:07:53
In context, it isn't clear what "rogue downloads"
ahendrickson
2012/03/02 17:29:41
Changed the comment.
| |
79 | |
76 private: | 80 private: |
77 typedef std::set<content::DownloadItem*> DownloadSet; | 81 typedef std::set<content::DownloadItem*> DownloadSet; |
78 | 82 |
79 // Called when we know that a download item is in a final state. | 83 // Called when we know that a download item is in a final state. |
80 // Note that this is not the same as it first transitioning in to the | 84 // Note that this is not the same as it first transitioning in to the |
81 // final state; multiple notifications may occur once the item is in | 85 // final state; multiple notifications may occur once the item is in |
82 // that state. So we keep our own track of transitions into final. | 86 // that state. So we keep our own track of transitions into final. |
83 void DownloadInFinalState(content::DownloadItem* download); | 87 void DownloadInFinalState(content::DownloadItem* download); |
84 | 88 |
89 // Called when we think the download item is in a terminal state. | |
90 void DownloadInTerminalState(content::DownloadItem* download); | |
91 | |
85 void SignalIfFinished(); | 92 void SignalIfFinished(); |
86 | 93 |
87 // The observed download manager. | 94 // The observed download manager. |
88 scoped_refptr<content::DownloadManager> download_manager_; | 95 scoped_refptr<content::DownloadManager> download_manager_; |
89 | 96 |
97 // The set of |DownloadItem|s that have transitioned to a final state before | |
98 // we start. Will not overlap with |finished_downloads_|. | |
99 DownloadSet previously_finished_downloads_; | |
100 | |
101 // The set of |DownloadItem|s that have transitioned to a final state without | |
102 // having hit the 'finished' state. Will not overlap with | |
103 // |finished_downloads_|. | |
104 // This is so the test will finish even if it doesn't have the expected | |
105 // result. | |
106 DownloadSet finished_other_downloads_; | |
107 | |
90 // The set of DownloadItem's that have transitioned to their finished state | 108 // The set of DownloadItem's that have transitioned to their finished state |
91 // since construction of this object. When the size of this array | 109 // since construction of this object. When the size of this array |
92 // reaches wait_count_, we're done. | 110 // reaches wait_count_, we're done. |
93 DownloadSet finished_downloads_; | 111 DownloadSet finished_downloads_; |
94 | 112 |
95 // The set of DownloadItem's we are currently observing. Generally there | 113 // The set of DownloadItem's we are currently observing. Generally there |
96 // won't be any overlap with the above; once we see the final state | 114 // won't be any overlap with the above; once we see the final state |
97 // on a DownloadItem, we'll stop observing it. | 115 // on a DownloadItem, we'll stop observing it. |
98 DownloadSet downloads_observed_; | 116 DownloadSet downloads_observed_; |
99 | 117 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 void PingIOThread(int cycle); | 193 void PingIOThread(int cycle); |
176 | 194 |
177 content::DownloadManager* download_manager_; | 195 content::DownloadManager* download_manager_; |
178 DownloadSet downloads_observed_; | 196 DownloadSet downloads_observed_; |
179 bool waiting_for_zero_inprogress_; | 197 bool waiting_for_zero_inprogress_; |
180 | 198 |
181 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); | 199 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); |
182 }; | 200 }; |
183 | 201 |
184 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 202 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
OLD | NEW |