Commit 6a17682d authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Drive: Show the total size of cache files at chrome://drive-internals.

BUG=135197

Review URL: https://chromiumcodereview.appspot.com/10834168

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150061 0039d316-1c4b-4281-b951-d872f2087c98
parent 8e581967
...@@ -29,6 +29,13 @@ ...@@ -29,6 +29,13 @@
</tbody> </tbody>
</table> </table>
<ul>
<li>
Total Size:
<span id='gcache-summary-total-size'>(calculating...)</span> bytes.
</li>
</ul>
<h2 id='file-system-contents-section'>File System Contents</h2> <h2 id='file-system-contents-section'>File System Contents</h2>
<div id='file-system-contents'></div> <div id='file-system-contents'></div>
......
...@@ -15,8 +15,9 @@ function updateAuthStatus(authStatus) { ...@@ -15,8 +15,9 @@ function updateAuthStatus(authStatus) {
* Updates the GCache Contents section. * Updates the GCache Contents section.
* @param {Array} gcacheContents List of dictionaries describing metadata * @param {Array} gcacheContents List of dictionaries describing metadata
* of files and directories under the GCache directory. * of files and directories under the GCache directory.
* @param {Object} gcacheSummary Dictionary of summary of GCache.
*/ */
function updateGCacheContents(gcacheContents) { function updateGCacheContents(gcacheContents, gcacheSummary) {
var tbody = $('gcache-contents'); var tbody = $('gcache-contents');
for (var i = 0; i < gcacheContents.length; i++) { for (var i = 0; i < gcacheContents.length; i++) {
var entry = gcacheContents[i]; var entry = gcacheContents[i];
...@@ -34,6 +35,8 @@ function updateGCacheContents(gcacheContents) { ...@@ -34,6 +35,8 @@ function updateGCacheContents(gcacheContents) {
tr.appendChild(createElementFromText('td', entry.last_modified)); tr.appendChild(createElementFromText('td', entry.last_modified));
tbody.appendChild(tr); tbody.appendChild(tr);
} }
$('gcache-summary-total-size').textContent = gcacheSummary['total_size'];
} }
/** /**
......
...@@ -39,7 +39,8 @@ namespace { ...@@ -39,7 +39,8 @@ namespace {
// //
// The list is sorted by the path. // The list is sorted by the path.
void GetGCacheContents(const FilePath& root_path, void GetGCacheContents(const FilePath& root_path,
base::ListValue* gcache_contents) { base::ListValue* gcache_contents,
base::DictionaryValue* gcache_summary) {
using file_util::FileEnumerator; using file_util::FileEnumerator;
// Use this map to sort the result list by the path. // Use this map to sort the result list by the path.
std::map<FilePath, DictionaryValue*> files; std::map<FilePath, DictionaryValue*> files;
...@@ -52,6 +53,7 @@ void GetGCacheContents(const FilePath& root_path, ...@@ -52,6 +53,7 @@ void GetGCacheContents(const FilePath& root_path,
true, // recursive true, // recursive
static_cast<FileEnumerator::FileType>(options)); static_cast<FileEnumerator::FileType>(options));
int64 total_size = 0;
for (FilePath current = enumerator.Next(); !current.empty(); for (FilePath current = enumerator.Next(); !current.empty();
current = enumerator.Next()) { current = enumerator.Next()) {
FileEnumerator::FindInfo find_info; FileEnumerator::FindInfo find_info;
...@@ -70,8 +72,9 @@ void GetGCacheContents(const FilePath& root_path, ...@@ -70,8 +72,9 @@ void GetGCacheContents(const FilePath& root_path,
entry->SetBoolean("is_symbolic_link", is_symbolic_link); entry->SetBoolean("is_symbolic_link", is_symbolic_link);
entry->SetString("last_modified", entry->SetString("last_modified",
gdata::util::FormatTimeAsString(last_modified)); gdata::util::FormatTimeAsString(last_modified));
files[current] = entry; files[current] = entry;
total_size += size;
} }
// Convert |files| into |gcache_contents|. // Convert |files| into |gcache_contents|.
...@@ -79,6 +82,8 @@ void GetGCacheContents(const FilePath& root_path, ...@@ -79,6 +82,8 @@ void GetGCacheContents(const FilePath& root_path,
iter = files.begin(); iter != files.end(); ++iter) { iter = files.begin(); iter != files.end(); ++iter) {
gcache_contents->Append(iter->second); gcache_contents->Append(iter->second);
} }
gcache_summary->SetDouble("total_size", total_size);
} }
// Formats |entry| into text. // Formats |entry| into text.
...@@ -159,7 +164,8 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { ...@@ -159,7 +164,8 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
void OnPageLoaded(const base::ListValue* args); void OnPageLoaded(const base::ListValue* args);
// Called when GetGCacheContents() is complete. // Called when GetGCacheContents() is complete.
void OnGetGCacheContents(base::ListValue* gcache_contents); void OnGetGCacheContents(base::ListValue* gcache_contents,
base::DictionaryValue* cache_summary);
// Called when ReadDirectoryByPath() is complete. // Called when ReadDirectoryByPath() is complete.
void OnReadDirectoryByPath(const FilePath& parent_path, void OnReadDirectoryByPath(const FilePath& parent_path,
...@@ -217,18 +223,27 @@ void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) { ...@@ -217,18 +223,27 @@ void DriveInternalsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
const FilePath root_path = const FilePath root_path =
gdata::GDataCache::GetCacheRootPath(profile); gdata::GDataCache::GetCacheRootPath(profile);
base::ListValue* gcache_contents = new ListValue; base::ListValue* gcache_contents = new ListValue;
base::DictionaryValue* gcache_summary = new DictionaryValue;
content::BrowserThread::PostBlockingPoolTaskAndReply( content::BrowserThread::PostBlockingPoolTaskAndReply(
FROM_HERE, FROM_HERE,
base::Bind(&GetGCacheContents, root_path, gcache_contents), base::Bind(&GetGCacheContents,
root_path,
gcache_contents,
gcache_summary),
base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents, base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents,
weak_ptr_factory_.GetWeakPtr(), weak_ptr_factory_.GetWeakPtr(),
base::Owned(gcache_contents))); base::Owned(gcache_contents),
base::Owned(gcache_summary)));
} }
void DriveInternalsWebUIHandler::OnGetGCacheContents( void DriveInternalsWebUIHandler::OnGetGCacheContents(
base::ListValue* gcache_contents) { base::ListValue* gcache_contents,
base::DictionaryValue* gcache_summary) {
DCHECK(gcache_contents); DCHECK(gcache_contents);
web_ui()->CallJavascriptFunction("updateGCacheContents", *gcache_contents); DCHECK(gcache_summary);
web_ui()->CallJavascriptFunction("updateGCacheContents",
*gcache_contents,
*gcache_summary);
// Start updating the file system tree section, if we have access token. // Start updating the file system tree section, if we have access token.
gdata::GDataSystemService* system_service = GetSystemService(); gdata::GDataSystemService* system_service = GetSystemService();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment