| 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> | 7 #include <algorithm> |
| 8 #include <numeric> | 8 #include <numeric> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 base::TaskPriority::BACKGROUND), | 254 base::TaskPriority::BACKGROUND), |
| 255 base::Bind(&base::ComputeDirectorySize, downloads_path), | 255 base::Bind(&base::ComputeDirectorySize, downloads_path), |
| 256 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, | 256 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, |
| 257 weak_ptr_factory_.GetWeakPtr())); | 257 weak_ptr_factory_.GetWeakPtr())); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { | 260 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { |
| 261 updating_downloads_size_ = false; | 261 updating_downloads_size_ = false; |
| 262 web_ui()->CallJavascriptFunctionUnsafe( | 262 web_ui()->CallJavascriptFunctionUnsafe( |
| 263 "options.StorageManager.setDownloadsSize", | 263 "options.StorageManager.setDownloadsSize", |
| 264 base::StringValue(ui::FormatBytes(size))); | 264 base::Value(ui::FormatBytes(size))); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void StorageManagerHandler::UpdateDriveCacheSize() { | 267 void StorageManagerHandler::UpdateDriveCacheSize() { |
| 268 if (updating_drive_cache_size_) | 268 if (updating_drive_cache_size_) |
| 269 return; | 269 return; |
| 270 | 270 |
| 271 drive::FileSystemInterface* const file_system = | 271 drive::FileSystemInterface* const file_system = |
| 272 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); | 272 drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); |
| 273 if (!file_system) | 273 if (!file_system) |
| 274 return; | 274 return; |
| 275 | 275 |
| 276 // Shows the item "Offline cache" and start calculating size. | 276 // Shows the item "Offline cache" and start calculating size. |
| 277 web_ui()->CallJavascriptFunctionUnsafe( | 277 web_ui()->CallJavascriptFunctionUnsafe( |
| 278 "options.StorageManager.showDriveCacheItem"); | 278 "options.StorageManager.showDriveCacheItem"); |
| 279 updating_drive_cache_size_ = true; | 279 updating_drive_cache_size_ = true; |
| 280 file_system->CalculateCacheSize( | 280 file_system->CalculateCacheSize( |
| 281 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, | 281 base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, |
| 282 weak_ptr_factory_.GetWeakPtr())); | 282 weak_ptr_factory_.GetWeakPtr())); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { | 285 void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { |
| 286 updating_drive_cache_size_ = false; | 286 updating_drive_cache_size_ = false; |
| 287 web_ui()->CallJavascriptFunctionUnsafe( | 287 web_ui()->CallJavascriptFunctionUnsafe( |
| 288 "options.StorageManager.setDriveCacheSize", | 288 "options.StorageManager.setDriveCacheSize", |
| 289 base::StringValue(ui::FormatBytes(size))); | 289 base::Value(ui::FormatBytes(size))); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void StorageManagerHandler::UpdateBrowsingDataSize() { | 292 void StorageManagerHandler::UpdateBrowsingDataSize() { |
| 293 if (updating_browsing_data_size_) | 293 if (updating_browsing_data_size_) |
| 294 return; | 294 return; |
| 295 updating_browsing_data_size_ = true; | 295 updating_browsing_data_size_ = true; |
| 296 | 296 |
| 297 has_browser_cache_size_ = false; | 297 has_browser_cache_size_ = false; |
| 298 has_browser_site_data_size_ = false; | 298 has_browser_site_data_size_ = false; |
| 299 Profile* const profile = Profile::FromWebUI(web_ui()); | 299 Profile* const profile = Profile::FromWebUI(web_ui()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 base::string16 size_string; | 350 base::string16 size_string; |
| 351 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) { | 351 if (browser_cache_size_ >= 0 && browser_site_data_size_ >= 0) { |
| 352 size_string = ui::FormatBytes( | 352 size_string = ui::FormatBytes( |
| 353 browser_site_data_size_ + browser_cache_size_); | 353 browser_site_data_size_ + browser_cache_size_); |
| 354 } else { | 354 } else { |
| 355 size_string = l10n_util::GetStringUTF16( | 355 size_string = l10n_util::GetStringUTF16( |
| 356 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 356 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
| 357 } | 357 } |
| 358 updating_browsing_data_size_ = false; | 358 updating_browsing_data_size_ = false; |
| 359 web_ui()->CallJavascriptFunctionUnsafe( | 359 web_ui()->CallJavascriptFunctionUnsafe( |
| 360 "options.StorageManager.setBrowsingDataSize", | 360 "options.StorageManager.setBrowsingDataSize", base::Value(size_string)); |
| 361 base::StringValue(size_string)); | |
| 362 } | 361 } |
| 363 } | 362 } |
| 364 | 363 |
| 365 void StorageManagerHandler::UpdateOtherUsersSize() { | 364 void StorageManagerHandler::UpdateOtherUsersSize() { |
| 366 if (updating_other_users_size_) | 365 if (updating_other_users_size_) |
| 367 return; | 366 return; |
| 368 updating_other_users_size_ = true; | 367 updating_other_users_size_ = true; |
| 369 | 368 |
| 370 other_users_.clear(); | 369 other_users_.clear(); |
| 371 user_sizes_.clear(); | 370 user_sizes_.clear(); |
| 372 const user_manager::UserList& users = | 371 const user_manager::UserList& users = |
| 373 user_manager::UserManager::Get()->GetUsers(); | 372 user_manager::UserManager::Get()->GetUsers(); |
| 374 for (auto* user : users) { | 373 for (auto* user : users) { |
| 375 if (user->is_active()) | 374 if (user->is_active()) |
| 376 continue; | 375 continue; |
| 377 other_users_.push_back(user); | 376 other_users_.push_back(user); |
| 378 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( | 377 cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage( |
| 379 cryptohome::Identification(user->GetAccountId()), | 378 cryptohome::Identification(user->GetAccountId()), |
| 380 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, | 379 base::Bind(&StorageManagerHandler::OnGetOtherUserSize, |
| 381 weak_ptr_factory_.GetWeakPtr())); | 380 weak_ptr_factory_.GetWeakPtr())); |
| 382 } | 381 } |
| 383 // We should show "0 B" if there is no other user. | 382 // We should show "0 B" if there is no other user. |
| 384 if (other_users_.empty()) { | 383 if (other_users_.empty()) { |
| 385 updating_other_users_size_ = false; | 384 updating_other_users_size_ = false; |
| 386 web_ui()->CallJavascriptFunctionUnsafe( | 385 web_ui()->CallJavascriptFunctionUnsafe( |
| 387 "options.StorageManager.setOtherUsersSize", | 386 "options.StorageManager.setOtherUsersSize", |
| 388 base::StringValue(ui::FormatBytes(0))); | 387 base::Value(ui::FormatBytes(0))); |
| 389 } | 388 } |
| 390 } | 389 } |
| 391 | 390 |
| 392 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { | 391 void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) { |
| 393 user_sizes_.push_back(success ? size : -1); | 392 user_sizes_.push_back(success ? size : -1); |
| 394 if (user_sizes_.size() == other_users_.size()) { | 393 if (user_sizes_.size() == other_users_.size()) { |
| 395 base::string16 size_string; | 394 base::string16 size_string; |
| 396 // If all the requests succeed, shows the total bytes in the UI. | 395 // If all the requests succeed, shows the total bytes in the UI. |
| 397 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { | 396 if (std::count(user_sizes_.begin(), user_sizes_.end(), -1) == 0) { |
| 398 size_string = ui::FormatBytes( | 397 size_string = ui::FormatBytes( |
| 399 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL)); | 398 std::accumulate(user_sizes_.begin(), user_sizes_.end(), 0LL)); |
| 400 } else { | 399 } else { |
| 401 size_string = l10n_util::GetStringUTF16( | 400 size_string = l10n_util::GetStringUTF16( |
| 402 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 401 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
| 403 } | 402 } |
| 404 updating_other_users_size_ = false; | 403 updating_other_users_size_ = false; |
| 405 web_ui()->CallJavascriptFunctionUnsafe( | 404 web_ui()->CallJavascriptFunctionUnsafe( |
| 406 "options.StorageManager.setOtherUsersSize", | 405 "options.StorageManager.setOtherUsersSize", base::Value(size_string)); |
| 407 base::StringValue(size_string)); | |
| 408 } | 406 } |
| 409 } | 407 } |
| 410 | 408 |
| 411 void StorageManagerHandler::UpdateArcSize() { | 409 void StorageManagerHandler::UpdateArcSize() { |
| 412 if (updating_arc_size_) | 410 if (updating_arc_size_) |
| 413 return; | 411 return; |
| 414 updating_arc_size_ = true; | 412 updating_arc_size_ = true; |
| 415 | 413 |
| 416 Profile* const profile = Profile::FromWebUI(web_ui()); | 414 Profile* const profile = Profile::FromWebUI(web_ui()); |
| 417 if (!arc::IsArcPlayStoreEnabledForProfile(profile) || | 415 if (!arc::IsArcPlayStoreEnabledForProfile(profile) || |
| (...skipping 18 matching lines...) Expand all Loading... |
| 436 uint64_t total_bytes = size->total_code_bytes + | 434 uint64_t total_bytes = size->total_code_bytes + |
| 437 size->total_data_bytes + | 435 size->total_data_bytes + |
| 438 size->total_cache_bytes; | 436 size->total_cache_bytes; |
| 439 size_string = ui::FormatBytes(total_bytes); | 437 size_string = ui::FormatBytes(total_bytes); |
| 440 } else { | 438 } else { |
| 441 size_string = l10n_util::GetStringUTF16( | 439 size_string = l10n_util::GetStringUTF16( |
| 442 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); | 440 IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN); |
| 443 } | 441 } |
| 444 updating_arc_size_ = false; | 442 updating_arc_size_ = false; |
| 445 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 443 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
| 446 base::StringValue(size_string)); | 444 base::Value(size_string)); |
| 447 } | 445 } |
| 448 | 446 |
| 449 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { | 447 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
| 450 UpdateDriveCacheSize(); | 448 UpdateDriveCacheSize(); |
| 451 } | 449 } |
| 452 | 450 |
| 453 } // namespace options | 451 } // namespace options |
| 454 } // namespace chromeos | 452 } // namespace chromeos |
| OLD | NEW |