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

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

Issue 2041343002: Storage manager: Show overall size information and size of Downloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and rebase on top of https://codereview.chromium.org/1995113002. Created 4 years, 6 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc b/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
index aa25f873a897c182d1bcba3a316fb0068d05269f..6616c3dc4f3d81582e1ccfc5671d50d6dbf5500b 100644
--- a/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
+++ b/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
@@ -4,12 +4,36 @@
#include "chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h"
+#include <sys/statvfs.h>
+
+#include "base/files/file_util.h"
+#include "base/posix/eintr_wrapper.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/file_manager/path_util.h"
+#include "chrome/browser/platform_util.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/grit/generated_resources.h"
+#include "content/public/browser/browser_thread.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/text/bytes_formatting.h"
namespace chromeos {
namespace options {
+namespace {
-StorageManagerHandler::StorageManagerHandler() {
+void GetSizeStatOnBlockingPool(const std::string& mount_path,
+ int64_t* total_size,
+ int64_t* available_size) {
+ struct statvfs stat = {};
+ if (HANDLE_EINTR(statvfs(mount_path.c_str(), &stat)) == 0) {
+ *total_size = static_cast<int64_t>(stat.f_blocks) * stat.f_frsize;
+ *available_size = static_cast<int64_t>(stat.f_bavail) * stat.f_frsize;
+ }
+}
+
+} // namespace
+
+StorageManagerHandler::StorageManagerHandler() : weak_ptr_factory_(this) {
}
StorageManagerHandler::~StorageManagerHandler() {
@@ -21,6 +45,19 @@ void StorageManagerHandler::GetLocalizedValues(
RegisterTitle(localized_strings, "storageManagerPage",
IDS_OPTIONS_SETTINGS_STORAGE_MANAGER_TAB_TITLE);
+
+ localized_strings->SetString(
+ "storageItemLabelCapacity", l10n_util::GetStringUTF16(
+ IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_CAPACITY));
+ localized_strings->SetString(
+ "storageItemLabelInUse", l10n_util::GetStringUTF16(
+ IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_IN_USE));
+ localized_strings->SetString(
+ "storageItemLabelAvailable", l10n_util::GetStringUTF16(
+ IDS_OPTIONS_SETTINGS_STORAGE_ITEM_LABEL_AVAILABLE));
+ localized_strings->SetString(
+ "storageSubitemLabelDownloads", l10n_util::GetStringUTF16(
+ IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DOWNLOADS));
}
void StorageManagerHandler::InitializePage() {
@@ -29,6 +66,84 @@ void StorageManagerHandler::InitializePage() {
void StorageManagerHandler::RegisterMessages() {
DCHECK(web_ui());
+
+ web_ui()->RegisterMessageCallback(
+ "updateStorageInfo",
+ base::Bind(&StorageManagerHandler::HandleUpdateStorageInfo,
+ base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "openDownloads",
+ base::Bind(&StorageManagerHandler::HandleOpenDownloads,
+ base::Unretained(this)));
+}
+
+void StorageManagerHandler::HandleUpdateStorageInfo(
+ const base::ListValue* unused_args) {
+ UpdateSizeStat();
+ UpdateDownloadsSize();
+}
+
+void StorageManagerHandler::HandleOpenDownloads(
+ const base::ListValue* unused_args) {
+ Profile* const profile = Profile::FromWebUI(web_ui());
+ const base::FilePath downloads_path =
+ file_manager::util::GetDownloadsFolderForProfile(profile);
+ platform_util::OpenItem(
+ profile,
+ downloads_path,
+ platform_util::OPEN_FOLDER,
+ platform_util::OpenOperationCallback());
+}
+
+void StorageManagerHandler::UpdateSizeStat() {
+ Profile* const profile = Profile::FromWebUI(web_ui());
+ const base::FilePath downloads_path =
+ file_manager::util::GetDownloadsFolderForProfile(profile);
+
+ int64_t* total_size = new int64_t(0);
+ int64_t* available_size = new int64_t(0);
+ content::BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE,
+ base::Bind(&GetSizeStatOnBlockingPool,
+ downloads_path.value(),
+ total_size,
+ available_size),
+ base::Bind(&StorageManagerHandler::OnGetSizeStat,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(total_size),
+ base::Owned(available_size)));
+}
+
+void StorageManagerHandler::OnGetSizeStat(int64_t* total_size,
+ int64_t* available_size) {
+ int64_t used_size = *total_size - *available_size;
+ base::DictionaryValue size_stat;
+ size_stat.SetString("totalSize", ui::FormatBytes(*total_size));
+ size_stat.SetString("availableSize", ui::FormatBytes(*available_size));
+ size_stat.SetString("usedSize", ui::FormatBytes(used_size));
+ size_stat.SetDouble("usedRatio",
+ static_cast<double>(used_size) / *total_size);
+ web_ui()->CallJavascriptFunctionUnsafe(
+ "options.StorageManager.setSizeStat", size_stat);
+}
+
+void StorageManagerHandler::UpdateDownloadsSize() {
+ Profile* const profile = Profile::FromWebUI(web_ui());
+ const base::FilePath downloads_path =
+ file_manager::util::GetDownloadsFolderForProfile(profile);
+
+ base::PostTaskAndReplyWithResult(
+ content::BrowserThread::GetBlockingPool(),
+ FROM_HERE,
+ base::Bind(&base::ComputeDirectorySize, downloads_path),
+ base::Bind(&StorageManagerHandler::OnGetDownloadsSize,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void StorageManagerHandler::OnGetDownloadsSize(int64_t size) {
+ web_ui()->CallJavascriptFunctionUnsafe(
+ "options.StorageManager.setDownloadsSize",
+ base::StringValue(ui::FormatBytes(size)));
}
} // namespace options
« 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