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 #include "content/public/test/download_test_observer.h" | 5 #include "content/public/test/download_test_observer.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 | 124 |
| 125 default: | 125 default: |
| 126 NOTREACHED(); | 126 NOTREACHED(); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 if (IsDownloadInFinalState(download)) | 130 if (IsDownloadInFinalState(download)) |
| 131 DownloadInFinalState(download); | 131 DownloadInFinalState(download); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void DownloadTestObserver::OnDownloadCreated( | |
| 135 DownloadManager* manager, DownloadItem* item) { | |
| 136 item->AddObserver(this); | |
| 137 downloads_observed_.insert(item); | |
|
Randy Smith (Not in Mondays)
2012/08/28 13:11:49
Why the addition? I don't mind changing over, but
benjhayden
2012/09/10 19:02:56
Done.
| |
| 138 } | |
| 139 | |
| 134 void DownloadTestObserver::ModelChanged(DownloadManager* manager) { | 140 void DownloadTestObserver::ModelChanged(DownloadManager* manager) { |
| 135 DCHECK_EQ(manager, download_manager_); | 141 DCHECK_EQ(manager, download_manager_); |
| 136 | 142 |
| 137 // Regenerate DownloadItem observers. If there are any download items | 143 // Regenerate DownloadItem observers. If there are any download items |
| 138 // in our final state, note them in |finished_downloads_| | 144 // in our final state, note them in |finished_downloads_| |
| 139 // (done by |OnDownloadUpdated()|). | 145 // (done by |OnDownloadUpdated()|). |
| 140 std::vector<DownloadItem*> downloads; | 146 std::vector<DownloadItem*> downloads; |
| 141 download_manager_->GetAllDownloads(FilePath(), &downloads); | 147 download_manager_->GetAllDownloads(FilePath(), &downloads); |
| 142 // As a test class, we're generally interested in whatever's there, | 148 // As a test class, we're generally interested in whatever's there, |
| 143 // so we include temporary downloads. | 149 // so we include temporary downloads. |
| 144 download_manager_->GetTemporaryDownloads(FilePath(), &downloads); | 150 download_manager_->GetTemporaryDownloads(FilePath(), &downloads); |
| 145 | 151 |
| 146 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 152 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| 147 it != downloads.end(); ++it) { | 153 it != downloads.end(); ++it) { |
| 148 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. | 154 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. |
| 149 | 155 |
| 150 DownloadSet::const_iterator finished_it(finished_downloads_.find(*it)); | 156 DownloadSet::const_iterator finished_it(finished_downloads_.find(*it)); |
| 151 DownloadSet::iterator observed_it(downloads_observed_.find(*it)); | 157 DownloadSet::iterator observed_it(downloads_observed_.find(*it)); |
| 152 | 158 |
| 153 // If it isn't finished and we're aren't observing it, start. | 159 // If it isn't finished and we're aren't observing it, start. |
| 160 // Usually, OnDownloadCreated should have started observing it. | |
| 154 if (finished_it == finished_downloads_.end() && | 161 if (finished_it == finished_downloads_.end() && |
| 155 observed_it == downloads_observed_.end()) { | 162 observed_it == downloads_observed_.end()) { |
| 156 (*it)->AddObserver(this); | 163 (*it)->AddObserver(this); |
| 157 downloads_observed_.insert(*it); | 164 downloads_observed_.insert(*it); |
| 158 continue; | 165 continue; |
| 159 } | 166 } |
| 160 | 167 |
| 161 // If it is finished and we are observing it, stop. | 168 // If it is finished and we are observing it, stop. |
| 162 if (finished_it != finished_downloads_.end() && | 169 if (finished_it != finished_downloads_.end() && |
| 163 observed_it != downloads_observed_.end()) { | 170 observed_it != downloads_observed_.end()) { |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 379 MessageLoopForUI::current()->Quit(); | 386 MessageLoopForUI::current()->Quit(); |
| 380 } | 387 } |
| 381 | 388 |
| 382 const DownloadUrlParameters::OnStartedCallback | 389 const DownloadUrlParameters::OnStartedCallback |
| 383 DownloadTestItemCreationObserver::callback() { | 390 DownloadTestItemCreationObserver::callback() { |
| 384 return base::Bind( | 391 return base::Bind( |
| 385 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 392 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
| 386 } | 393 } |
| 387 | 394 |
| 388 } // namespace content | 395 } // namespace content |
| OLD | NEW |