Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/browsing_data/site_data_size_collector.h" | |
| 6 | |
| 7 #include "base/files/file_util.h" | |
| 8 #include "chrome/common/chrome_constants.h" | |
| 9 #include "chrome/common/pref_names.h" | |
| 10 #include "content/public/browser/browser_thread.h" | |
| 11 #include "content/public/common/content_constants.h" | |
| 12 | |
| 13 SiteDataSizeCollector::SiteDataSizeCollector(Profile* profile) | |
| 14 : profile_(profile) | |
| 15 , storage_partition_(nullptr) | |
| 16 , in_flight_operations_(0) | |
| 17 , total_bytes_(0) | |
| 18 , weak_ptr_factory_(this) { | |
| 19 } | |
| 20 | |
| 21 SiteDataSizeCollector::~SiteDataSizeCollector() { | |
| 22 } | |
| 23 | |
| 24 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
| |
| 25 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 26 DCHECK(!callback.is_null()); | |
| 27 | |
| 28 fetch_callback_ = callback; | |
| 29 total_bytes_ = 0; | |
| 30 in_flight_operations_ = 0; | |
| 31 | |
| 32 storage_partition_ = | |
| 33 content::BrowserContext::GetDefaultStoragePartition(profile_); | |
| 34 appcache_helper_ = new BrowsingDataAppCacheHelper(profile_); | |
| 35 cookie_helper_ = new BrowsingDataCookieHelper( | |
| 36 profile_->GetRequestContext()); | |
| 37 database_helper_ = new BrowsingDataDatabaseHelper(profile_); | |
| 38 local_storage_helper_ = new BrowsingDataLocalStorageHelper(profile_); | |
| 39 indexed_db_helper_ = new BrowsingDataIndexedDBHelper( | |
| 40 storage_partition_->GetIndexedDBContext()); | |
| 41 file_system_helper_ = BrowsingDataFileSystemHelper::Create( | |
| 42 storage_partition_->GetFileSystemContext()); | |
| 43 quota_helper_ = BrowsingDataQuotaHelper::Create(profile_); | |
| 44 channel_id_helper_ = BrowsingDataChannelIDHelper::Create( | |
| 45 profile_->GetRequestContext()); | |
| 46 service_worker_helper_ = new BrowsingDataServiceWorkerHelper( | |
| 47 storage_partition_->GetServiceWorkerContext()); | |
| 48 cache_storage_helper_ = new BrowsingDataCacheStorageHelper( | |
| 49 storage_partition_->GetCacheStorageContext()); | |
| 50 flash_lso_helper_ = BrowsingDataFlashLSOHelper::Create(profile_); | |
| 51 | |
| 52 appcache_helper_->StartFetching( | |
| 53 base::Bind(&SiteDataSizeCollector::OnAppCacheModelInfoLoaded, | |
| 54 weak_ptr_factory_.GetWeakPtr())); | |
| 55 in_flight_operations_++; | |
| 56 cookie_helper_->StartFetching( | |
| 57 base::Bind(&SiteDataSizeCollector::OnCookiesModelInfoLoaded, | |
| 58 weak_ptr_factory_.GetWeakPtr())); | |
| 59 in_flight_operations_++; | |
| 60 database_helper_->StartFetching( | |
| 61 base::Bind(&SiteDataSizeCollector::OnDatabaseModelInfoLoaded, | |
| 62 weak_ptr_factory_.GetWeakPtr())); | |
| 63 in_flight_operations_++; | |
| 64 local_storage_helper_->StartFetching( | |
| 65 base::Bind(&SiteDataSizeCollector::OnLocalStorageModelInfoLoaded, | |
| 66 weak_ptr_factory_.GetWeakPtr())); | |
| 67 in_flight_operations_++; | |
| 68 indexed_db_helper_->StartFetching( | |
| 69 base::Bind(&SiteDataSizeCollector::OnIndexedDBModelInfoLoaded, | |
| 70 weak_ptr_factory_.GetWeakPtr())); | |
| 71 in_flight_operations_++; | |
| 72 file_system_helper_->StartFetching( | |
| 73 base::Bind(&SiteDataSizeCollector::OnFileSystemModelInfoLoaded, | |
| 74 weak_ptr_factory_.GetWeakPtr())); | |
| 75 in_flight_operations_++; | |
| 76 quota_helper_->StartFetching( | |
| 77 base::Bind(&SiteDataSizeCollector::OnQuotaModelInfoLoaded, | |
| 78 weak_ptr_factory_.GetWeakPtr())); | |
| 79 in_flight_operations_++; | |
| 80 channel_id_helper_->StartFetching( | |
| 81 base::Bind(&SiteDataSizeCollector::OnChannelIDModelInfoLoaded, | |
| 82 weak_ptr_factory_.GetWeakPtr())); | |
| 83 in_flight_operations_++; | |
| 84 service_worker_helper_->StartFetching( | |
| 85 base::Bind(&SiteDataSizeCollector::OnServiceWorkerModelInfoLoaded, | |
| 86 weak_ptr_factory_.GetWeakPtr())); | |
| 87 in_flight_operations_++; | |
| 88 cache_storage_helper_->StartFetching( | |
| 89 base::Bind(&SiteDataSizeCollector::OnCacheStorageModelInfoLoaded, | |
| 90 weak_ptr_factory_.GetWeakPtr())); | |
| 91 in_flight_operations_++; | |
| 92 flash_lso_helper_->StartFetching( | |
| 93 base::Bind(&SiteDataSizeCollector::OnFlashLSOInfoLoaded, | |
| 94 weak_ptr_factory_.GetWeakPtr())); | |
| 95 in_flight_operations_++; | |
| 96 } | |
| 97 | |
| 98 void SiteDataSizeCollector::OnAppCacheModelInfoLoaded( | |
| 99 scoped_refptr<content::AppCacheInfoCollection> appcache_info) { | |
| 100 int64_t total_size = 0; | |
| 101 if (appcache_info.get()) { | |
| 102 for (const auto& origin : appcache_info->infos_by_origin) { | |
| 103 for (const auto& info : origin.second) | |
| 104 total_size += info.size; | |
| 105 } | |
| 106 } | |
| 107 OnStorageSizeFetched(total_size); | |
| 108 } | |
| 109 | |
| 110 void SiteDataSizeCollector::OnCookiesModelInfoLoaded( | |
| 111 const net::CookieList& cookie_list) { | |
| 112 int64_t size = 0; | |
| 113 if (!cookie_list.empty()) { | |
| 114 // Consider cookie file size only when at least one cookie is found. | |
| 115 base::FilePath cookie_file_path = storage_partition_->GetPath() | |
| 116 .Append(chrome::kCookieFilename); | |
| 117 base::GetFileSize(cookie_file_path, &size); | |
| 118 } | |
| 119 OnStorageSizeFetched(size); | |
| 120 } | |
| 121 | |
| 122 void SiteDataSizeCollector::OnDatabaseModelInfoLoaded( | |
| 123 const DatabaseInfoList& database_info_list) { | |
| 124 int64_t total_size = 0; | |
| 125 for (const auto& database_info : database_info_list) | |
| 126 total_size += database_info.size; | |
| 127 OnStorageSizeFetched(total_size); | |
| 128 } | |
| 129 | |
| 130 void SiteDataSizeCollector::OnLocalStorageModelInfoLoaded( | |
| 131 const LocalStorageInfoList& local_storage_info_list) { | |
| 132 int64_t total_size = 0; | |
| 133 for (const auto& local_storage_info : local_storage_info_list) | |
| 134 total_size += local_storage_info.size; | |
| 135 OnStorageSizeFetched(total_size); | |
| 136 } | |
| 137 | |
| 138 void SiteDataSizeCollector::OnIndexedDBModelInfoLoaded( | |
| 139 const std::list<content::IndexedDBInfo>& indexed_db_info_list) { | |
| 140 int64_t total_size = 0; | |
| 141 for (const auto& indexed_db_info : indexed_db_info_list) | |
| 142 total_size += indexed_db_info.size; | |
| 143 OnStorageSizeFetched(total_size); | |
| 144 } | |
| 145 | |
| 146 void SiteDataSizeCollector::OnFileSystemModelInfoLoaded( | |
| 147 const FileSystemInfoList& file_system_info_list) { | |
| 148 int64_t total_size = 0; | |
| 149 for (const auto& file_system_info : file_system_info_list) { | |
| 150 for (const auto& usage : file_system_info.usage_map) | |
| 151 total_size += usage.second; | |
| 152 } | |
| 153 OnStorageSizeFetched(total_size); | |
| 154 } | |
| 155 | |
| 156 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
| |
| 157 const QuotaInfoList& quota_info_list) { | |
| 158 int64_t total_size = 0; | |
| 159 for (const auto& quota_info : quota_info_list) { | |
| 160 total_size += quota_info.temporary_usage + quota_info.persistent_usage + | |
| 161 quota_info.syncable_usage; | |
| 162 } | |
| 163 OnStorageSizeFetched(total_size); | |
| 164 } | |
| 165 | |
| 166 void SiteDataSizeCollector::OnChannelIDModelInfoLoaded( | |
| 167 const ChannelIDList& channel_id_list) { | |
| 168 int64_t size = 0; | |
| 169 if (!channel_id_list.empty()) { | |
| 170 // Consider channel id file size only when at least one channel id is found. | |
| 171 base::FilePath channel_id_file_path = storage_partition_->GetPath() | |
| 172 .Append(chrome::kChannelIDFilename); | |
| 173 base::GetFileSize(channel_id_file_path, &size); | |
| 174 } | |
| 175 OnStorageSizeFetched(size); | |
| 176 } | |
| 177 | |
| 178 void SiteDataSizeCollector::OnServiceWorkerModelInfoLoaded( | |
| 179 const ServiceWorkerUsageInfoList& service_worker_info_list) { | |
| 180 int64_t total_size = 0; | |
| 181 for (const auto& service_worker_info : service_worker_info_list) | |
| 182 total_size += service_worker_info.total_size_bytes; | |
| 183 OnStorageSizeFetched(total_size); | |
| 184 } | |
| 185 | |
| 186 void SiteDataSizeCollector::OnCacheStorageModelInfoLoaded( | |
| 187 const CacheStorageUsageInfoList& cache_storage_info_list) { | |
| 188 int64_t total_size = 0; | |
| 189 for (const auto& cache_storage_info : cache_storage_info_list) | |
| 190 total_size += cache_storage_info.total_size_bytes; | |
| 191 OnStorageSizeFetched(total_size); | |
| 192 } | |
| 193 | |
| 194 void SiteDataSizeCollector::OnFlashLSOInfoLoaded( | |
| 195 const FlashLSODomainList& domains) { | |
| 196 int64_t size = 0; | |
| 197 if (!domains.empty()) { | |
| 198 // Consider pepper data directory size only when at least one Flash LSO is | |
| 199 // found. | |
| 200 base::FilePath pepper_data_dir_path = storage_partition_->GetPath() | |
| 201 .Append(content::kPepperDataDirname); | |
| 202 size = base::ComputeDirectorySize(pepper_data_dir_path); | |
| 203 } | |
| 204 OnStorageSizeFetched(size); | |
| 205 } | |
| 206 | |
| 207 void SiteDataSizeCollector::OnStorageSizeFetched(int64_t size) { | |
| 208 total_bytes_ += size; | |
| 209 if (--in_flight_operations_ == 0) | |
| 210 fetch_callback_.Run(total_bytes_); | |
| 211 } | |
| OLD | NEW |