OLD | NEW |
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 download_manager_->GetAllDownloads(FilePath(), &downloads); | 293 download_manager_->GetAllDownloads(FilePath(), &downloads); |
294 active_downloads_.clear(); | 294 active_downloads_.clear(); |
295 for (size_t i = 0; i < downloads.size(); ++i) { | 295 for (size_t i = 0; i < downloads.size(); ++i) { |
296 AddDownload(downloads[i]); | 296 AddDownload(downloads[i]); |
297 } | 297 } |
298 SendDownloads(); | 298 SendDownloads(); |
299 } | 299 } |
300 | 300 |
301 void ActiveDownloadsHandler::AddDownload(DownloadItem* item) { | 301 void ActiveDownloadsHandler::AddDownload(DownloadItem* item) { |
302 // Observe in progress and dangerous downloads. | 302 // Observe in progress and dangerous downloads. |
303 if (item->state() == DownloadItem::IN_PROGRESS || | 303 if (item->GetState() == DownloadItem::IN_PROGRESS || |
304 item->safety_state() == DownloadItem::DANGEROUS) { | 304 item->GetSafetyState() == DownloadItem::DANGEROUS) { |
305 active_downloads_.push_back(item); | 305 active_downloads_.push_back(item); |
306 | 306 |
307 DownloadList::const_iterator it = | 307 DownloadList::const_iterator it = |
308 std::find(downloads_.begin(), downloads_.end(), item); | 308 std::find(downloads_.begin(), downloads_.end(), item); |
309 if (it == downloads_.end()) { | 309 if (it == downloads_.end()) { |
310 downloads_.push_back(item); | 310 downloads_.push_back(item); |
311 item->AddObserver(this); | 311 item->AddObserver(this); |
312 } | 312 } |
313 } | 313 } |
314 } | 314 } |
315 | 315 |
316 void ActiveDownloadsHandler::SendDownloads() { | 316 void ActiveDownloadsHandler::SendDownloads() { |
317 ListValue results; | 317 ListValue results; |
318 for (size_t i = 0; i < downloads_.size(); ++i) { | 318 for (size_t i = 0; i < downloads_.size(); ++i) { |
319 results.Append(download_util::CreateDownloadItemValue(downloads_[i], i)); | 319 results.Append(download_util::CreateDownloadItemValue(downloads_[i], i)); |
320 } | 320 } |
321 | 321 |
322 web_ui_->CallJavascriptFunction("downloadsList", results); | 322 web_ui_->CallJavascriptFunction("downloadsList", results); |
323 } | 323 } |
324 | 324 |
325 void ActiveDownloadsHandler::OnDownloadUpdated(DownloadItem* item) { | 325 void ActiveDownloadsHandler::OnDownloadUpdated(DownloadItem* item) { |
326 DownloadList::iterator it = | 326 DownloadList::iterator it = |
327 find(downloads_.begin(), downloads_.end(), item); | 327 find(downloads_.begin(), downloads_.end(), item); |
328 | 328 |
329 if (it == downloads_.end()) { | 329 if (it == downloads_.end()) { |
330 NOTREACHED() << "Updated item " << item->full_path().value() | 330 NOTREACHED() << "Updated item " << item->GetFullPath().value() |
331 << " not found"; | 331 << " not found"; |
332 } | 332 } |
333 | 333 |
334 if (item->state() == DownloadItem::REMOVING || item->auto_opened()) { | 334 if (item->GetState() == DownloadItem::REMOVING || item->GetAutoOpened()) { |
335 // Item is going away, or item is an extension that has auto opened. | 335 // Item is going away, or item is an extension that has auto opened. |
336 item->RemoveObserver(this); | 336 item->RemoveObserver(this); |
337 downloads_.erase(it); | 337 downloads_.erase(it); |
338 DownloadList::iterator ita = | 338 DownloadList::iterator ita = |
339 find(active_downloads_.begin(), active_downloads_.end(), item); | 339 find(active_downloads_.begin(), active_downloads_.end(), item); |
340 if (ita != active_downloads_.end()) | 340 if (ita != active_downloads_.end()) |
341 active_downloads_.erase(ita); | 341 active_downloads_.erase(ita); |
342 SendDownloads(); | 342 SendDownloads(); |
343 } else { | 343 } else { |
344 const size_t id = it - downloads_.begin(); | 344 const size_t id = it - downloads_.begin(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 } | 439 } |
440 } | 440 } |
441 } | 441 } |
442 return NULL; | 442 return NULL; |
443 } | 443 } |
444 #endif // defined(TOUCH_UI) | 444 #endif // defined(TOUCH_UI) |
445 | 445 |
446 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { | 446 const ActiveDownloadsUI::DownloadList& ActiveDownloadsUI::GetDownloads() const { |
447 return handler_->downloads(); | 447 return handler_->downloads(); |
448 } | 448 } |
OLD | NEW |