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

Side by Side Diff: chrome/browser/download/download_status_updater.cc

Issue 2457923002: Remove stl_util's deletion function use and ScopedVector from chrome/browser/download/. (Closed)
Patch Set: extra clear Created 4 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
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 "chrome/browser/download/download_status_updater.h" 5 #include "chrome/browser/download/download_status_updater.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/stl_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "build/build_config.h" 14 #include "build/build_config.h"
15 15
16 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) 16 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
17 #include "ui/views/linux_ui/linux_ui.h" 17 #include "ui/views/linux_ui/linux_ui.h"
18 #endif 18 #endif
19 19
20 namespace { 20 namespace {
21 21
22 // DownloadStatusUpdater::UpdateAppIconDownloadProgress() expects to only be 22 // DownloadStatusUpdater::UpdateAppIconDownloadProgress() expects to only be
23 // called once when a DownloadItem completes, then not again (except perhaps 23 // called once when a DownloadItem completes, then not again (except perhaps
(...skipping 25 matching lines...) Expand all
49 49
50 const char WasInProgressData::kKey[] = 50 const char WasInProgressData::kKey[] =
51 "DownloadItem DownloadStatusUpdater WasInProgressData"; 51 "DownloadItem DownloadStatusUpdater WasInProgressData";
52 52
53 } // anonymous namespace 53 } // anonymous namespace
54 54
55 DownloadStatusUpdater::DownloadStatusUpdater() { 55 DownloadStatusUpdater::DownloadStatusUpdater() {
56 } 56 }
57 57
58 DownloadStatusUpdater::~DownloadStatusUpdater() { 58 DownloadStatusUpdater::~DownloadStatusUpdater() {
59 base::STLDeleteElements(&notifiers_);
60 } 59 }
61 60
62 bool DownloadStatusUpdater::GetProgress(float* progress, 61 bool DownloadStatusUpdater::GetProgress(float* progress,
63 int* download_count) const { 62 int* download_count) const {
64 *progress = 0; 63 *progress = 0;
65 *download_count = 0; 64 *download_count = 0;
66 bool progress_certain = true; 65 bool progress_certain = true;
67 int64_t received_bytes = 0; 66 int64_t received_bytes = 0;
68 int64_t total_bytes = 0; 67 int64_t total_bytes = 0;
69 68
70 for (std::vector<AllDownloadItemNotifier*>::const_iterator it = 69 for (const auto& notifier : notifiers_) {
71 notifiers_.begin(); it != notifiers_.end(); ++it) { 70 if (notifier->GetManager()) {
72 if ((*it)->GetManager()) {
73 content::DownloadManager::DownloadVector items; 71 content::DownloadManager::DownloadVector items;
74 (*it)->GetManager()->GetAllDownloads(&items); 72 notifier->GetManager()->GetAllDownloads(&items);
75 for (content::DownloadManager::DownloadVector::const_iterator it = 73 for (auto item : items) {
sky 2016/10/28 13:33:59 auto*
Avi (use Gerrit) 2016/10/28 14:04:10 Done.
76 items.begin(); it != items.end(); ++it) { 74 if (item->GetState() == content::DownloadItem::IN_PROGRESS) {
77 if ((*it)->GetState() == content::DownloadItem::IN_PROGRESS) {
78 ++*download_count; 75 ++*download_count;
79 if ((*it)->GetTotalBytes() <= 0) { 76 if (item->GetTotalBytes() <= 0) {
80 // There may or may not be more data coming down this pipe. 77 // There may or may not be more data coming down this pipe.
81 progress_certain = false; 78 progress_certain = false;
82 } else { 79 } else {
83 received_bytes += (*it)->GetReceivedBytes(); 80 received_bytes += item->GetReceivedBytes();
84 total_bytes += (*it)->GetTotalBytes(); 81 total_bytes += item->GetTotalBytes();
85 } 82 }
86 } 83 }
87 } 84 }
88 } 85 }
89 } 86 }
90 87
91 if (total_bytes > 0) 88 if (total_bytes > 0)
92 *progress = static_cast<float>(received_bytes) / total_bytes; 89 *progress = static_cast<float>(received_bytes) / total_bytes;
93 return progress_certain; 90 return progress_certain;
94 } 91 }
95 92
96 void DownloadStatusUpdater::AddManager(content::DownloadManager* manager) { 93 void DownloadStatusUpdater::AddManager(content::DownloadManager* manager) {
97 notifiers_.push_back(new AllDownloadItemNotifier(manager, this)); 94 notifiers_.push_back(
95 base::MakeUnique<AllDownloadItemNotifier>(manager, this));
98 content::DownloadManager::DownloadVector items; 96 content::DownloadManager::DownloadVector items;
99 manager->GetAllDownloads(&items); 97 manager->GetAllDownloads(&items);
100 for (content::DownloadManager::DownloadVector::const_iterator 98 for (auto item : items) {
sky 2016/10/28 13:33:59 no {} and auto*
Avi (use Gerrit) 2016/10/28 14:04:10 Done.
101 it = items.begin(); it != items.end(); ++it) { 99 OnDownloadCreated(manager, item);
102 OnDownloadCreated(manager, *it);
103 } 100 }
104 } 101 }
105 102
106 void DownloadStatusUpdater::OnDownloadCreated( 103 void DownloadStatusUpdater::OnDownloadCreated(
107 content::DownloadManager* manager, content::DownloadItem* item) { 104 content::DownloadManager* manager, content::DownloadItem* item) {
108 // Ignore downloads loaded from history, which are in a terminal state. 105 // Ignore downloads loaded from history, which are in a terminal state.
109 // TODO(benjhayden): Use the Observer interface to distinguish between 106 // TODO(benjhayden): Use the Observer interface to distinguish between
110 // historical and started downloads. 107 // historical and started downloads.
111 if (item->GetState() == content::DownloadItem::IN_PROGRESS) { 108 if (item->GetState() == content::DownloadItem::IN_PROGRESS) {
112 UpdateAppIconDownloadProgress(item); 109 UpdateAppIconDownloadProgress(item);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 float progress = 0; 143 float progress = 0;
147 int download_count = 0; 144 int download_count = 0;
148 GetProgress(&progress, &download_count); 145 GetProgress(&progress, &download_count);
149 linux_ui->SetDownloadCount(download_count); 146 linux_ui->SetDownloadCount(download_count);
150 linux_ui->SetProgressFraction(progress); 147 linux_ui->SetProgressFraction(progress);
151 } 148 }
152 #endif 149 #endif
153 // TODO(avi): Implement for Android? 150 // TODO(avi): Implement for Android?
154 } 151 }
155 #endif 152 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698