Chromium Code Reviews| 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..da0b6256f3f389a4fd87e2b461d53c6de7dbbd5b 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,14 @@ void GetGCacheContents(const FilePath& root_path, |
| gcache_summary->SetDouble("total_size", total_size); |
| } |
| +void GetFreeDiskSpace(const FilePath& path, |
|
satorux1
2012/08/17 10:50:49
function comment is missing.
Haruki Sato
2012/08/17 15:08:45
Done.
Thanks.
|
| + base::DictionaryValue* local_storage_summary) { |
| + DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
satorux1
2012/08/17 10:50:49
let's add
DCHECK(local_storage_summary);
Haruki Sato
2012/08/17 15:08:45
Done.
|
| + |
| + int64 free_space = base::SysInfo::AmountOfFreeDiskSpace(path); |
|
satorux1
2012/08/17 10:50:49
matter of taste, but you might want to add 'const'
Haruki Sato
2012/08/17 15:08:45
Done.
|
| + local_storage_summary->SetDouble("free_space", free_space); |
| +} |
| + |
| // Formats |entry| into text. |
| std::string FormatEntry(const FilePath& path, |
| const gdata::GDataEntryProto& entry) { |
| @@ -179,6 +191,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 +213,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 +238,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 +248,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 path; |
|
satorux1
2012/08/17 10:50:49
let's make it a bit more descriptive.
path -> hom
Haruki Sato
2012/08/17 15:08:45
Done.
|
| + if (PathService::Get(base::DIR_HOME, &path)) { |
| + base::DictionaryValue* local_storage_summary = new DictionaryValue; |
| + BrowserThread::PostBlockingPoolTaskAndReply( |
| + FROM_HERE, |
| + base::Bind(&GetFreeDiskSpace, 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 +366,15 @@ void DriveInternalsWebUIHandler::OnGetCacheEntry( |
| web_ui()->CallJavascriptFunction("updateCacheContents", value); |
| } |
| +void DriveInternalsWebUIHandler::OnGetFreeDiskSpace( |
| + base::DictionaryValue* local_storage_summary) { |
| + DCHECK(local_storage_summary); |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
|
satorux1
2012/08/17 10:50:49
nit: reverse the two DCHECKs
Haruki Sato
2012/08/17 15:08:45
Done.
|
| + |
| + web_ui()->CallJavascriptFunction( |
| + "updateLocalStorageUsage", *local_storage_summary); |
| +} |
| + |
| } // namespace |
| DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui) |