| 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 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( | 98 "storageClearDriveCacheDescription", l10n_util::GetStringUTF16( |
| 92 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION)); | 99 IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION)); |
| 93 localized_strings->SetString( | 100 localized_strings->SetString( |
| 94 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16( | 101 "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 base::Bind(&StorageManagerHandler::HandleClearDriveCache, | 144 base::Bind(&StorageManagerHandler::HandleClearDriveCache, |
| 138 base::Unretained(this))); | 145 base::Unretained(this))); |
| 139 } | 146 } |
| 140 | 147 |
| 141 void StorageManagerHandler::HandleUpdateStorageInfo( | 148 void StorageManagerHandler::HandleUpdateStorageInfo( |
| 142 const base::ListValue* unused_args) { | 149 const base::ListValue* unused_args) { |
| 143 UpdateSizeStat(); | 150 UpdateSizeStat(); |
| 144 UpdateDownloadsSize(); | 151 UpdateDownloadsSize(); |
| 145 UpdateDriveCacheSize(); | 152 UpdateDriveCacheSize(); |
| 146 UpdateBrowsingDataSize(); | 153 UpdateBrowsingDataSize(); |
| 154 UpdateOtherUsersSize(); |
| 147 UpdateArcSize(); | 155 UpdateArcSize(); |
| 148 } | 156 } |
| 149 | 157 |
| 150 void StorageManagerHandler::HandleOpenDownloads( | 158 void StorageManagerHandler::HandleOpenDownloads( |
| 151 const base::ListValue* unused_args) { | 159 const base::ListValue* unused_args) { |
| 152 Profile* const profile = Profile::FromWebUI(web_ui()); | 160 Profile* const profile = Profile::FromWebUI(web_ui()); |
| 153 const base::FilePath downloads_path = | 161 const base::FilePath downloads_path = |
| 154 file_manager::util::GetDownloadsFolderForProfile(profile); | 162 file_manager::util::GetDownloadsFolderForProfile(profile); |
| 155 platform_util::OpenItem( | 163 platform_util::OpenItem( |
| 156 profile, | 164 profile, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 browser_site_data_size_ = size; | 274 browser_site_data_size_ = size; |
| 267 else | 275 else |
| 268 browser_cache_size_ = size; | 276 browser_cache_size_ = size; |
| 269 | 277 |
| 270 web_ui()->CallJavascriptFunctionUnsafe( | 278 web_ui()->CallJavascriptFunctionUnsafe( |
| 271 "options.StorageManager.setBrowsingDataSize", | 279 "options.StorageManager.setBrowsingDataSize", |
| 272 base::StringValue(ui::FormatBytes(static_cast<int64_t>( | 280 base::StringValue(ui::FormatBytes(static_cast<int64_t>( |
| 273 browser_cache_size_ + browser_site_data_size_)))); | 281 browser_cache_size_ + browser_site_data_size_)))); |
| 274 } | 282 } |
| 275 | 283 |
| 284 void StorageManagerHandler::UpdateOtherUsersSize() { |
| 285 other_users_.clear(); |
| 286 user_sizes_.clear(); |
| 287 const user_manager::UserList& users = |
| 288 user_manager::UserManager::Get()->GetUsers(); |
| 289 for (const auto& user : users) { |
| 290 if (user->is_active()) |
| 291 continue; |
| 292 other_users_.push_back(user); |
| 293 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( |
| 294 cryptohome::Identification(user->GetAccountId()), |
| 295 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, |
| 296 weak_ptr_factory_.GetWeakPtr())); |
| 297 } |
| 298 } |
| 299 |
| 300 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { |
| 301 user_sizes_.push_back(success ? size : -1); |
| 302 if (user_sizes_.size() == other_users_.size()) { |
| 303 base::StringValue other_users_size(l10n_util::GetStringUTF16( |
| 304 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN)); |
| 305 // If all the requests succeed, shows the total bytes in the UI. |
| 306 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { |
| 307 other_users_size = base::StringValue(ui::FormatBytes( |
| 308 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL))); |
| 309 } |
| 310 web_ui()->CallJavascriptFunctionUnsafe( |
| 311 "options.StorageManager.setOtherUsersSize", other_users_size); |
| 312 } |
| 313 } |
| 314 |
| 276 void StorageManagerHandler::UpdateArcSize() { | 315 void StorageManagerHandler::UpdateArcSize() { |
| 277 Profile* const profile = Profile::FromWebUI(web_ui()); | 316 Profile* const profile = Profile::FromWebUI(web_ui()); |
| 278 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || | 317 if (!arc::ArcAuthService::IsAllowedForProfile(profile) || |
| 279 arc::ArcAuthService::IsOptInVerificationDisabled() || | 318 arc::ArcAuthService::IsOptInVerificationDisabled() || |
| 280 !arc::ArcAuthService::Get()->IsArcEnabled()) { | 319 !arc::ArcAuthService::Get()->IsArcEnabled()) { |
| 281 return; | 320 return; |
| 282 } | 321 } |
| 283 | 322 |
| 284 // Shows the item "Android apps and cache" and start calculating size. | 323 // Shows the item "Android apps and cache" and start calculating size. |
| 285 web_ui()->CallJavascriptFunctionUnsafe( | 324 web_ui()->CallJavascriptFunctionUnsafe( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 310 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 349 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
| 311 arc_size); | 350 arc_size); |
| 312 } | 351 } |
| 313 | 352 |
| 314 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { | 353 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
| 315 UpdateDriveCacheSize(); | 354 UpdateDriveCacheSize(); |
| 316 } | 355 } |
| 317 | 356 |
| 318 } // namespace options | 357 } // namespace options |
| 319 } // namespace chromeos | 358 } // namespace chromeos |
| OLD | NEW |