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..51709fb51c046ecef045667c03a479441bf9aeb3 |
--- /dev/null |
+++ b/chrome/browser/browsing_data/site_data_size_collector.cc |
@@ -0,0 +1,211 @@ |
+// 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(Profile* profile) |
+ : profile_(profile) |
+ , storage_partition_(nullptr) |
+ , in_flight_operations_(0) |
+ , total_bytes_(0) |
+ , weak_ptr_factory_(this) { |
+} |
+ |
+SiteDataSizeCollector::~SiteDataSizeCollector() { |
+} |
+ |
+void SiteDataSizeCollector::Fetch(const FetchCallback& callback) { |
msramek
2016/06/23 21:30:35
Looking at BrowsingDataRemover::REMOVE_SITE_DATA,
fukino
2016/06/30 09:21:24
I'll include SITE_USAGE_DATA and WEB_APP_DATA, and
msramek
2016/06/30 13:58:10
Sounds good. Please add a TODO or file a bug for t
|
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
+ DCHECK(!callback.is_null()); |
+ |
+ fetch_callback_ = callback; |
+ total_bytes_ = 0; |
+ in_flight_operations_ = 0; |
+ |
+ storage_partition_ = |
+ content::BrowserContext::GetDefaultStoragePartition(profile_); |
+ appcache_helper_ = new BrowsingDataAppCacheHelper(profile_); |
+ cookie_helper_ = new BrowsingDataCookieHelper( |
+ profile_->GetRequestContext()); |
+ database_helper_ = new BrowsingDataDatabaseHelper(profile_); |
+ local_storage_helper_ = new BrowsingDataLocalStorageHelper(profile_); |
+ indexed_db_helper_ = new BrowsingDataIndexedDBHelper( |
+ storage_partition_->GetIndexedDBContext()); |
+ file_system_helper_ = BrowsingDataFileSystemHelper::Create( |
+ storage_partition_->GetFileSystemContext()); |
+ quota_helper_ = BrowsingDataQuotaHelper::Create(profile_); |
+ channel_id_helper_ = BrowsingDataChannelIDHelper::Create( |
+ profile_->GetRequestContext()); |
+ service_worker_helper_ = new BrowsingDataServiceWorkerHelper( |
+ storage_partition_->GetServiceWorkerContext()); |
+ cache_storage_helper_ = new BrowsingDataCacheStorageHelper( |
+ storage_partition_->GetCacheStorageContext()); |
+ flash_lso_helper_ = BrowsingDataFlashLSOHelper::Create(profile_); |
+ |
+ appcache_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnAppCacheModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ cookie_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnCookiesModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ database_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnDatabaseModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ local_storage_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnLocalStorageModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ indexed_db_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnIndexedDBModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ file_system_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnFileSystemModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ quota_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnQuotaModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ channel_id_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnChannelIDModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ service_worker_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnServiceWorkerModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ cache_storage_helper_->StartFetching( |
+ base::Bind(&SiteDataSizeCollector::OnCacheStorageModelInfoLoaded, |
+ weak_ptr_factory_.GetWeakPtr())); |
+ in_flight_operations_++; |
+ 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; |
+ if (!cookie_list.empty()) { |
+ // Consider cookie file size only when at least one cookie is found. |
+ base::FilePath cookie_file_path = storage_partition_->GetPath() |
+ .Append(chrome::kCookieFilename); |
+ base::GetFileSize(cookie_file_path, &size); |
+ } |
+ 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::OnQuotaModelInfoLoaded( |
msramek
2016/06/23 21:30:35
Quota model consists of these things:
https://cs.
fukino
2016/06/30 09:21:24
It seems all sizes in quota model are already coun
|
+ const QuotaInfoList& quota_info_list) { |
+ int64_t total_size = 0; |
+ for (const auto& quota_info : quota_info_list) { |
+ total_size += quota_info.temporary_usage + quota_info.persistent_usage + |
+ quota_info.syncable_usage; |
+ } |
+ 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 = storage_partition_->GetPath() |
+ .Append(chrome::kChannelIDFilename); |
+ base::GetFileSize(channel_id_file_path, &size); |
+ } |
+ 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 |
+ // found. |
+ base::FilePath pepper_data_dir_path = storage_partition_->GetPath() |
+ .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_); |
+} |