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

Unified Diff: chrome/browser/ui/webui/chromeos/drive_internals_ui.cc

Issue 10827292: Propagate the result of AmountOfFreeSpace to JS and show it in chrome://drive-internals. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: style fixes, small improvements Created 8 years, 4 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/resources/chromeos/drive_internals.js ('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/chromeos/drive_internals_ui.cc
diff --git a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
index 8a875624819598cf3791447dbaafcaa4189d0218..12371e4cdb5525282a330751a2d417f5b3785a4c 100644
--- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
@@ -9,6 +9,8 @@
#include "base/format_macros.h"
#include "base/stringprintf.h"
#include "base/memory/weak_ptr.h"
+#include "base/path_service.h"
+#include "base/sys_info.h"
#include "chrome/browser/chromeos/gdata/gdata.pb.h"
#include "chrome/browser/chromeos/gdata/gdata_auth_service.h"
#include "chrome/browser/chromeos/gdata/gdata_cache.h"
@@ -24,6 +26,8 @@
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
+using content::BrowserThread;
+
namespace chromeos {
namespace {
@@ -83,6 +87,16 @@ void GetGCacheContents(const FilePath& root_path,
gcache_summary->SetDouble("total_size", total_size);
}
+// Gets the available disk space for the path |home_path|.
+void GetFreeDiskSpace(const FilePath& home_path,
+ base::DictionaryValue* local_storage_summary) {
+ DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(local_storage_summary);
+
+ const int64 free_space = base::SysInfo::AmountOfFreeDiskSpace(home_path);
+ local_storage_summary->SetDouble("free_space", free_space);
+}
+
// Formats |entry| into text.
std::string FormatEntry(const FilePath& path,
const gdata::GDataEntryProto& entry) {
@@ -179,6 +193,9 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
bool success,
const gdata::GDataCacheEntry& cache_entry);
+ // Called when GetFreeDiskSpace() is complete.
+ void OnGetFreeDiskSpace(base::DictionaryValue* local_storage_summary);
+
// The number of pending ReadDirectoryByPath() calls.
int num_pending_reads_;
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
@@ -198,6 +215,8 @@ gdata::GDataSystemService* DriveInternalsWebUIHandler::GetSystemService() {
}
void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
gdata::GDataSystemService* system_service = GetSystemService();
// |system_service| may be NULL in the guest/incognito mode.
if (!system_service)
@@ -221,7 +240,7 @@ void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
gdata::GDataCache::GetCacheRootPath(profile);
base::ListValue* gcache_contents = new ListValue;
base::DictionaryValue* gcache_summary = new DictionaryValue;
- content::BrowserThread::PostBlockingPoolTaskAndReply(
+ BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE,
base::Bind(&GetGCacheContents,
root_path,
@@ -231,6 +250,20 @@ void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
weak_ptr_factory_.GetWeakPtr(),
base::Owned(gcache_contents),
base::Owned(gcache_summary)));
+
+ // Propagate the amount of local free space in bytes.
+ FilePath home_path;
+ if (PathService::Get(base::DIR_HOME, &home_path)) {
+ base::DictionaryValue* local_storage_summary = new DictionaryValue;
+ BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE,
+ base::Bind(&GetFreeDiskSpace, home_path, local_storage_summary),
+ base::Bind(&DriveInternalsWebUIHandler::OnGetFreeDiskSpace,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(local_storage_summary)));
+ } else {
+ LOG(ERROR) << "Home directory not found";
+ }
}
void DriveInternalsWebUIHandler::OnGetGCacheContents(
@@ -335,6 +368,15 @@ void DriveInternalsWebUIHandler::OnGetCacheEntry(
web_ui()->CallJavascriptFunction("updateCacheContents", value);
}
+void DriveInternalsWebUIHandler::OnGetFreeDiskSpace(
+ base::DictionaryValue* local_storage_summary) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(local_storage_summary);
+
+ web_ui()->CallJavascriptFunction(
+ "updateLocalStorageUsage", *local_storage_summary);
+}
+
} // namespace
DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
« no previous file with comments | « chrome/browser/resources/chromeos/drive_internals.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698