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