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

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: . Created 8 years, 3 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DCHECK_EQ(manager, download_manager_);
137 OnDownloadUpdated(item);
138
139 DownloadSet::const_iterator finished_it(finished_downloads_.find(item));
Randy Smith (Not in Mondays) 2012/09/11 18:36:53 How could item ever be in finished_downloads_ when
benjhayden 2012/09/13 15:18:16 OnDownloadUpdated() is called before this code. Th
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(FilePath(), &downloads); 164 download_manager_->GetAllDownloads(FilePath(), &downloads);
142 // As a test class, we're generally interested in whatever's there, 165 // As a test class, we're generally interested in whatever's there,
143 // so we include temporary downloads. 166 // so we include temporary downloads.
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 MessageLoopForUI::current()->Quit(); 402 MessageLoopForUI::current()->Quit();
380 } 403 }
381 404
382 const DownloadUrlParameters::OnStartedCallback 405 const DownloadUrlParameters::OnStartedCallback
383 DownloadTestItemCreationObserver::callback() { 406 DownloadTestItemCreationObserver::callback() {
384 return base::Bind( 407 return base::Bind(
385 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 408 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
386 } 409 }
387 410
388 } // namespace content 411 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698