OLD | NEW |
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> |
| 8 #include <numeric> |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
10 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
11 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/chromeos/arc/arc_auth_service.h" | 14 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
13 #include "chrome/browser/chromeos/drive/file_system_util.h" | 15 #include "chrome/browser/chromeos/drive/file_system_util.h" |
14 #include "chrome/browser/chromeos/file_manager/path_util.h" | 16 #include "chrome/browser/chromeos/file_manager/path_util.h" |
15 #include "chrome/browser/platform_util.h" | 17 #include "chrome/browser/platform_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "chromeos/cryptohome/homedir_methods.h" |
18 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" | 21 #include "components/browsing_data/storage_partition_http_cache_data_remover.h" |
19 #include "components/drive/chromeos/file_system_interface.h" | 22 #include "components/drive/chromeos/file_system_interface.h" |
| 23 #include "components/user_manager/user_manager.h" |
20 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
21 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
22 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/text/bytes_formatting.h" | 27 #include "ui/base/text/bytes_formatting.h" |
24 | 28 |
25 namespace chromeos { | 29 namespace chromeos { |
26 namespace options { | 30 namespace options { |
27 namespace { | 31 namespace { |
28 | 32 |
29 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, | 33 void GetSizeStatOnBlockingPool(const base::FilePath& mount_path, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 localized_strings->SetString( | 79 localized_strings->SetString( |
76 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16( | 80 "storageSubitemLabelDownloads", l10n_util::GetStringUTF16( |
77 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS)); | 81 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS)); |
78 localized_strings->SetString( | 82 localized_strings->SetString( |
79 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16( | 83 "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16( |
80 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE)); | 84 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE)); |
81 localized_strings->SetString( | 85 localized_strings->SetString( |
82 "storageSubitemLabelBrowsingData", l10n_util::GetStringUTF16( | 86 "storageSubitemLabelBrowsingData", l10n_util::GetStringUTF16( |
83 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_BROWSING_DATA)); | 87 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_BROWSING_DATA)); |
84 localized_strings->SetString( | 88 localized_strings->SetString( |
| 89 "storageSubitemLabelOtherUsers", l10n_util::GetStringUTF16( |
| 90 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_OTHER_USERS)); |
| 91 localized_strings->SetString( |
85 "storageSubitemLabelArc", l10n_util::GetStringUTF16( | 92 "storageSubitemLabelArc", l10n_util::GetStringUTF16( |
86 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC)); | 93 IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC)); |
87 localized_strings->SetString( | 94 localized_strings->SetString( |
88 "storageSizeCalculating", l10n_util::GetStringUTF16( | 95 "storageSizeCalculating", l10n_util::GetStringUTF16( |
89 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING)); | 96 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING)); |
90 localized_strings->SetString( | 97 localized_strings->SetString( |
91 "storageClearDriveCacheDialogTitle", l10n_util::GetStringUTF16( | 98 "storageClearDriveCacheDialogTitle", l10n_util::GetStringUTF16( |
92 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DIALOG_TITLE)); | 99 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DIALOG_TITLE)); |
93 localized_strings->SetString( | 100 localized_strings->SetString( |
94 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( | 101 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 base::Bind(&StorageManagerHandler::HandleClearDriveCache, | 147 base::Bind(&StorageManagerHandler::HandleClearDriveCache, |
141 base::Unretained(this))); | 148 base::Unretained(this))); |
142 } | 149 } |
143 | 150 |
144 void StorageManagerHandler::HandleUpdateStorageInfo( | 151 void StorageManagerHandler::HandleUpdateStorageInfo( |
145 const base::ListValue* unused_args) { | 152 const base::ListValue* unused_args) { |
146 UpdateSizeStat(); | 153 UpdateSizeStat(); |
147 UpdateDownloadsSize(); | 154 UpdateDownloadsSize(); |
148 UpdateDriveCacheSize(); | 155 UpdateDriveCacheSize(); |
149 UpdateBrowsingDataSize(); | 156 UpdateBrowsingDataSize(); |
| 157 UpdateOtherUsersSize(); |
150 UpdateArcSize(); | 158 UpdateArcSize(); |
151 } | 159 } |
152 | 160 |
153 void StorageManagerHandler::HandleOpenDownloads( | 161 void StorageManagerHandler::HandleOpenDownloads( |
154 const base::ListValue* unused_args) { | 162 const base::ListValue* unused_args) { |
155 Profile* const profile = Profile::FromWebUI(web_ui()); | 163 Profile* const profile = Profile::FromWebUI(web_ui()); |
156 const base::FilePath downloads_path = | 164 const base::FilePath downloads_path = |
157 file_manager::util::GetDownloadsFolderForProfile(profile); | 165 file_manager::util::GetDownloadsFolderForProfile(profile); |
158 platform_util::OpenItem( | 166 platform_util::OpenItem( |
159 profile, | 167 profile, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 browser_site_data_size_ = size; | 277 browser_site_data_size_ = size; |
270 else | 278 else |
271 browser_cache_size_ = size; | 279 browser_cache_size_ = size; |
272 | 280 |
273 web_ui()->CallJavascriptFunctionUnsafe( | 281 web_ui()->CallJavascriptFunctionUnsafe( |
274 "options.StorageManager.setBrowsingDataSize", | 282 "options.StorageManager.setBrowsingDataSize", |
275 base::StringValue(ui::FormatBytes(static_cast<int64_t>( | 283 base::StringValue(ui::FormatBytes(static_cast<int64_t>( |
276 browser_cache_size_ + browser_site_data_size_)))); | 284 browser_cache_size_ + browser_site_data_size_)))); |
277 } | 285 } |
278 | 286 |
| 287 void StorageManagerHandler::UpdateOtherUsersSize() { |
| 288 other_users_.clear(); |
| 289 user_sizes_.clear(); |
| 290 const user_manager::UserList& users = |
| 291 user_manager::UserManager::Get()->GetUsers(); |
| 292 for (const auto& user : users) { |
| 293 if (user->is_active()) |
| 294 continue; |
| 295 other_users_.push_back(user); |
| 296 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( |
| 297 cryptohome::Identification(user->GetAccountId()), |
| 298 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, |
| 299 weak_ptr_factory_.GetWeakPtr())); |
| 300 } |
| 301 } |
| 302 |
| 303 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { |
| 304 user_sizes_.push_back(success ? size : -1); |
| 305 if (user_sizes_.size() == other_users_.size()) { |
| 306 base::StringValue other_users_size(l10n_util::GetStringUTF16( |
| 307 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN)); |
| 308 // If all the requests succeed, shows the total bytes in the UI. |
| 309 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { |
| 310 other_users_size = base::StringValue(ui::FormatBytes( |
| 311 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL))); |
| 312 } |
| 313 web_ui()->CallJavascriptFunctionUnsafe( |
| 314 "options.StorageManager.setOtherUsersSize", other_users_size); |
| 315 } |
| 316 } |
| 317 |
279 void StorageManagerHandler::UpdateArcSize() { | 318 void StorageManagerHandler::UpdateArcSize() { |
280 Profile* const profile = Profile::FromWebUI(web_ui()); | 319 Profile* const profile = Profile::FromWebUI(web_ui()); |
281 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || | 320 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || |
282 arc::ArcAuthService::IsOptInVerificationDisabled() || | 321 arc::ArcAuthService::IsOptInVerificationDisabled() || |
283 !arc::ArcAuthService::Get()->IsArcEnabled()) { | 322 !arc::ArcAuthService::Get()->IsArcEnabled()) { |
284 return; | 323 return; |
285 } | 324 } |
286 | 325 |
287 // Shows the item "Android apps and cache" and start calculating size. | 326 // Shows the item "Android apps and cache" and start calculating size. |
288 web_ui()->CallJavascriptFunctionUnsafe( | 327 web_ui()->CallJavascriptFunctionUnsafe( |
(...skipping 24 matching lines...) Expand all Loading... |
313 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 352 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
314 arc_size); | 353 arc_size); |
315 } | 354 } |
316 | 355 |
317 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { | 356 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
318 UpdateDriveCacheSize(); | 357 UpdateDriveCacheSize(); |
319 } | 358 } |
320 | 359 |
321 } // namespace options | 360 } // namespace options |
322 } // namespace chromeos | 361 } // namespace chromeos |
OLD | NEW |