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

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

Issue 2073903002: Storage manager: Add browsing data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a minor issue on closure annotation. 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 <string> 7 #include <string>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/sys_info.h" 10 #include "base/sys_info.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/arc/arc_auth_service.h" 12 #include "chrome/browser/chromeos/arc/arc_auth_service.h"
13 #include "chrome/browser/chromeos/drive/file_system_util.h" 13 #include "chrome/browser/chromeos/drive/file_system_util.h"
14 #include "chrome/browser/chromeos/file_manager/path_util.h" 14 #include "chrome/browser/chromeos/file_manager/path_util.h"
15 #include "chrome/browser/platform_util.h" 15 #include "chrome/browser/platform_util.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/browsing_data/storage_partition_http_cache_data_remover.h"
18 #include "components/drive/chromeos/file_system_interface.h" 19 #include "components/drive/chromeos/file_system_interface.h"
20 #include "content/public/browser/browser_context.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
20 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/text/bytes_formatting.h" 23 #include "ui/base/text/bytes_formatting.h"
22 24
23 namespace chromeos { 25 namespace chromeos {
24 namespace options { 26 namespace options {
25 namespace { 27 namespace {
26 28
27 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, 29 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path,
28 int64_t* total_size, 30 int64_t* total_size,
29 int64_t* available_size) { 31 int64_t* available_size) {
30 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path); 32 int64_t size = base::SysInfo::AmountOfTotalDiskSpace(mount_path);
31 if (size >= 0) 33 if (size >= 0)
32 *total_size = size; 34 *total_size = size;
33 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path); 35 size = base::SysInfo::AmountOfFreeDiskSpace(mount_path);
34 if (size >= 0) 36 if (size >= 0)
35 *available_size = size; 37 *available_size = size;
36 } 38 }
37 39
38 // Threshold to show a message indicating space is critically low (512 MB). 40 // Threshold to show a message indicating space is critically low (512 MB).
39 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024; 41 const int64_t kSpaceCriticallyLowBytes = 512 * 1024 * 1024;
40 42
41 // Threshold to show a message indicating space is low (1 GB). 43 // Threshold to show a message indicating space is low (1 GB).
42 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024; 44 const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024;
43 45
44 } // namespace 46 } // namespace
45 47
46 StorageManagerHandler::StorageManagerHandler() : weak_ptr_factory_(this) { 48 StorageManagerHandler::StorageManagerHandler()
49 : browser_cache_size_(0),
50 browser_site_data_size_(0),
51 weak_ptr_factory_(this) {
47 } 52 }
48 53
49 StorageManagerHandler::~StorageManagerHandler() { 54 StorageManagerHandler::~StorageManagerHandler() {
50 } 55 }
51 56
52 void StorageManagerHandler::GetLocalizedValues( 57 void StorageManagerHandler::GetLocalizedValues(
53 base::DictionaryValue* localized_strings) { 58 base::DictionaryValue* localized_strings) {
54 DCHECK(localized_strings); 59 DCHECK(localized_strings);
55 60
56 RegisterTitle(localized_strings, "storageManagerPage", 61 RegisterTitle(localized_strings, "storageManagerPage",
(...skipping 10 matching lines...) Expand all
67 localized_strings->SetString( 72 localized_strings->SetString(
68 "storageItemLabelAvailable", l10n_util::GetStringUTF16( 73 "storageItemLabelAvailable", l10n_util::GetStringUTF16(
69 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE)); 74 IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE));
70 localized_strings->SetString( 75 localized_strings->SetString(
71 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16( 76 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16(
72 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS)); 77 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS));
73 localized_strings->SetString( 78 localized_strings->SetString(
74 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16( 79 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16(
75 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE)); 80 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE));
76 localized_strings->SetString( 81 localized_strings->SetString(
82 "storageSubitemLabelBrowsingData", l10n_util::GetStringUTF16(
83 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_BROWSING_DATA));
84 localized_strings->SetString(
77 "storageSubitemLabelArc", l10n_util::GetStringUTF16( 85 "storageSubitemLabelArc", l10n_util::GetStringUTF16(
78 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC)); 86 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC));
79 localized_strings->SetString( 87 localized_strings->SetString(
80 "storageSizeCalculating", l10n_util::GetStringUTF16( 88 "storageSizeCalculating", l10n_util::GetStringUTF16(
81 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING)); 89 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING));
82 localized_strings->SetString( 90 localized_strings->SetString(
83 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( 91 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16(
84 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION)); 92 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION));
85 localized_strings->SetString( 93 localized_strings->SetString(
86 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16( 94 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 "clearDriveCache", 136 "clearDriveCache",
129 base::Bind(&StorageManagerHandler::HandleClearDriveCache, 137 base::Bind(&StorageManagerHandler::HandleClearDriveCache,
130 base::Unretained(this))); 138 base::Unretained(this)));
131 } 139 }
132 140
133 void StorageManagerHandler::HandleUpdateStorageInfo( 141 void StorageManagerHandler::HandleUpdateStorageInfo(
134 const base::ListValue* unused_args) { 142 const base::ListValue* unused_args) {
135 UpdateSizeStat(); 143 UpdateSizeStat();
136 UpdateDownloadsSize(); 144 UpdateDownloadsSize();
137 UpdateDriveCacheSize(); 145 UpdateDriveCacheSize();
146 UpdateBrowsingDataSize();
138 UpdateArcSize(); 147 UpdateArcSize();
139 } 148 }
140 149
141 void StorageManagerHandler::HandleOpenDownloads( 150 void StorageManagerHandler::HandleOpenDownloads(
142 const base::ListValue* unused_args) { 151 const base::ListValue* unused_args) {
143 Profile* const profile = Profile::FromWebUI(web_ui()); 152 Profile* const profile = Profile::FromWebUI(web_ui());
144 const base::FilePath downloads_path = 153 const base::FilePath downloads_path =
145 file_manager::util::GetDownloadsFolderForProfile(profile); 154 file_manager::util::GetDownloadsFolderForProfile(profile);
146 platform_util::OpenItem( 155 platform_util::OpenItem(
147 profile, 156 profile,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, 239 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize,
231 weak_ptr_factory_.GetWeakPtr())); 240 weak_ptr_factory_.GetWeakPtr()));
232 } 241 }
233 242
234 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { 243 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) {
235 web_ui()->CallJavascriptFunctionUnsafe( 244 web_ui()->CallJavascriptFunctionUnsafe(
236 "options.StorageManager.setDriveCacheSize", 245 "options.StorageManager.setDriveCacheSize",
237 base::StringValue(ui::FormatBytes(size))); 246 base::StringValue(ui::FormatBytes(size)));
238 } 247 }
239 248
249 void StorageManagerHandler::UpdateBrowsingDataSize() {
250 Profile* const profile = Profile::FromWebUI(web_ui());
251 // Fetch the size of http cache in browsing data.
252 // StoragePartitionHttpCacheDataRemover deletes itself when it is done.
253 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange(
254 content::BrowserContext::GetDefaultStoragePartition(profile),
255 base::Time(),
256 base::Time::Max())->Count(
257 base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
258 weak_ptr_factory_.GetWeakPtr(), false));
259
260 // TODO(fukino): fetch the size of site data in browsing data.
261 }
262
263 void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data,
264 int64_t size) {
265 if (is_site_data)
266 browser_site_data_size_ = size;
267 else
268 browser_cache_size_ = size;
269
270 web_ui()->CallJavascriptFunctionUnsafe(
271 "options.StorageManager.setBrowsingDataSize",
272 base::StringValue(ui::FormatBytes(static_cast<int64_t>(
273 browser_cache_size_ + browser_site_data_size_))));
274 }
275
240 void StorageManagerHandler::UpdateArcSize() { 276 void StorageManagerHandler::UpdateArcSize() {
241 Profile* const profile = Profile::FromWebUI(web_ui()); 277 Profile* const profile = Profile::FromWebUI(web_ui());
242 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || 278 if (!arc::ArcAuthService::IsAllowedForProfile(profile) ||
243 arc::ArcAuthService::IsOptInVerificationDisabled() || 279 arc::ArcAuthService::IsOptInVerificationDisabled() ||
244 !arc::ArcAuthService::Get()->IsArcEnabled()) { 280 !arc::ArcAuthService::Get()->IsArcEnabled()) {
245 return; 281 return;
246 } 282 }
247 283
248 // Shows the item "Android apps and cache" and start calculating size. 284 // Shows the item "Android apps and cache" and start calculating size.
249 web_ui()->CallJavascriptFunctionUnsafe( 285 web_ui()->CallJavascriptFunctionUnsafe(
(...skipping 24 matching lines...) Expand all
274 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", 310 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize",
275 arc_size); 311 arc_size);
276 } 312 }
277 313
278 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { 314 void StorageManagerHandler::OnClearDriveCacheDone(bool success) {
279 UpdateDriveCacheSize(); 315 UpdateDriveCacheSize();
280 } 316 }
281 317
282 } // namespace options 318 } // namespace options
283 } // namespace chromeos 319 } // 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