Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: content/public/test/download_test_observer.cc

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r159248 Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 DownloadTestObserver::~DownloadTestObserver() { 102 DownloadTestObserver::~DownloadTestObserver() {
103 for (DownloadSet::iterator it = downloads_observed_.begin(); 103 for (DownloadSet::iterator it = downloads_observed_.begin();
104 it != downloads_observed_.end(); ++it) 104 it != downloads_observed_.end(); ++it)
105 (*it)->RemoveObserver(this); 105 (*it)->RemoveObserver(this);
106 106
107 download_manager_->RemoveObserver(this); 107 download_manager_->RemoveObserver(this);
108 } 108 }
109 109
110 void DownloadTestObserver::Init() { 110 void DownloadTestObserver::Init() {
111 download_manager_->AddObserver(this); 111 download_manager_->AddObserver(this);
112 // Regenerate DownloadItem observers. If there are any download items
113 // in our final state, note them in |finished_downloads_|
114 // (done by |OnDownloadUpdated()|).
115 std::vector<DownloadItem*> downloads; 112 std::vector<DownloadItem*> downloads;
116 download_manager_->GetAllDownloads(&downloads); 113 download_manager_->GetAllDownloads(&downloads);
117
118 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); 114 for (std::vector<DownloadItem*>::iterator it = downloads.begin();
119 it != downloads.end(); ++it) { 115 it != downloads.end(); ++it) {
120 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. 116 OnDownloadCreated(download_manager_, *it);
121
122 DownloadSet::const_iterator finished_it(finished_downloads_.find(*it));
123 DownloadSet::iterator observed_it(downloads_observed_.find(*it));
124
125 // If it isn't finished and we're aren't observing it, start.
126 if (finished_it == finished_downloads_.end() &&
127 observed_it == downloads_observed_.end()) {
128 (*it)->AddObserver(this);
129 downloads_observed_.insert(*it);
130 }
131 } 117 }
132 finished_downloads_at_construction_ = finished_downloads_.size(); 118 finished_downloads_at_construction_ = finished_downloads_.size();
133 states_observed_.clear(); 119 states_observed_.clear();
134 } 120 }
135 121
136 void DownloadTestObserver::WaitForFinished() { 122 void DownloadTestObserver::WaitForFinished() {
137 if (!IsFinished()) { 123 if (!IsFinished()) {
138 waiting_ = true; 124 waiting_ = true;
139 RunMessageLoop(); 125 RunMessageLoop();
140 waiting_ = false; 126 waiting_ = false;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 NOTREACHED(); 176 NOTREACHED();
191 } 177 }
192 } 178 }
193 179
194 if (IsDownloadInFinalState(download)) 180 if (IsDownloadInFinalState(download))
195 DownloadInFinalState(download); 181 DownloadInFinalState(download);
196 } 182 }
197 183
198 void DownloadTestObserver::OnDownloadCreated( 184 void DownloadTestObserver::OnDownloadCreated(
199 DownloadManager* manager, DownloadItem* item) { 185 DownloadManager* manager, DownloadItem* item) {
186 DCHECK_EQ(manager, download_manager_);
200 OnDownloadUpdated(item); 187 OnDownloadUpdated(item);
188
201 DownloadSet::const_iterator finished_it(finished_downloads_.find(item)); 189 DownloadSet::const_iterator finished_it(finished_downloads_.find(item));
202 DownloadSet::iterator observed_it(downloads_observed_.find(item)); 190 DownloadSet::iterator observed_it(downloads_observed_.find(item));
203 191
204 // If it isn't finished and we're aren't observing it, start. 192 // If it isn't finished and we're aren't observing it, start.
205 if (finished_it == finished_downloads_.end() && 193 if (finished_it == finished_downloads_.end() &&
206 observed_it == downloads_observed_.end()) { 194 observed_it == downloads_observed_.end()) {
207 item->AddObserver(this); 195 item->AddObserver(this);
208 downloads_observed_.insert(item); 196 downloads_observed_.insert(item);
209 } 197 }
210 } 198 }
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 MessageLoopForUI::current()->Quit(); 409 MessageLoopForUI::current()->Quit();
422 } 410 }
423 411
424 const DownloadUrlParameters::OnStartedCallback 412 const DownloadUrlParameters::OnStartedCallback
425 DownloadTestItemCreationObserver::callback() { 413 DownloadTestItemCreationObserver::callback() {
426 return base::Bind( 414 return base::Bind(
427 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 415 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
428 } 416 }
429 417
430 } // namespace content 418 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698