| 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 a terminal state (defined | 20 // - A specified number of downloads change to a terminal state (defined |
| 19 // in derived classes). | 21 // in derived classes). |
| 20 // - Specific events, such as a select file dialog. | 22 // - Specific events, such as a select file dialog. |
| 21 // Callers may either probe for the finished state, or wait on it. | 23 // Callers may either probe for the finished state, or wait on it. |
| 22 // | 24 // |
| 23 // TODO(rdsmith): Detect manager going down, remove pointer to | 25 // TODO(rdsmith): Detect manager going down, remove pointer to |
| 24 // DownloadManager, transition to finished. (For right now we | 26 // DownloadManager, transition to finished. (For right now we |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 | 228 |
| 227 void PingIOThread(int cycle); | 229 void PingIOThread(int cycle); |
| 228 | 230 |
| 229 content::DownloadManager* download_manager_; | 231 content::DownloadManager* download_manager_; |
| 230 DownloadSet downloads_observed_; | 232 DownloadSet downloads_observed_; |
| 231 bool waiting_for_zero_inprogress_; | 233 bool waiting_for_zero_inprogress_; |
| 232 | 234 |
| 233 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); | 235 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); |
| 234 }; | 236 }; |
| 235 | 237 |
| 238 // Waits for a callback indicating that the DownloadItem is about to be created, |
| 239 // or that an error occurred and it won't be created. |
| 240 class DownloadTestItemCreationObserver |
| 241 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { |
| 242 public: |
| 243 DownloadTestItemCreationObserver(); |
| 244 |
| 245 void WaitForDownloadItemCreation(); |
| 246 |
| 247 content::DownloadId download_id() const { return download_id_; } |
| 248 net::Error error() const { return error_; } |
| 249 bool started() const { return called_back_count_ > 0; } |
| 250 bool succeeded() const { return started() && (error_ == net::OK); } |
| 251 |
| 252 const content::DownloadManager::OnStartedCallback callback(); |
| 253 |
| 254 private: |
| 255 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; |
| 256 |
| 257 ~DownloadTestItemCreationObserver(); |
| 258 |
| 259 void DownloadItemCreationCallback(content::DownloadId download_id, |
| 260 net::Error error); |
| 261 |
| 262 // The download creation information we received. |
| 263 content::DownloadId download_id_; |
| 264 |
| 265 net::Error error_; |
| 266 |
| 267 // Count of callbacks. |
| 268 size_t called_back_count_; |
| 269 |
| 270 // We are in the message loop. |
| 271 bool waiting_; |
| 272 |
| 273 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); |
| 274 }; |
| 275 |
| 236 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 276 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
| OLD | NEW |