Chromium Code Reviews| Index: chrome/browser/browsing_data/site_data_size_collector.cc |
| diff --git a/chrome/browser/browsing_data/site_data_size_collector.cc b/chrome/browser/browsing_data/site_data_size_collector.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b355b2864abacd87058004a1a99e84046c4a52c0 |
| --- /dev/null |
| +++ b/chrome/browser/browsing_data/site_data_size_collector.cc |
| @@ -0,0 +1,216 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/browsing_data/site_data_size_collector.h" |
| + |
| +#include "base/files/file_util.h" |
| +#include "chrome/common/chrome_constants.h" |
| +#include "chrome/common/pref_names.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/common/content_constants.h" |
| + |
| +SiteDataSizeCollector::SiteDataSizeCollector( |
| + const base::FilePath& default_storage_partition_path, |
| + BrowsingDataCookieHelper* cookie_helper, |
| + BrowsingDataDatabaseHelper* database_helper, |
| + BrowsingDataLocalStorageHelper* local_storage_helper, |
| + BrowsingDataAppCacheHelper* appcache_helper, |
| + BrowsingDataIndexedDBHelper* indexed_db_helper, |
| + BrowsingDataFileSystemHelper* file_system_helper, |
| + BrowsingDataChannelIDHelper* channel_id_helper, |
| + BrowsingDataServiceWorkerHelper* service_worker_helper, |
| + BrowsingDataCacheStorageHelper* cache_storage_helper, |
| + BrowsingDataFlashLSOHelper* flash_lso_helper) |
| + : default_storage_partition_path_(default_storage_partition_path), |
| + appcache_helper_(appcache_helper), |
| + cookie_helper_(cookie_helper), |
| + database_helper_(database_helper), |
| + local_storage_helper_(local_storage_helper), |
| + indexed_db_helper_(indexed_db_helper), |
| + file_system_helper_(file_system_helper), |
| + channel_id_helper_(channel_id_helper), |
| + service_worker_helper_(service_worker_helper), |
| + cache_storage_helper_(cache_storage_helper), |
| + flash_lso_helper_(flash_lso_helper), |
| + in_flight_operations_(0), |
| + total_bytes_(0), |
| + weak_ptr_factory_(this) {} |
| + |
| +SiteDataSizeCollector::~SiteDataSizeCollector() { |
| +} |
| + |
| +void SiteDataSizeCollector::Fetch(const FetchCallback& callback) { |
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| + DCHECK(!callback.is_null()); |
| + |
| + fetch_callback_ = callback; |
| + total_bytes_ = 0; |
| + in_flight_operations_ = 0; |
| + |
| + if (appcache_helper_.get()) { |
| + appcache_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnAppCacheModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (cookie_helper_.get()) { |
| + cookie_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnCookiesModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (database_helper_.get()) { |
| + database_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnDatabaseModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (local_storage_helper_.get()) { |
| + local_storage_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnLocalStorageModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (indexed_db_helper_.get()) { |
| + indexed_db_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnIndexedDBModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (file_system_helper_.get()) { |
| + file_system_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnFileSystemModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (channel_id_helper_.get()) { |
| + channel_id_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnChannelIDModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (service_worker_helper_.get()) { |
| + service_worker_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnServiceWorkerModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (cache_storage_helper_.get()) { |
| + cache_storage_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnCacheStorageModelInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| + if (flash_lso_helper_.get()) { |
| + flash_lso_helper_->StartFetching( |
| + base::Bind(&SiteDataSizeCollector::OnFlashLSOInfoLoaded, |
| + weak_ptr_factory_.GetWeakPtr())); |
| + in_flight_operations_++; |
| + } |
| +} |
| + |
| +void SiteDataSizeCollector::OnAppCacheModelInfoLoaded( |
| + scoped_refptr<content::AppCacheInfoCollection> appcache_info) { |
| + int64_t total_size = 0; |
| + if (appcache_info.get()) { |
| + for (const auto& origin : appcache_info->infos_by_origin) { |
| + for (const auto& info : origin.second) |
| + total_size += info.size; |
| + } |
| + } |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnCookiesModelInfoLoaded( |
| + const net::CookieList& cookie_list) { |
| + int64_t size = 0; |
|
msramek
2016/06/30 13:58:11
nit: Please use |size| or |total_size| in all meth
fukino
2016/06/30 16:16:13
Done.
|
| + if (!cookie_list.empty()) { |
| + // Consider cookie file size only when at least one cookie is found. |
| + base::FilePath cookie_file_path = default_storage_partition_path_ |
| + .Append(chrome::kCookieFilename); |
| + base::GetFileSize(cookie_file_path, &size); |
|
msramek
2016/06/30 13:58:11
This callback is on the IO thread, right? Can you
fukino
2016/06/30 16:16:12
Oops! OnCookiesModelInfoLoaded is called UI thread
|
| + } |
| + OnStorageSizeFetched(size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnDatabaseModelInfoLoaded( |
| + const DatabaseInfoList& database_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& database_info : database_info_list) |
| + total_size += database_info.size; |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnLocalStorageModelInfoLoaded( |
| + const LocalStorageInfoList& local_storage_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& local_storage_info : local_storage_info_list) |
| + total_size += local_storage_info.size; |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnIndexedDBModelInfoLoaded( |
| + const std::list<content::IndexedDBInfo>& indexed_db_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& indexed_db_info : indexed_db_info_list) |
| + total_size += indexed_db_info.size; |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnFileSystemModelInfoLoaded( |
| + const FileSystemInfoList& file_system_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& file_system_info : file_system_info_list) { |
| + for (const auto& usage : file_system_info.usage_map) |
| + total_size += usage.second; |
| + } |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnChannelIDModelInfoLoaded( |
| + const ChannelIDList& channel_id_list) { |
| + int64_t size = 0; |
| + if (!channel_id_list.empty()) { |
| + // Consider channel id file size only when at least one channel id is found. |
| + base::FilePath channel_id_file_path = default_storage_partition_path_ |
| + .Append(chrome::kChannelIDFilename); |
| + base::GetFileSize(channel_id_file_path, &size); |
|
msramek
2016/06/30 13:58:11
Ditto here.
fukino
2016/06/30 16:16:12
Done.
|
| + } |
| + OnStorageSizeFetched(size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnServiceWorkerModelInfoLoaded( |
| + const ServiceWorkerUsageInfoList& service_worker_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& service_worker_info : service_worker_info_list) |
| + total_size += service_worker_info.total_size_bytes; |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnCacheStorageModelInfoLoaded( |
| + const CacheStorageUsageInfoList& cache_storage_info_list) { |
| + int64_t total_size = 0; |
| + for (const auto& cache_storage_info : cache_storage_info_list) |
| + total_size += cache_storage_info.total_size_bytes; |
| + OnStorageSizeFetched(total_size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnFlashLSOInfoLoaded( |
| + const FlashLSODomainList& domains) { |
| + int64_t size = 0; |
| + if (!domains.empty()) { |
| + // Consider pepper data directory size only when at least one Flash LSO is |
|
msramek
2016/06/30 13:58:10
Flash is not the only plugin; shouldn't we check i
fukino
2016/06/30 16:16:13
I could not find out what types of plugin data exi
|
| + // found. |
| + base::FilePath pepper_data_dir_path = default_storage_partition_path_ |
|
msramek
2016/06/30 13:58:10
And here.
fukino
2016/06/30 16:16:13
Done.
|
| + .Append(content::kPepperDataDirname); |
| + size = base::ComputeDirectorySize(pepper_data_dir_path); |
| + } |
| + OnStorageSizeFetched(size); |
| +} |
| + |
| +void SiteDataSizeCollector::OnStorageSizeFetched(int64_t size) { |
| + total_bytes_ += size; |
| + if (--in_flight_operations_ == 0) |
| + fetch_callback_.Run(total_bytes_); |
| +} |