OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browsing_data/downloads_counter.h" | 5 #include "chrome/browser/browsing_data/downloads_counter.h" |
6 | 6 |
7 #include "chrome/browser/download/download_history.h" | 7 #include "chrome/browser/download/download_history.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
8 #include "chrome/common/pref_names.h" | 9 #include "chrome/common/pref_names.h" |
9 #include "content/public/browser/download_manager.h" | 10 #include "content/public/browser/download_manager.h" |
10 | 11 |
11 DownloadsCounter::DownloadsCounter() | 12 DownloadsCounter::DownloadsCounter(Profile* profile) |
12 : pref_name_(prefs::kDeleteDownloadHistory) { | 13 : BrowsingDataCounter(prefs::kDeleteDownloadHistory), profile_(profile) {} |
13 } | |
14 | 14 |
15 DownloadsCounter::~DownloadsCounter() { | 15 DownloadsCounter::~DownloadsCounter() { |
16 } | 16 } |
17 | 17 |
18 const std::string& DownloadsCounter::GetPrefName() const { | |
19 return pref_name_; | |
20 } | |
21 | |
22 void DownloadsCounter::Count() { | 18 void DownloadsCounter::Count() { |
23 content::DownloadManager* download_manager = | 19 content::DownloadManager* download_manager = |
24 content::BrowserContext::GetDownloadManager(GetProfile()); | 20 content::BrowserContext::GetDownloadManager(profile_); |
25 std::vector<content::DownloadItem*> downloads; | 21 std::vector<content::DownloadItem*> downloads; |
26 download_manager->GetAllDownloads(&downloads); | 22 download_manager->GetAllDownloads(&downloads); |
27 base::Time begin_time = GetPeriodStart(); | 23 base::Time begin_time = GetPeriodStart(); |
28 | 24 |
29 ReportResult(std::count_if( | 25 ReportResult(std::count_if( |
30 downloads.begin(), | 26 downloads.begin(), |
31 downloads.end(), | 27 downloads.end(), |
32 [begin_time](const content::DownloadItem* item) { | 28 [begin_time](const content::DownloadItem* item) { |
33 return item->GetStartTime() >= begin_time && | 29 return item->GetStartTime() >= begin_time && |
34 DownloadHistory::IsPersisted(item); | 30 DownloadHistory::IsPersisted(item); |
35 })); | 31 })); |
36 } | 32 } |
OLD | NEW |