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 34afd551778dd2b6436b76aa642e00b76d625da4..d8214542295d0f302e500b5faf02ec2891c37112 100644 |
--- a/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc |
+++ b/chrome/browser/ui/webui/options/chromeos/storage_manager_handler.cc |
@@ -10,10 +10,12 @@ |
#include "base/sys_info.h" |
#include "chrome/browser/browser_process.h" |
#include "chrome/browser/chromeos/arc/arc_auth_service.h" |
+#include "chrome/browser/chromeos/drive/file_system_util.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 "components/drive/chromeos/file_system_interface.h" |
#include "content/public/browser/browser_thread.h" |
#include "ui/base/l10n/l10n_util.h" |
#include "ui/base/text/bytes_formatting.h" |
@@ -47,6 +49,8 @@ void StorageManagerHandler::GetLocalizedValues( |
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( |
@@ -61,11 +65,20 @@ void StorageManagerHandler::GetLocalizedValues( |
"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( |
"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( |
+ "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)); |
} |
void StorageManagerHandler::InitializePage() { |
@@ -87,12 +100,17 @@ void StorageManagerHandler::RegisterMessages() { |
"openArcStorage", |
base::Bind(&StorageManagerHandler::HandleOpenArcStorage, |
base::Unretained(this))); |
+ web_ui()->RegisterMessageCallback( |
+ "clearDriveCache", |
+ base::Bind(&StorageManagerHandler::HandleClearDriveCache, |
+ base::Unretained(this))); |
} |
void StorageManagerHandler::HandleUpdateStorageInfo( |
const base::ListValue* unused_args) { |
UpdateSizeStat(); |
UpdateDownloadsSize(); |
+ UpdateDriveCacheSize(); |
UpdateArcSize(); |
} |
@@ -113,6 +131,16 @@ void StorageManagerHandler::HandleOpenArcStorage( |
arc::ArcStorageManager::Get()->OpenPrivateVolumeSettings(); |
} |
+void StorageManagerHandler::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())); |
+} |
+ |
void StorageManagerHandler::UpdateSizeStat() { |
Profile* const profile = Profile::FromWebUI(web_ui()); |
const base::FilePath downloads_path = |
@@ -164,6 +192,20 @@ void StorageManagerHandler::OnGetDownloadsSize(int64_t size) { |
base::StringValue(ui::FormatBytes(size))); |
} |
+void StorageManagerHandler::UpdateDriveCacheSize() { |
+ drive::FileSystemInterface* const file_system = |
+ drive::util::GetFileSystemByProfile(Profile::FromWebUI(web_ui())); |
+ file_system->CalculateCacheSize( |
+ base::Bind(&StorageManagerHandler::OnGetDriveCacheSize, |
+ weak_ptr_factory_.GetWeakPtr())); |
+} |
+ |
+void StorageManagerHandler::OnGetDriveCacheSize(int64_t size) { |
+ web_ui()->CallJavascriptFunctionUnsafe( |
+ "options.StorageManager.setDriveCacheSize", |
+ base::StringValue(ui::FormatBytes(size))); |
+} |
+ |
void StorageManagerHandler::UpdateArcSize() { |
Profile* const profile = Profile::FromWebUI(web_ui()); |
if (!arc::ArcAuthService::IsAllowedForProfile(profile) || |
@@ -202,5 +244,9 @@ void StorageManagerHandler::OnGetArcSize(bool succeeded, |
arc_size); |
} |
+void StorageManagerHandler::OnClearDriveCacheDone(bool success) { |
+ UpdateDriveCacheSize(); |
+} |
+ |
} // namespace options |
} // namespace chromeos |