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

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: 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
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()
53 : browser_cache_size_(0), 64 : browser_cache_size_(-1),
54 browser_site_data_size_(0), 65 browser_site_data_size_(-1),
55 weak_ptr_factory_(this) { 66 weak_ptr_factory_(this) {
56 } 67 }
57 68
58 StorageManagerHandler::~StorageManagerHandler() { 69 StorageManagerHandler::~StorageManagerHandler() {
59 } 70 }
60 71
61 void StorageManagerHandler::GetLocalizedValues( 72 void StorageManagerHandler::GetLocalizedValues(
62 base::DictionaryValue* localized_strings) { 73 base::DictionaryValue* localized_strings) {
63 DCHECK(localized_strings); 74 DCHECK(localized_strings);
64 75
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { 265 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) {
255 web_ui()->CallJavascriptFunctionUnsafe( 266 web_ui()->CallJavascriptFunctionUnsafe(
256 "options.StorageManager.setDriveCacheSize", 267 "options.StorageManager.setDriveCacheSize",
257 base::StringValue(ui::FormatBytes(size))); 268 base::StringValue(ui::FormatBytes(size)));
258 } 269 }
259 270
260 void StorageManagerHandler::UpdateBrowsingDataSize() { 271 void StorageManagerHandler::UpdateBrowsingDataSize() {
261 Profile* const profile = Profile::FromWebUI(web_ui()); 272 Profile* const profile = Profile::FromWebUI(web_ui());
262 // Fetch the size of http cache in browsing data. 273 // Fetch the size of http cache in browsing data.
263 // StoragePartitionHttpCacheDataRemover deletes itself when it is done. 274 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
275 browser_cache_size_ = -1;
264 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( 276 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
265 content::BrowserContext::GetDefaultStoragePartition(profile), 277 content::BrowserContext::GetDefaultStoragePartition(profile),
266 base::Time(), 278 base::Time(),
267 base::Time::Max())->Count( 279 base::Time::Max())->Count(
268 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize, 280 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
269 weak_ptr_factory_.GetWeakPtr(), false)); 281 weak_ptr_factory_.GetWeakPtr(), false));
270 282
271 // TODO(fukino): fetch the size of site data in browsing data. 283 // Fetch the size of site data in browsing data.
284 if (!site_data_size_collector_.get()) {
285 content::StoragePartition* storage_partition =
286 content::BrowserContext::GetDefaultStoragePartition(profile);
287 site_data_size_collector_.reset(new SiteDataSizeCollector(
288 storage_partition->GetPath(),
289 new BrowsingDataCookieHelper(profile->GetRequestContext()),
290 new BrowsingDataDatabaseHelper(profile),
291 new BrowsingDataLocalStorageHelper(profile),
292 new BrowsingDataAppCacheHelper(profile),
293 new BrowsingDataIndexedDBHelper(
294 storage_partition->GetIndexedDBContext()),
295 BrowsingDataFileSystemHelper::Create(
296 storage_partition->GetFileSystemContext()),
297 BrowsingDataChannelIDHelper::Create(profile->GetRequestContext()),
298 new BrowsingDataServiceWorkerHelper(
299 storage_partition->GetServiceWorkerContext()),
300 new BrowsingDataCacheStorageHelper(
301 storage_partition->GetCacheStorageContext()),
302 BrowsingDataFlashLSOHelper::Create(profile)));
303 }
304 browser_site_data_size_ = -1;
305 site_data_size_collector_->Fetch(
306 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
307 weak_ptr_factory_.GetWeakPtr(), true));
272 } 308 }
273 309
274 void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data, 310 void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data,
275 int64_t size) { 311 int64_t size) {
276 if (is_site_data) 312 if (is_site_data)
277 browser_site_data_size_ = size; 313 browser_site_data_size_ = size;
278 else 314 else
279 browser_cache_size_ = size; 315 browser_cache_size_ = size;
280 316
281 web_ui()->CallJavascriptFunctionUnsafe( 317 if (browser_site_data_size_ >= 0 && browser_cache_size_ >= 0) {
Dan Beam 2016/07/06 18:29:22 what if there was a valid size and now it fails?
fukino 2016/07/07 11:08:18 Ah, yes, when fetching browsing data fails, I thin
282 "options.StorageManager.setBrowsingDataSize", 318 web_ui()->CallJavascriptFunctionUnsafe(
283 base::StringValue(ui::FormatBytes(static_cast<int64_t>( 319 "options.StorageManager.setBrowsingDataSize",
284 browser_cache_size_ + browser_site_data_size_)))); 320 base::StringValue(ui::FormatBytes(static_cast<int64_t>(
321 browser_cache_size_ + browser_site_data_size_))));
322 }
285 } 323 }
286 324
287 void StorageManagerHandler::UpdateOtherUsersSize() { 325 void StorageManagerHandler::UpdateOtherUsersSize() {
288 other_users_.clear(); 326 other_users_.clear();
289 user_sizes_.clear(); 327 user_sizes_.clear();
290 const user_manager::UserList& users = 328 const user_manager::UserList& users =
291 user_manager::UserManager::Get()->GetUsers(); 329 user_manager::UserManager::Get()->GetUsers();
292 for (const auto& user : users) { 330 for (const auto& user : users) {
293 if (user->is_active()) 331 if (user->is_active())
294 continue; 332 continue;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", 390 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize",
353 arc_size); 391 arc_size);
354 } 392 }
355 393
356 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { 394 void StorageManagerHandler::OnClearDriveCacheDone(bool success) {
357 UpdateDriveCacheSize(); 395 UpdateDriveCacheSize();
358 } 396 }
359 397
360 } // namespace options 398 } // namespace options
361 } // namespace chromeos 399 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698