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

Unified Diff: chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc

Issue 2348913002: Port storage manager to MD settings. (Closed)
Patch Set: Address review comments 2. Created 4 years, 2 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
Index: chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc
diff --git a/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc b/chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc
similarity index 58%
copy from chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
copy to chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc
index 5a3976cb2cd1f8477f085078a381db28697ca9d8..e89ab289fc2f456793922de089a21f1a9c20fe0b 100644
--- a/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc
+++ b/chrome/browser/ui/webui/settings/chromeos/device_storage_handler.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/ui/webui/options/chromeos/storage_manager_handler.h"
+#include "chrome/browser/ui/webui/settings/chromeos/device_storage_handler.h"
#include <algorithm>
#include <numeric>
@@ -38,7 +38,7 @@
#include "ui/base/text/bytes_formatting.h"
namespace chromeos {
-namespace options {
+namespace settings {
namespace {
void GetSizeStatOnBlockingPool(const base::FilePath& mount_path,
@@ -60,7 +60,7 @@ const int64_t kSpaceLowBytes = 1 * 1024 * 1024 * 1024;
} // namespace
-StorageManagerHandler::StorageManagerHandler()
+StorageHandler::StorageHandler()
: browser_cache_size_(-1),
has_browser_cache_size_(false),
browser_site_data_size_(-1),
@@ -68,115 +68,46 @@ StorageManagerHandler::StorageManagerHandler()
updating_downloads_size_(false),
updating_drive_cache_size_(false),
updating_browsing_data_size_(false),
- updating_arc_size_(false),
- updating_other_users_size_(false),
- weak_ptr_factory_(this) {
+ updating_android_size_(false),
+ updating_other_users_size_(false) {
}
-StorageManagerHandler::~StorageManagerHandler() {
+StorageHandler::~StorageHandler() {
}
-void StorageManagerHandler::GetLocalizedValues(
- base::DictionaryValue* localized_strings) {
- DCHECK(localized_strings);
-
- RegisterTitle(localized_strings, "storageManagerPage",
- IDS_OPTIONS_SETTINGS_STORAGE_MANAGER_TAB_TITLE);
- RegisterTitle(localized_strings, "storageClearDriveCachePage",
- IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_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));
- localized_strings->SetString(
- "storageSubitemLabelDriveCache", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_DRIVE_CACHE));
- localized_strings->SetString(
- "storageSubitemLabelBrowsingData", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_BROWSING_DATA));
- localized_strings->SetString(
- "storageSubitemLabelOtherUsers", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_OTHER_USERS));
- localized_strings->SetString(
- "storageSubitemLabelArc", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SUBITEM_LABEL_ARC));
- localized_strings->SetString(
- "storageSizeCalculating", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SIZE_CALCULATING));
- localized_strings->SetString(
- "storageClearDriveCacheDialogTitle", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DIALOG_TITLE));
- localized_strings->SetString(
- "storageClearDriveCacheDescription", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_CLEAR_DRIVE_CACHE_DESCRIPTION));
- localized_strings->SetString(
- "storageDeleteAllButtonTitle", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_DELETE_ALL_BUTTON_TITLE));
- localized_strings->SetString(
- "storageLowMessageTitle", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_TITLE));
- localized_strings->SetString(
- "storageLowMessageLine1", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_LINE_1));
- localized_strings->SetString(
- "storageLowMessageLine2", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_LOW_MESSAGE_LINE_2));
- localized_strings->SetString(
- "storageCriticallyLowMessageTitle", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_TITLE));
- localized_strings->SetString(
- "storageCriticallyLowMessageLine1", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_LINE_1));
- localized_strings->SetString(
- "storageCriticallyLowMessageLine2", l10n_util::GetStringUTF16(
- IDS_OPTIONS_SETTINGS_STORAGE_SPACE_CRITICALLY_LOW_MESSAGE_LINE_2));
-}
-
-void StorageManagerHandler::InitializePage() {
- DCHECK(web_ui());
-}
-
-void StorageManagerHandler::RegisterMessages() {
+void StorageHandler::RegisterMessages() {
DCHECK(web_ui());
web_ui()->RegisterMessageCallback(
"updateStorageInfo",
- base::Bind(&StorageManagerHandler::HandleUpdateStorageInfo,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::HandleUpdateStorageInfo,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"openDownloads",
- base::Bind(&StorageManagerHandler::HandleOpenDownloads,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::HandleOpenDownloads,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"openArcStorage",
- base::Bind(&StorageManagerHandler::HandleOpenArcStorage,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::HandleOpenArcStorage,
+ base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"clearDriveCache",
- base::Bind(&StorageManagerHandler::HandleClearDriveCache,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::HandleClearDriveCache,
+ base::Unretained(this)));
}
-void StorageManagerHandler::HandleUpdateStorageInfo(
- const base::ListValue* unused_args) {
+void StorageHandler::HandleUpdateStorageInfo(const base::ListValue* args) {
+ AllowJavascript();
+
UpdateSizeStat();
UpdateDownloadsSize();
UpdateDriveCacheSize();
UpdateBrowsingDataSize();
UpdateOtherUsersSize();
- UpdateArcSize();
+ UpdateAndroidSize();
}
-void StorageManagerHandler::HandleOpenDownloads(
+void StorageHandler::HandleOpenDownloads(
const base::ListValue* unused_args) {
Profile* const profile = Profile::FromWebUI(web_ui());
const base::FilePath downloads_path =
@@ -188,22 +119,22 @@ void StorageManagerHandler::HandleOpenDownloads(
platform_util::OpenOperationCallback());
}
-void StorageManagerHandler::HandleOpenArcStorage(
+void StorageHandler::HandleOpenArcStorage(
const base::ListValue* unused_args) {
arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings();
}
-void StorageManagerHandler::HandleClearDriveCache(
+void StorageHandler::HandleClearDriveCache(
const base::ListValue* unused_args) {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui()));
file_system->FreeDiskSpaceIfNeededFor(
std::numeric_limits<int64_t>::max(), // Removes as much as possible.
- base::Bind(&StorageManagerHandler::OnClearDriveCacheDone,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::OnClearDriveCacheDone,
+ base::Unretained(this)));
}
-void StorageManagerHandler::UpdateSizeStat() {
+void StorageHandler::UpdateSizeStat() {
Profile* const profile = Profile::FromWebUI(web_ui());
const base::FilePath downloads_path =
file_manager::util::GetDownloadsFolderForProfile(profile);
@@ -216,14 +147,14 @@ void StorageManagerHandler::UpdateSizeStat() {
downloads_path,
total_size,
available_size),
- base::Bind(&StorageManagerHandler::OnGetSizeStat,
- weak_ptr_factory_.GetWeakPtr(),
+ base::Bind(&StorageHandler::OnGetSizeStat,
+ base::Unretained(this),
base::Owned(total_size),
base::Owned(available_size)));
}
-void StorageManagerHandler::OnGetSizeStat(int64_t* total_size,
- int64_t* available_size) {
+void StorageHandler::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));
@@ -238,11 +169,12 @@ void StorageManagerHandler::OnGetSizeStat(int64_t* total_size,
storage_space_state = STORAGE_SPACE_LOW;
size_stat.SetInteger("spaceState", storage_space_state);
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setSizeStat", size_stat);
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-size-stat-changed"),
+ size_stat);
}
-void StorageManagerHandler::UpdateDownloadsSize() {
+void StorageHandler::UpdateDownloadsSize() {
if (updating_downloads_size_)
return;
updating_downloads_size_ = true;
@@ -255,18 +187,18 @@ void StorageManagerHandler::UpdateDownloadsSize() {
content::BrowserThread::GetBlockingPool(),
FROM_HERE,
base::Bind(&base::ComputeDirectorySize, downloads_path),
- base::Bind(&StorageManagerHandler::OnGetDownloadsSize,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::OnGetDownloadsSize,
+ base::Unretained(this)));
}
-void StorageManagerHandler::OnGetDownloadsSize(int64_t size) {
+void StorageHandler::OnGetDownloadsSize(int64_t size) {
updating_downloads_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setDownloadsSize",
- base::StringValue(ui::FormatBytes(size)));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-downloads-size-changed"),
+ base::StringValue(ui::FormatBytes(size)));
}
-void StorageManagerHandler::UpdateDriveCacheSize() {
+void StorageHandler::UpdateDriveCacheSize() {
if (updating_drive_cache_size_)
return;
@@ -276,22 +208,22 @@ void StorageManagerHandler::UpdateDriveCacheSize() {
return;
// Shows the item "Offline cache" and start calculating size.
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.showDriveCacheItem");
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-drive-enabled-changed"),
+ base::FundamentalValue(true));
updating_drive_cache_size_ = true;
file_system->CalculateCacheSize(
- base::Bind(&StorageManagerHandler::OnGetDriveCacheSize,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::OnGetDriveCacheSize, base::Unretained(this)));
}
-void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) {
+void StorageHandler::OnGetDriveCacheSize(int64_t size) {
updating_drive_cache_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setDriveCacheSize",
- base::StringValue(ui::FormatBytes(size)));
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-drive-cache-size-changed"),
+ base::StringValue(ui::FormatBytes(size)));
}
-void StorageManagerHandler::UpdateBrowsingDataSize() {
+void StorageHandler::UpdateBrowsingDataSize() {
if (updating_browsing_data_size_)
return;
updating_browsing_data_size_ = true;
@@ -305,8 +237,8 @@ void StorageManagerHandler::UpdateBrowsingDataSize() {
content::BrowserContext::GetDefaultStoragePartition(profile),
base::Time(),
base::Time::Max())->Count(
- base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
- weak_ptr_factory_.GetWeakPtr(), false));
+ base::Bind(&StorageHandler::OnGetBrowsingDataSize,
+ base::Unretained(this), false));
// Fetch the size of site data in browsing data.
if (!site_data_size_collector_.get()) {
@@ -330,12 +262,11 @@ void StorageManagerHandler::UpdateBrowsingDataSize() {
BrowsingDataFlashLSOHelper::Create(profile)));
}
site_data_size_collector_->Fetch(
- base::Bind(&StorageManagerHandler::OnGetBrowsingDataSize,
- weak_ptr_factory_.GetWeakPtr(), true));
+ base::Bind(&StorageHandler::OnGetBrowsingDataSize,
+ base::Unretained(this), true));
}
-void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data,
- int64_t size) {
+void StorageHandler::OnGetBrowsingDataSize(bool is_site_data, int64_t size) {
if (is_site_data) {
has_browser_site_data_size_ = true;
browser_site_data_size_ = size;
@@ -353,13 +284,14 @@ void StorageManagerHandler::OnGetBrowsingDataSize(bool is_site_data,
IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
}
updating_browsing_data_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setBrowsingDataSize",
+ CallJavascriptFunction(
+ "cr.webUIListenerCallback",
+ base::StringValue("storage-browsing-data-size-changed"),
base::StringValue(size_string));
}
}
-void StorageManagerHandler::UpdateOtherUsersSize() {
+void StorageHandler::UpdateOtherUsersSize() {
if (updating_other_users_size_)
return;
updating_other_users_size_ = true;
@@ -374,19 +306,20 @@ void StorageManagerHandler::UpdateOtherUsersSize() {
other_users_.push_back(user);
cryptohome::HomedirMethods::GetInstance()->GetAccountDiskUsage(
cryptohome::Identification(user->GetAccountId()),
- base::Bind(&StorageManagerHandler::OnGetOtherUserSize,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::OnGetOtherUserSize,
+ base::Unretained(this)));
}
// We should show "0 B" if there is no other user.
if (other_users_.empty()) {
updating_other_users_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setOtherUsersSize",
+ CallJavascriptFunction(
+ "cr.webUIListenerCallback",
+ base::StringValue("storage-other-users-size-changed"),
base::StringValue(ui::FormatBytes(0)));
}
}
-void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) {
+void StorageHandler::OnGetOtherUserSize(bool success, int64_t size) {
user_sizes_.push_back(success ? size : -1);
if (user_sizes_.size() == other_users_.size()) {
base::string16 size_string;
@@ -399,16 +332,17 @@ void StorageManagerHandler::OnGetOtherUserSize(bool success, int64_t size) {
IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
}
updating_other_users_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.setOtherUsersSize",
+ CallJavascriptFunction(
+ "cr.webUIListenerCallback",
+ base::StringValue("storage-other-users-size-changed"),
base::StringValue(size_string));
}
}
-void StorageManagerHandler::UpdateArcSize() {
- if (updating_arc_size_)
+void StorageHandler::UpdateAndroidSize() {
+ if (updating_android_size_)
return;
- updating_arc_size_ = true;
+ updating_android_size_ = true;
Profile* const profile = Profile::FromWebUI(web_ui());
if (!arc::ArcAuthService::IsAllowedForProfile(profile) ||
@@ -418,17 +352,18 @@ void StorageManagerHandler::UpdateArcSize() {
}
// Shows the item "Android apps and cache" and start calculating size.
- web_ui()->CallJavascriptFunctionUnsafe(
- "options.StorageManager.showArcItem");
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-android-enabled-changed"),
+ base::FundamentalValue(true));
bool success = arc::ArcStorageManager::Get()->GetApplicationsSize(
- base::Bind(&StorageManagerHandler::OnGetArcSize,
- weak_ptr_factory_.GetWeakPtr()));
+ base::Bind(&StorageHandler::OnGetAndroidSize,
+ base::Unretained(this)));
if (!success)
- updating_arc_size_ = false;
+ updating_android_size_ = false;
}
-void StorageManagerHandler::OnGetArcSize(bool succeeded,
- arc::mojom::ApplicationsSizePtr size) {
+void StorageHandler::OnGetAndroidSize(bool succeeded,
+ arc::mojom::ApplicationsSizePtr size) {
base::string16 size_string;
if (succeeded) {
uint64_t total_bytes = size->total_code_bytes +
@@ -439,14 +374,15 @@ void StorageManagerHandler::OnGetArcSize(bool succeeded,
size_string = l10n_util::GetStringUTF16(
IDS_OPTIONS_SETTINGS_STORAGE_SIZE_UNKNOWN);
}
- updating_arc_size_ = false;
- web_ui()->CallJavascriptFunctionUnsafe("options.StorageManager.setArcSize",
- base::StringValue(size_string));
+ updating_android_size_ = false;
+ CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("storage-android-size-changed"),
+ base::StringValue(size_string));
}
-void StorageManagerHandler::OnClearDriveCacheDone(bool success) {
+void StorageHandler::OnClearDriveCacheDone(bool success) {
UpdateDriveCacheSize();
}
-} // namespace options
+} // namespace settings
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698