Chromium Code Reviews| 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 #include <vector> | |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 13 #include "content/public/browser/download_item.h" | 14 #include "content/public/browser/download_item.h" |
| 14 #include "content/public/browser/download_manager.h" | 15 #include "content/public/browser/download_manager.h" |
| 16 #include "net/base/net_errors.h" | |
| 15 | 17 |
| 16 // Detects changes to the downloads after construction. | 18 // Detects changes to the downloads after construction. |
| 17 // Finishes when one of the following happens: | 19 // Finishes when one of the following happens: |
| 18 // - A specified number of downloads change to either a given state or a | 20 // - A specified number of downloads change to either a given state or a |
| 19 // terminal state (defined as either CANCELLED, or one which you can't | 21 // terminal state (defined as either CANCELLED, or one which you can't |
| 20 // switch out of). | 22 // switch out of). |
| 21 // - Specific events, such as a select file dialog. | 23 // - Specific events, such as a select file dialog. |
| 22 // Callers may either probe for the finished state, or wait on it. | 24 // Callers may either probe for the finished state, or wait on it. |
| 23 // | 25 // |
| 24 // TODO(rdsmith): Detect manager going down, remove pointer to | 26 // TODO(rdsmith): Detect manager going down, remove pointer to |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 195 |
| 194 void PingIOThread(int cycle); | 196 void PingIOThread(int cycle); |
| 195 | 197 |
| 196 content::DownloadManager* download_manager_; | 198 content::DownloadManager* download_manager_; |
| 197 DownloadSet downloads_observed_; | 199 DownloadSet downloads_observed_; |
| 198 bool waiting_for_zero_inprogress_; | 200 bool waiting_for_zero_inprogress_; |
| 199 | 201 |
| 200 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); | 202 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); |
| 201 }; | 203 }; |
| 202 | 204 |
| 205 // Waits for a callback indicating that the DownloadItem is about to be created, | |
| 206 // or that an error occurred and it won't be created. | |
| 207 class DownloadTestItemCreationObserver | |
| 208 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { | |
| 209 public: | |
| 210 struct CreationInfo { | |
|
Randy Smith (Not in Mondays)
2012/03/06 21:29:14
Sorry to be pedantic about test code, but good cla
ahendrickson
2012/03/07 02:58:12
Done.
| |
| 211 CreationInfo() | |
| 212 : download_id(content::DownloadId::Invalid()), | |
| 213 error(net::OK) { | |
| 214 } | |
| 215 | |
| 216 content::DownloadId download_id; | |
| 217 net::Error error; | |
| 218 }; | |
| 219 | |
| 220 DownloadTestItemCreationObserver(); | |
| 221 | |
| 222 void WaitForDownloadItemCreation(); | |
| 223 | |
| 224 content::DownloadId download_id() const { | |
| 225 return creation_info_.download_id; | |
| 226 } | |
| 227 net::Error error() const { return creation_info_.error; } | |
| 228 bool started() const { return called_back_count_ > 0; } | |
| 229 bool succeeded() const { | |
| 230 return started() && (creation_info_.error == net::OK); | |
| 231 } | |
| 232 | |
| 233 const content::DownloadManager::OnStartedCallback callback(); | |
| 234 | |
| 235 private: | |
| 236 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; | |
| 237 | |
| 238 ~DownloadTestItemCreationObserver(); | |
| 239 | |
| 240 void DownloadItemCreationCallback(content::DownloadId download_id, | |
| 241 net::Error error); | |
| 242 | |
| 243 // The download creation information we received. | |
| 244 CreationInfo creation_info_; | |
| 245 | |
| 246 // Count of callbacks. | |
| 247 size_t called_back_count_; | |
| 248 | |
| 249 // We are in the message loop. | |
| 250 bool waiting_; | |
| 251 | |
| 252 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | |
| 253 }; | |
| 254 | |
| 203 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 255 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
| OLD | NEW |