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 "chrome/browser/download/download_status_updater.h" | 5 #include "chrome/browser/download/download_status_updater.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 bool DownloadStatusUpdater::GetProgress(float* progress, | 55 bool DownloadStatusUpdater::GetProgress(float* progress, |
56 int* download_count) const { | 56 int* download_count) const { |
57 *progress = 0; | 57 *progress = 0; |
58 *download_count = 0; | 58 *download_count = 0; |
59 bool progress_certain = true; | 59 bool progress_certain = true; |
60 int64 received_bytes = 0; | 60 int64 received_bytes = 0; |
61 int64 total_bytes = 0; | 61 int64 total_bytes = 0; |
62 | 62 |
63 for (std::vector<HyperbolicDownloadItemNotifier*>::const_iterator it = | 63 for (std::vector<AllDownloadItemNotifier*>::const_iterator it = |
64 notifiers_.begin(); it != notifiers_.end(); ++it) { | 64 notifiers_.begin(); it != notifiers_.end(); ++it) { |
65 if ((*it)->GetManager()) { | 65 if ((*it)->GetManager()) { |
66 content::DownloadManager::DownloadVector items; | 66 content::DownloadManager::DownloadVector items; |
67 (*it)->GetManager()->GetAllDownloads(&items); | 67 (*it)->GetManager()->GetAllDownloads(&items); |
68 for (content::DownloadManager::DownloadVector::const_iterator it = | 68 for (content::DownloadManager::DownloadVector::const_iterator it = |
69 items.begin(); it != items.end(); ++it) { | 69 items.begin(); it != items.end(); ++it) { |
70 if ((*it)->IsInProgress()) { | 70 if ((*it)->IsInProgress()) { |
71 ++*download_count; | 71 ++*download_count; |
72 if ((*it)->GetTotalBytes() <= 0) { | 72 if ((*it)->GetTotalBytes() <= 0) { |
73 // There may or may not be more data coming down this pipe. | 73 // There may or may not be more data coming down this pipe. |
74 progress_certain = false; | 74 progress_certain = false; |
75 } else { | 75 } else { |
76 received_bytes += (*it)->GetReceivedBytes(); | 76 received_bytes += (*it)->GetReceivedBytes(); |
77 total_bytes += (*it)->GetTotalBytes(); | 77 total_bytes += (*it)->GetTotalBytes(); |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 if (total_bytes > 0) | 84 if (total_bytes > 0) |
85 *progress = static_cast<float>(received_bytes) / total_bytes; | 85 *progress = static_cast<float>(received_bytes) / total_bytes; |
86 return progress_certain; | 86 return progress_certain; |
87 } | 87 } |
88 | 88 |
89 void DownloadStatusUpdater::AddManager(content::DownloadManager* manager) { | 89 void DownloadStatusUpdater::AddManager(content::DownloadManager* manager) { |
90 notifiers_.push_back(new HyperbolicDownloadItemNotifier(manager, this)); | 90 notifiers_.push_back(new AllDownloadItemNotifier(manager, this)); |
91 content::DownloadManager::DownloadVector items; | 91 content::DownloadManager::DownloadVector items; |
92 manager->GetAllDownloads(&items); | 92 manager->GetAllDownloads(&items); |
93 for (content::DownloadManager::DownloadVector::const_iterator | 93 for (content::DownloadManager::DownloadVector::const_iterator |
94 it = items.begin(); it != items.end(); ++it) { | 94 it = items.begin(); it != items.end(); ++it) { |
95 OnDownloadCreated(manager, *it); | 95 OnDownloadCreated(manager, *it); |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 void DownloadStatusUpdater::OnDownloadCreated( | 99 void DownloadStatusUpdater::OnDownloadCreated( |
100 content::DownloadManager* manager, content::DownloadItem* item) { | 100 content::DownloadManager* manager, content::DownloadItem* item) { |
(...skipping 29 matching lines...) Expand all Loading... |
130 UpdateAppIconDownloadProgress(item); | 130 UpdateAppIconDownloadProgress(item); |
131 } | 131 } |
132 | 132 |
133 #if defined(USE_AURA) || defined(OS_ANDROID) | 133 #if defined(USE_AURA) || defined(OS_ANDROID) |
134 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( | 134 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( |
135 content::DownloadItem* download) { | 135 content::DownloadItem* download) { |
136 // TODO(davemoore): Implement once UX for aura download is decided <104742> | 136 // TODO(davemoore): Implement once UX for aura download is decided <104742> |
137 // TODO(avi): Implement for Android? | 137 // TODO(avi): Implement for Android? |
138 } | 138 } |
139 #endif | 139 #endif |
OLD | NEW |