| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 } | 205 } |
| 206 | 206 |
| 207 void StorageManagerHandler::UpdateSizeStat() { | 207 void StorageManagerHandler::UpdateSizeStat() { |
| 208 Profile* const profile = Profile::FromWebUI(web_ui()); | 208 Profile* const profile = Profile::FromWebUI(web_ui()); |
| 209 const base::FilePath downloads_path = | 209 const base::FilePath downloads_path = |
| 210 file_manager::util::GetDownloadsFolderForProfile(profile); | 210 file_manager::util::GetDownloadsFolderForProfile(profile); |
| 211 | 211 |
| 212 int64_t* total_size = new int64_t(0); | 212 int64_t* total_size = new int64_t(0); |
| 213 int64_t* available_size = new int64_t(0); | 213 int64_t* available_size = new int64_t(0); |
| 214 base::PostTaskWithTraitsAndReply( | 214 base::PostTaskWithTraitsAndReply( |
| 215 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 215 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 216 base::TaskPriority::BACKGROUND), | |
| 217 base::Bind(&GetSizeStatAsync, downloads_path, total_size, available_size), | 216 base::Bind(&GetSizeStatAsync, downloads_path, total_size, available_size), |
| 218 base::Bind(&StorageManagerHandler::OnGetSizeStat, | 217 base::Bind(&StorageManagerHandler::OnGetSizeStat, |
| 219 weak_ptr_factory_.GetWeakPtr(), base::Owned(total_size), | 218 weak_ptr_factory_.GetWeakPtr(), base::Owned(total_size), |
| 220 base::Owned(available_size))); | 219 base::Owned(available_size))); |
| 221 } | 220 } |
| 222 | 221 |
| 223 void StorageManagerHandler::OnGetSizeStat(int64_t* total_size, | 222 void StorageManagerHandler::OnGetSizeStat(int64_t* total_size, |
| 224 int64_t* available_size) { | 223 int64_t* available_size) { |
| 225 int64_t used_size = *total_size - *available_size; | 224 int64_t used_size = *total_size - *available_size; |
| 226 base::DictionaryValue size_stat; | 225 base::DictionaryValue size_stat; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 243 void StorageManagerHandler::UpdateDownloadsSize() { | 242 void StorageManagerHandler::UpdateDownloadsSize() { |
| 244 if (updating_downloads_size_) | 243 if (updating_downloads_size_) |
| 245 return; | 244 return; |
| 246 updating_downloads_size_ = true; | 245 updating_downloads_size_ = true; |
| 247 | 246 |
| 248 Profile* const profile = Profile::FromWebUI(web_ui()); | 247 Profile* const profile = Profile::FromWebUI(web_ui()); |
| 249 const base::FilePath downloads_path = | 248 const base::FilePath downloads_path = |
| 250 file_manager::util::GetDownloadsFolderForProfile(profile); | 249 file_manager::util::GetDownloadsFolderForProfile(profile); |
| 251 | 250 |
| 252 base::PostTaskWithTraitsAndReplyWithResult( | 251 base::PostTaskWithTraitsAndReplyWithResult( |
| 253 FROM_HERE, base::TaskTraits().MayBlock().WithPriority( | 252 FROM_HERE, {base::MayBlock(), base::TaskPriority::BACKGROUND}, |
| 254 base::TaskPriority::BACKGROUND), | |
| 255 base::Bind(&base::ComputeDirectorySize, downloads_path), | 253 base::Bind(&base::ComputeDirectorySize, downloads_path), |
| 256 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, | 254 base::Bind(&StorageManagerHandler::OnGetDownloadsSize, |
| 257 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 258 } | 256 } |
| 259 | 257 |
| 260 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { | 258 void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { |
| 261 updating_downloads_size_ = false; | 259 updating_downloads_size_ = false; |
| 262 web_ui()->CallJavascriptFunctionUnsafe( | 260 web_ui()->CallJavascriptFunctionUnsafe( |
| 263 "options.StorageManager.setDownloadsSize", | 261 "options.StorageManager.setDownloadsSize", |
| 264 base::Value(ui::FormatBytes(size))); | 262 base::Value(ui::FormatBytes(size))); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", | 441 web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize", |
| 444 base::Value(size_string)); | 442 base::Value(size_string)); |
| 445 } | 443 } |
| 446 | 444 |
| 447 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { | 445 void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
| 448 UpdateDriveCacheSize(); | 446 UpdateDriveCacheSize(); |
| 449 } | 447 } |
| 450 | 448 |
| 451 } // namespace options | 449 } // namespace options |
| 452 } // namespace chromeos | 450 } // namespace chromeos |
| OLD | NEW |