Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc

Issue 2123133002: Storage manager: Add site data size on the amount of browsing data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a missing header. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ui/webui/options/chromeos/storage_manager_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <numeric> 8 #include <numeric>
9 #include <string> 9 #include <string>
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
15 #include "chrome/browser/browsing_data/browsing_data_cache_storage_helper.h"
16 #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
17 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
18 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
19 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
21 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
23 #include "chrome/browser/browsing_data/browsing_data_service_worker_helper.h"
14 #include "chrome/browser/chromeos/arc/arc_auth_service.h" 24 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
15 #include "chrome/browser/chromeos/drive/file_system_util.h" 25 #include "chrome/browser/chromeos/drive/file_system_util.h"
16 #include "chrome/browser/chromeos/file_manager/path_util.h" 26 #include "chrome/browser/chromeos/file_manager/path_util.h"
17 #include "chrome/browser/platform_util.h" 27 #include "chrome/browser/platform_util.h"
18 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
20 #include "chromeos/cryptohome/homedir_methods.h" 30 #include "chromeos/cryptohome/homedir_methods.h"
21 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" 31 #include "components/browsing_data/storage_partition_http_cache_data_remover.h"
22 #include "components/drive/chromeos/file_system_interface.h" 32 #include "components/drive/chromeos/file_system_interface.h"
23 #include "components/user_manager/user_manager.h" 33 #include "components/user_manager/user_manager.h"
24 #include "content/public/browser/browser_context.h" 34 #include "content/public/browser/browser_context.h"
25 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
36 #include "content/public/browser/storage_partition.h"
26 #include "ui/base/l10n/l10n_util.h" 37 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/text/bytes_formatting.h" 38 #include "ui/base/text/bytes_formatting.h"
28 39
29 namespace chromeos { 40 namespace chromeos {
30 namespace options { 41 namespace options {
31 namespace { 42 namespace {
32 43
33 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, 44 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path,
34 int64_t* total_size, 45 int64_t* total_size,
35 int64_t* available_size) { 46 int64_t* available_size) {
36 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); 47 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path);
37 if (size >= 0) 48 if (size >= 0)
38 *total_size = size; 49 *total_size = size;
39 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); 50 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path);
40 if (size >= 0) 51 if (size >= 0)
41 *available_size = size; 52 *available_size = size;
42 } 53 }
43 54
44 // Threshold to show a message indicating space is critically low (512 MB). 55 // Threshold to show a message indicating space is critically low (512 MB).
45 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024; 56 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024;
46 57
47 // Threshold to show a message indicating space is low (1 GB). 58 // Threshold to show a message indicating space is low (1 GB).
48 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024; 59 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024;
49 60
50 } // namespace 61 } // namespace
51 62
52 StorageManagerHandler::StorageManagerHandler() 63 StorageManagerHandler::StorageManagerHandler() : weak_ptr_factory_(this) {
53 : browser_cache_size_(0),
54 browser_site_data_size_(0),
55 weak_ptr_factory_(this) {
56 } 64 }
57 65
58 StorageManagerHandler::~StorageManagerHandler() { 66 StorageManagerHandler::~StorageManagerHandler() {
59 } 67 }
60 68
61 void StorageManagerHandler::GetLocalizedValues( 69 void StorageManagerHandler::GetLocalizedValues(
62 base::DictionaryValue* localized_strings) { 70 base::DictionaryValue* localized_strings) {
63 DCHECK(localized_strings); 71 DCHECK(localized_strings);
64 72
65 RegisterTitle(localized_strings, "storageManagerPage", 73 RegisterTitle(localized_strings, "storageManagerPage",
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 weak_ptr_factory_.GetWeakPtr())); 259 weak_ptr_factory_.GetWeakPtr()));
252 } 260 }
253 261
254 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { 262 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) {
255 web_ui()->CallJavascriptFunctionUnsafe( 263 web_ui()->CallJavascriptFunctionUnsafe(
256 "options.StorageManager.setDriveCacheSize", 264 "options.StorageManager.setDriveCacheSize",
257 base::StringValue(ui::FormatBytes(size))); 265 base::StringValue(ui::FormatBytes(size)));
258 } 266 }
259 267
260 void StorageManagerHandler::UpdateBrowsingDataSize() { 268 void StorageManagerHandler::UpdateBrowsingDataSize() {
269 browsing_data_size_.clear();
261 Profile* const profile = Profile::FromWebUI(web_ui()); 270 Profile* const profile = Profile::FromWebUI(web_ui());
262 // Fetch the size of http cache in browsing data. 271 // Fetch the size of http cache in browsing data.
263 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 272 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
264 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 273 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
265 content::BrowserContext::GetDefaultStoragePartition(profile), 274 content::BrowserContext::GetDefaultStoragePartition(profile),
266 base::Time(), 275 base::Time(),
267 base::Time::Max())->Count( 276 base::Time::Max())->Count(
268 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, 277 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
269 weak_ptr_factory_.GetWeakPtr(), false)); 278 weak_ptr_factory_.GetWeakPtr(),
279 BROWSING_DATA_TYPE_HTTP_CACHE));
270 280
271 // TODO(fukino): fetch the size of site data in browsing data. 281 // Fetch the size of site data in browsing data.
282 if (!site_data_size_collector_.get()) {
283 content::StoragePartition* storage_partition =
284 content::BrowserContext::GetDefaultStoragePartition(profile);
285 site_data_size_collector_.reset(new SiteDataSizeCollector(
286 storage_partition->GetPath(),
287 new BrowsingDataCookieHelper(profile->GetRequestContext()),
288 new BrowsingDataDatabaseHelper(profile),
289 new BrowsingDataLocalStorageHelper(profile),
290 new BrowsingDataAppCacheHelper(profile),
291 new BrowsingDataIndexedDBHelper(
292 storage_partition->GetIndexedDBContext()),
293 BrowsingDataFileSystemHelper::Create(
294 storage_partition->GetFileSystemContext()),
295 BrowsingDataChannelIDHelper::Create(profile->GetRequestContext()),
296 new BrowsingDataServiceWorkerHelper(
297 storage_partition->GetServiceWorkerContext()),
298 new BrowsingDataCacheStorageHelper(
299 storage_partition->GetCacheStorageContext()),
300 BrowsingDataFlashLSOHelper::Create(profile)));
301 }
302 site_data_size_collector_->Fetch(
303 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
304 weak_ptr_factory_.GetWeakPtr(), BROWSING_DATA_TYPE_SITE_DATA));
272 } 305 }
273 306
274 void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data, 307 void StorageManagerHandler::OnGetBrowsingDataSize(BrowsingDataType data_type,
275 int64_t size) { 308 int64_t size) {
276 if (is_site_data) 309 browsing_data_size_[data_type] = size;
277 browser_site_data_size_ = size; 310 if (browsing_data_size_.size() == BROWSING_DATA_TYPE_MAX) {
278 else 311 base::StringValue size_string(l10n_util::GetStringUTF16(
279 browser_cache_size_ = size; 312 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN));
280 313 if (browsing_data_size_[BROWSING_DATA_TYPE_HTTP_CACHE] >= 0 &&
281 web_ui()->CallJavascriptFunctionUnsafe( 314 browsing_data_size_[BROWSING_DATA_TYPE_SITE_DATA] >= 0) {
Dan Beam 2016/07/07 18:46:23 you treat everything else like a map then expand o
fukino 2016/07/08 03:47:01 I don't use map in the latest patch. I'll iterate
282 "options.StorageManager.setBrowsingDataSize", 315 size_string = base::StringValue(ui::FormatBytes(
283 base::StringValue(ui::FormatBytes(static_cast<int64_t>( 316 browsing_data_size_[BROWSING_DATA_TYPE_HTTP_CACHE] +
284 browser_cache_size_ + browser_site_data_size_)))); 317 browsing_data_size_[BROWSING_DATA_TYPE_SITE_DATA]));
318 }
Dan Beam 2016/07/07 18:46:22 nit: base::string16 size_string; if (browsing_da
fukino 2016/07/08 03:47:01 Done. Thank you for the suggestion! I took the sam
319 web_ui()->CallJavascriptFunctionUnsafe(
320 "options.StorageManager.setBrowsingDataSize", size_string);
321 }
285 } 322 }
286 323
287 void StorageManagerHandler::UpdateOtherUsersSize() { 324 void StorageManagerHandler::UpdateOtherUsersSize() {
288 other_users_.clear(); 325 other_users_.clear();
289 user_sizes_.clear(); 326 user_sizes_.clear();
290 const user_manager::UserList& users = 327 const user_manager::UserList& users =
291 user_manager::UserManager::Get()->GetUsers(); 328 user_manager::UserManager::Get()->GetUsers();
292 for (const auto& user : users) { 329 for (const auto& user : users) {
293 if (user->is_active()) 330 if (user->is_active())
294 continue; 331 continue;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", 389 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize",
353 arc_size); 390 arc_size);
354 } 391 }
355 392
356 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { 393 void StorageManagerHandler::OnClearDriveCacheDone(bool success) {
357 UpdateDriveCacheSize(); 394 UpdateDriveCacheSize();
358 } 395 }
359 396
360 } // namespace options 397 } // namespace options
361 } // namespace chromeos 398 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698