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

Side by Side Diff: chrome/browser/ui/webui/active_downloads_ui.cc

Issue 8503018: Split DownloadItem into an ABC, an Impl, and a Mock. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: CamelCase Created 9 years, 1 month 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/webui/active_downloads_ui.h" 5 #include "chrome/browser/ui/webui/active_downloads_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 download_manager_->GetAllDownloads(FilePath(), &downloads); 282 download_manager_->GetAllDownloads(FilePath(), &downloads);
283 active_downloads_.clear(); 283 active_downloads_.clear();
284 for (size_t i = 0; i < downloads.size(); ++i) { 284 for (size_t i = 0; i < downloads.size(); ++i) {
285 AddDownload(downloads[i]); 285 AddDownload(downloads[i]);
286 } 286 }
287 SendDownloads(); 287 SendDownloads();
288 } 288 }
289 289
290 void ActiveDownloadsHandler::AddDownload(DownloadItem* item) { 290 void ActiveDownloadsHandler::AddDownload(DownloadItem* item) {
291 // Observe in progress and dangerous downloads. 291 // Observe in progress and dangerous downloads.
292 if (item->state() == DownloadItem::IN_PROGRESS || 292 if (item->GetState() == DownloadItem::IN_PROGRESS ||
293 item->safety_state() == DownloadItem::DANGEROUS) { 293 item->GetSafetyState() == DownloadItem::DANGEROUS) {
294 active_downloads_.push_back(item); 294 active_downloads_.push_back(item);
295 295
296 DownloadList::const_iterator it = 296 DownloadList::const_iterator it =
297 std::find(downloads_.begin(), downloads_.end(), item); 297 std::find(downloads_.begin(), downloads_.end(), item);
298 if (it == downloads_.end()) { 298 if (it == downloads_.end()) {
299 downloads_.push_back(item); 299 downloads_.push_back(item);
300 item->AddObserver(this); 300 item->AddObserver(this);
301 } 301 }
302 } 302 }
303 } 303 }
304 304
305 void ActiveDownloadsHandler::SendDownloads() { 305 void ActiveDownloadsHandler::SendDownloads() {
306 ListValue results; 306 ListValue results;
307 for (size_t i = 0; i < downloads_.size(); ++i) { 307 for (size_t i = 0; i < downloads_.size(); ++i) {
308 results.Append(download_util::CreateDownloadItemValue(downloads_[i], i)); 308 results.Append(download_util::CreateDownloadItemValue(downloads_[i], i));
309 } 309 }
310 310
311 web_ui_->CallJavascriptFunction("downloadsList", results); 311 web_ui_->CallJavascriptFunction("downloadsList", results);
312 } 312 }
313 313
314 void ActiveDownloadsHandler::OnDownloadUpdated(DownloadItem* item) { 314 void ActiveDownloadsHandler::OnDownloadUpdated(DownloadItem* item) {
315 DownloadList::iterator it = 315 DownloadList::iterator it =
316 find(downloads_.begin(), downloads_.end(), item); 316 find(downloads_.begin(), downloads_.end(), item);
317 317
318 if (it == downloads_.end()) { 318 if (it == downloads_.end()) {
319 NOTREACHED() << "Updated item " << item->full_path().value() 319 NOTREACHED() << "Updated item " << item->GetFullPath().value()
320 << " not found"; 320 << " not found";
321 } 321 }
322 322
323 if (item->state() == DownloadItem::REMOVING || item->auto_opened()) { 323 if (item->GetState() == DownloadItem::REMOVING || item->GetAutoOpened()) {
324 // Item is going away, or item is an extension that has auto opened. 324 // Item is going away, or item is an extension that has auto opened.
325 item->RemoveObserver(this); 325 item->RemoveObserver(this);
326 downloads_.erase(it); 326 downloads_.erase(it);
327 DownloadList::iterator ita = 327 DownloadList::iterator ita =
328 find(active_downloads_.begin(), active_downloads_.end(), item); 328 find(active_downloads_.begin(), active_downloads_.end(), item);
329 if (ita != active_downloads_.end()) 329 if (ita != active_downloads_.end())
330 active_downloads_.erase(ita); 330 active_downloads_.erase(ita);
331 SendDownloads(); 331 SendDownloads();
332 } else { 332 } else {
333 const size_t id = it - downloads_.begin(); 333 const size_t id = it - downloads_.begin();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } 428 }
429 } 429 }
430 } 430 }
431 return NULL; 431 return NULL;
432 } 432 }
433 #endif // defined(TOUCH_UI) 433 #endif // defined(TOUCH_UI)
434 434
435 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { 435 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const {
436 return handler_->downloads(); 436 return handler_->downloads();
437 } 437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698