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( | |
|
Randy Smith (Not in Mondays)
2012/09/13 19:53:19
It seems wrong to use *both* OnDownloadCreated() a
benjhayden
2012/09/21 20:45:46
Done.
| |
| 135 DownloadManager* manager, DownloadItem* item) { | |
| 136 DCHECK_EQ(manager, download_manager_); | |
| 137 OnDownloadUpdated(item); | |
| 138 | |
| 139 DownloadSet::const_iterator finished_it(finished_downloads_.find(item)); | |
| 140 DownloadSet::iterator observed_it(downloads_observed_.find(item)); | |
| 141 | |
| 142 // If it isn't finished and we're aren't observing it, start. | |
| 143 if (finished_it == finished_downloads_.end() && | |
| 144 observed_it == downloads_observed_.end()) { | |
| 145 item->AddObserver(this); | |
| 146 downloads_observed_.insert(item); | |
| 147 } | |
| 148 | |
| 149 // If it is finished and we are observing it, stop. | |
| 150 if (finished_it != finished_downloads_.end() && | |
| 151 observed_it != downloads_observed_.end()) { | |
| 152 item->RemoveObserver(this); | |
| 153 downloads_observed_.erase(observed_it); | |
| 154 } | |
| 155 } | |
| 156 | |
| 134 void DownloadTestObserver::ModelChanged(DownloadManager* manager) { | 157 void DownloadTestObserver::ModelChanged(DownloadManager* manager) { |
| 135 DCHECK_EQ(manager, download_manager_); | 158 DCHECK_EQ(manager, download_manager_); |
| 136 | 159 |
| 137 // Regenerate DownloadItem observers. If there are any download items | 160 // Regenerate DownloadItem observers. If there are any download items |
| 138 // in our final state, note them in |finished_downloads_| | 161 // in our final state, note them in |finished_downloads_| |
| 139 // (done by |OnDownloadUpdated()|). | 162 // (done by |OnDownloadUpdated()|). |
| 140 std::vector<DownloadItem*> downloads; | 163 std::vector<DownloadItem*> downloads; |
| 141 download_manager_->GetAllDownloads(&downloads); | 164 download_manager_->GetAllDownloads(&downloads); |
| 142 | 165 |
| 143 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); | 166 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 376 MessageLoopForUI::current()->Quit(); | 399 MessageLoopForUI::current()->Quit(); |
| 377 } | 400 } |
| 378 | 401 |
| 379 const DownloadUrlParameters::OnStartedCallback | 402 const DownloadUrlParameters::OnStartedCallback |
| 380 DownloadTestItemCreationObserver::callback() { | 403 DownloadTestItemCreationObserver::callback() { |
| 381 return base::Bind( | 404 return base::Bind( |
| 382 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); | 405 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); |
| 383 } | 406 } |
| 384 | 407 |
| 385 } // namespace content | 408 } // namespace content |
| OLD | NEW |