Commit b4306f90 authored by satorux@chromium.org's avatar satorux@chromium.org

gdata: Add Cache Contents section to chrome:drive-internals

This section is used to show states of cached files.

BUG=135328
TEST=the new section is shown in chrome:drive-internals properly

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148823 0039d316-1c4b-4281-b951-d872f2087c98
parent b48f7f75
...@@ -10,3 +10,7 @@ ...@@ -10,3 +10,7 @@
#file-system-contents { #file-system-contents {
font-size: small; font-size: small;
} }
#cache-contents {
font-size: small;
}
...@@ -9,16 +9,42 @@ ...@@ -9,16 +9,42 @@
</head> </head>
<body> <body>
<h1>Drive Internals</h1> <h1>Drive Internals</h1>
<h2>Authentication Status</h2> <div>
<a href="#auth-status-section">Authentication Status</a> |
<a href="#gcache-contents-section">GCache Contents</a> |
<a href="#file-system-contents-section">File System Contents</a> |
<a href="#cache-contents-section">Cache Contents</a>
</div>
<h2 id='auth-status-contents-section'>Authentication Status</h2>
<ul> <ul>
<li>Has refresh token: <span id='has-refresh-token'></span></li> <li>Has refresh token: <span id='has-refresh-token'></span></li>
<li>Has access token: <span id='has-access-token'></span></li> <li>Has access token: <span id='has-access-token'></span></li>
</ul> </ul>
<h2>GCache Contents</h2>
<h2 id='gcache-contents-section'>GCache Contents</h2>
<table> <table>
<tbody id='gcache-contents'></tbody> <tbody id='gcache-contents'>
<tr><th>Path</th><th>Size</th><th>Last Modified</th></tr>
</tbody>
</table> </table>
<h2>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>
<h2 id='cache-contents-section'>Cache Contents</h2>
<table>
<tbody id='cache-contents'>
<tr>
<th>Resource ID</th>
<th>MD5</th>
<th>Present</th>
<th>Pinned</th>
<th>Dirty</th>
<th>Mounted</th>
<th>Persistent</th>
</tr>
</tbody>
</table>
</body> </body>
</html> </html>
...@@ -18,13 +18,6 @@ function updateAuthStatus(authStatus) { ...@@ -18,13 +18,6 @@ function updateAuthStatus(authStatus) {
*/ */
function updateGCacheContents(gcacheContents) { function updateGCacheContents(gcacheContents) {
var tbody = $('gcache-contents'); var tbody = $('gcache-contents');
// Add a header row.
var tr = document.createElement('tr');
tr.appendChild(createElementFromText('th', 'Path'));
tr.appendChild(createElementFromText('th', 'Size'));
tr.appendChild(createElementFromText('th', 'Last Modified'));
tbody.appendChild(tr);
for (var i = 0; i < gcacheContents.length; i++) { for (var i = 0; i < gcacheContents.length; i++) {
var entry = gcacheContents[i]; var entry = gcacheContents[i];
var tr = document.createElement('tr'); var tr = document.createElement('tr');
...@@ -54,6 +47,24 @@ function updateFileSystemContents(directoryContentsAsText) { ...@@ -54,6 +47,24 @@ function updateFileSystemContents(directoryContentsAsText) {
div.appendChild(createElementFromText('pre', directoryContentsAsText)); div.appendChild(createElementFromText('pre', directoryContentsAsText));
} }
/**
* Updates the Cache Contents section.
* @param {Object} cacheEntry Dictionary describing a cache entry.
* The function is called from the C++ side repeatedly.
*/
function updateCacheContents(cacheEntry) {
var tr = document.createElement('tr');
tr.appendChild(createElementFromText('td', cacheEntry.resource_id));
tr.appendChild(createElementFromText('td', cacheEntry.md5));
tr.appendChild(createElementFromText('td', cacheEntry.is_present));
tr.appendChild(createElementFromText('td', cacheEntry.is_pinned));
tr.appendChild(createElementFromText('td', cacheEntry.is_dirty));
tr.appendChild(createElementFromText('td', cacheEntry.is_mounted));
tr.appendChild(createElementFromText('td', cacheEntry.is_persistent));
$('cache-contents').appendChild(tr);
}
/** /**
* Creates an element named |elementName| containing the content |text|. * Creates an element named |elementName| containing the content |text|.
* @param {string} elementName Name of the new element to be created. * @param {string} elementName Name of the new element to be created.
......
...@@ -141,7 +141,8 @@ std::string FormatEntry(const FilePath& path, ...@@ -141,7 +141,8 @@ std::string FormatEntry(const FilePath& path,
class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
public: public:
DriveInternalsWebUIHandler() DriveInternalsWebUIHandler()
: weak_ptr_factory_(this) { : num_pending_reads_(0),
weak_ptr_factory_(this) {
} }
virtual ~DriveInternalsWebUIHandler() { virtual ~DriveInternalsWebUIHandler() {
...@@ -166,6 +167,17 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { ...@@ -166,6 +167,17 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
bool hide_hosted_documents, bool hide_hosted_documents,
scoped_ptr<gdata::GDataEntryProtoVector> entries); scoped_ptr<gdata::GDataEntryProtoVector> entries);
// Called when GetResourceIdsOfAllFilesOnUIThread() is complete.
void OnGetResourceIdsOfAllFiles(
const std::vector<std::string>& resource_ids);
// Called when GetCacheEntryOnUIThread() is complete.
void OnGetCacheEntry(const std::string& resource_id,
bool success,
const gdata::GDataCacheEntry& cache_entry);
// The number of pending ReadDirectoryByPath() calls.
int num_pending_reads_;
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
}; };
...@@ -225,6 +237,7 @@ void DriveInternalsWebUIHandler::OnGetGCacheContents( ...@@ -225,6 +237,7 @@ void DriveInternalsWebUIHandler::OnGetGCacheContents(
// Start rendering the file system tree as text. // Start rendering the file system tree as text.
const FilePath root_path = FilePath(gdata::kGDataRootDirectory); const FilePath root_path = FilePath(gdata::kGDataRootDirectory);
++num_pending_reads_;
system_service->file_system()->ReadDirectoryByPath( system_service->file_system()->ReadDirectoryByPath(
root_path, root_path,
base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
...@@ -237,8 +250,8 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath( ...@@ -237,8 +250,8 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
gdata::GDataFileError error, gdata::GDataFileError error,
bool hide_hosted_documents, bool hide_hosted_documents,
scoped_ptr<gdata::GDataEntryProtoVector> entries) { scoped_ptr<gdata::GDataEntryProtoVector> entries) {
if (error != gdata::GDATA_FILE_OK) --num_pending_reads_;
return; if (error == gdata::GDATA_FILE_OK) {
DCHECK(entries.get()); DCHECK(entries.get());
std::string file_system_as_text; std::string file_system_as_text;
...@@ -250,6 +263,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath( ...@@ -250,6 +263,7 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
file_system_as_text.append(FormatEntry(current_path, entry) + "\n"); file_system_as_text.append(FormatEntry(current_path, entry) + "\n");
if (entry.file_info().is_directory()) { if (entry.file_info().is_directory()) {
++num_pending_reads_;
GetSystemService()->file_system()->ReadDirectoryByPath( GetSystemService()->file_system()->ReadDirectoryByPath(
current_path, current_path,
base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath,
...@@ -263,6 +277,50 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath( ...@@ -263,6 +277,50 @@ void DriveInternalsWebUIHandler::OnReadDirectoryByPath(
// updates, which is good for a large file system. // updates, which is good for a large file system.
const base::StringValue value(file_system_as_text); const base::StringValue value(file_system_as_text);
web_ui()->CallJavascriptFunction("updateFileSystemContents", value); web_ui()->CallJavascriptFunction("updateFileSystemContents", value);
}
// Start updating the cache contents section once all directories are
// processed.
if (num_pending_reads_ == 0) {
GetSystemService()->cache()->GetResourceIdsOfAllFilesOnUIThread(
base::Bind(&DriveInternalsWebUIHandler::OnGetResourceIdsOfAllFiles,
weak_ptr_factory_.GetWeakPtr()));
}
}
void DriveInternalsWebUIHandler::OnGetResourceIdsOfAllFiles(
const std::vector<std::string>& resource_ids) {
for (size_t i = 0; i < resource_ids.size(); ++i) {
const std::string& resource_id = resource_ids[i];
GetSystemService()->cache()->GetCacheEntryOnUIThread(
resource_id,
"", // Don't check MD5.
base::Bind(&DriveInternalsWebUIHandler::OnGetCacheEntry,
weak_ptr_factory_.GetWeakPtr(),
resource_id));
}
}
void DriveInternalsWebUIHandler::OnGetCacheEntry(
const std::string& resource_id,
bool success,
const gdata::GDataCacheEntry& cache_entry) {
if (!success) {
LOG(ERROR) << "Failed to get cache entry: " << resource_id;
return;
}
// Convert |cache_entry| into a dictionary.
base::DictionaryValue value;
value.SetString("resource_id", resource_id);
value.SetString("md5", cache_entry.md5());
value.SetBoolean("is_present", cache_entry.is_present());
value.SetBoolean("is_pinned", cache_entry.is_pinned());
value.SetBoolean("is_dirty", cache_entry.is_dirty());
value.SetBoolean("is_mounted", cache_entry.is_mounted());
value.SetBoolean("is_persistent", cache_entry.is_persistent());
web_ui()->CallJavascriptFunction("updateCacheContents", value);
} }
} // namespace } // namespace
......
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