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 // Construction of this class defines a system state, based on some number | 18 // Construction of this class defines a system state, based on some number |
| 17 // of downloads being seen in a particular state + other events that | 19 // 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 | 20 // 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 | 21 // 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 | 22 // is considered finished. Callers may either probe for the finished state, or |
| 21 // wait on it. | 23 // 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 | 193 |
| 192 void PingIOThread(int cycle); | 194 void PingIOThread(int cycle); |
| 193 | 195 |
| 194 content::DownloadManager* download_manager_; | 196 content::DownloadManager* download_manager_; |
| 195 DownloadSet downloads_observed_; | 197 DownloadSet downloads_observed_; |
| 196 bool waiting_for_zero_inprogress_; | 198 bool waiting_for_zero_inprogress_; |
| 197 | 199 |
| 198 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); | 200 DISALLOW_COPY_AND_ASSIGN(DownloadTestFlushObserver); |
| 199 }; | 201 }; |
| 200 | 202 |
| 203 // Waits for a callback indicating that the DownloadItem is about to be created, | |
| 204 // or that an error occurred and it won't be created. | |
|
Randy Smith (Not in Mondays)
2012/03/01 21:17:24
Hmmm. Good point that we now have a new need for
ahendrickson
2012/03/02 17:34:39
I'll simplify it to only using one download, but I
| |
| 205 class DownloadTestItemCreationObserver | |
|
benjhayden
2012/03/01 19:48:53
This doesn't appear to be used in this CL. Could i
ahendrickson
2012/03/01 21:15:01
It was split off from CL 9426029, which uses it.
| |
| 206 : public base::RefCountedThreadSafe<DownloadTestItemCreationObserver> { | |
| 207 public: | |
| 208 struct CreationInfo { | |
| 209 CreationInfo() | |
| 210 : download_id(content::DownloadId::Invalid()), | |
| 211 error(net::OK) { | |
| 212 } | |
| 213 | |
| 214 content::DownloadId download_id; | |
| 215 net::Error error; | |
| 216 }; | |
| 217 | |
| 218 explicit DownloadTestItemCreationObserver(size_t count); | |
| 219 | |
| 220 void WaitForDownloadItemCreation(); | |
| 221 | |
| 222 void DownloadItemCreationCallback(content::DownloadId download_id, | |
| 223 net::Error error); | |
| 224 | |
| 225 content::DownloadId download_id(size_t index) const { | |
| 226 return creation_info_[index].download_id; | |
| 227 } | |
| 228 net::Error error(size_t index) const { return creation_info_[index].error; } | |
| 229 bool created(size_t index) const { | |
| 230 return (called_back_count_ > index) && | |
| 231 (creation_info_[index].error == net::OK); | |
| 232 } | |
| 233 size_t num_created() const { return called_back_count_; } | |
|
benjhayden
2012/03/01 19:48:53
This method's idea of creation is different from t
ahendrickson
2012/03/01 21:15:01
Renamed.
| |
| 234 | |
| 235 const content::DownloadManager::OnStartedCallback& callback() { | |
| 236 return callback_; | |
|
benjhayden
2012/03/01 19:48:53
Caching the callback seems unnecessary. It isn't e
ahendrickson
2012/03/01 21:15:01
It lets me make DownloadItemCreationCallback() pri
benjhayden
2012/03/02 20:27:16
You can keep that method private, and you can get
ahendrickson
2012/03/02 21:51:41
Ah, I didn't think of that.
Changed.
| |
| 237 } | |
| 238 | |
| 239 private: | |
| 240 friend class base::RefCountedThreadSafe<DownloadTestItemCreationObserver>; | |
| 241 | |
| 242 ~DownloadTestItemCreationObserver() {} | |
| 243 | |
| 244 // The download creation information we received. | |
| 245 std::vector<CreationInfo> creation_info_; | |
| 246 | |
| 247 // Expected number of callbacks. | |
| 248 size_t expected_count_; | |
| 249 | |
| 250 // Count of callbacks. | |
| 251 size_t called_back_count_; | |
| 252 | |
| 253 // We are in the message loop. | |
| 254 bool waiting_; | |
| 255 | |
| 256 // The callback to pass into |DownloadUrl()|. | |
| 257 const content::DownloadManager::OnStartedCallback callback_; | |
| 258 | |
| 259 DISALLOW_COPY_AND_ASSIGN(DownloadTestItemCreationObserver); | |
| 260 }; | |
| 261 | |
| 201 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ | 262 #endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TEST_OBSERVER_H_ |
| OLD | NEW |