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

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

Issue 10823039: gdata: Add GCache Contents section to chrome:drive-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 5 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
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 c2149932478dd3b5284bdff89fa7eaac89da7450..d667a36cb5924ac062a16e3a3c91815f76ad5ad0 100644
--- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
+++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc
@@ -5,13 +5,17 @@
#include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
#include "base/bind.h"
+#include "base/file_util.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/chromeos/gdata/gdata_auth_service.h"
+#include "chrome/browser/chromeos/gdata/gdata_cache.h"
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h"
#include "chrome/browser/chromeos/gdata/gdata_system_service.h"
+#include "chrome/browser/chromeos/gdata/gdata_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
#include "chrome/common/url_constants.h"
+#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
@@ -20,6 +24,59 @@ namespace chromeos {
namespace {
+// Gets metadata of all files and directories in |root_path|
+// recursively. Stores the result as a list of dictionaries like:
+//
+// [{ path: 'GCache/v1/tmp/<resource_id>',
+// size: 12345,
+// is_directory: false,
+// last_modified: '2005-08-09T09:57:00-08:00',
+// },...]
+//
+// The list is sorted by the path.
+void GetGCacheContents(const FilePath& root_path,
+ base::ListValue* gcache_contents) {
+ using file_util::FileEnumerator;
+ // Use this map to sort the result list by the path.
+ std::map<FilePath, DictionaryValue*> files;
+
+ const int options = (file_util::FileEnumerator::FILES |
+ file_util::FileEnumerator::DIRECTORIES |
+ file_util::FileEnumerator::SHOW_SYM_LINKS);
+ FileEnumerator enumerator(
+ root_path,
+ true, // recursive
+ static_cast<FileEnumerator::FileType>(options));
+
+ for (FilePath current = enumerator.Next(); !current.empty();
+ current = enumerator.Next()) {
+ FileEnumerator::FindInfo find_info;
+ enumerator.GetFindInfo(&find_info);
+ int64 size = FileEnumerator::GetFilesize(find_info);
+ const bool is_directory = FileEnumerator::IsDirectory(find_info);
+ const bool is_symbolic_link = FileEnumerator::IsLink(find_info);
+ const base::Time last_modified =
+ FileEnumerator::GetLastModifiedTime(find_info);
+
+ base::DictionaryValue* entry = new base::DictionaryValue;
+ entry->SetString("path", current.value());
+ // Use double instead of integer for large files.
+ entry->SetDouble("size", size);
+ entry->SetBoolean("is_directory", is_directory);
+ entry->SetBoolean("is_symbolic_link", is_symbolic_link);
+ entry->SetString("last_modified",
+ gdata::util::FormatTimeAsString(last_modified));
+
+ files[current] = entry;
+ }
+
+ // Convert |files| into |gcache_contents|.
+ for (std::map<FilePath, DictionaryValue*>::const_iterator
+ iter = files.begin(); iter != files.end(); ++iter) {
+ gcache_contents->Append(iter->second);
+ }
+}
+
// Class to handle messages from chrome://drive-internals.
class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
public:
@@ -59,6 +116,23 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
auth_status.SetBoolean("has-access-token",
documents_service->HasAccessToken());
web_ui()->CallJavascriptFunction("UpdateAuthStatus", auth_status);
+
+ // Start updating the GCache contents section.
+ const FilePath root_path =
+ gdata::GDataCache::GetCacheRootPath(profile);
+ base::ListValue* gcache_contents = new ListValue;
+ content::BrowserThread::PostBlockingPoolTaskAndReply(
+ FROM_HERE,
+ base::Bind(&GetGCacheContents, root_path, gcache_contents),
+ base::Bind(&DriveInternalsWebUIHandler::OnGetGCacheContents,
+ weak_ptr_factory_.GetWeakPtr(),
+ base::Owned(gcache_contents)));
+ }
+
+ // Called when GetGCacheContents() is complete.
+ void OnGetGCacheContents(base::ListValue* gcache_contents) {
+ DCHECK(gcache_contents);
+ web_ui()->CallJavascriptFunction("UpdateGCacheContents", *gcache_contents);
}
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_;
@@ -73,6 +147,7 @@ DriveInternalsUI::DriveInternalsUI(content::WebUI* web_ui)
ChromeWebUIDataSource* source =
new ChromeWebUIDataSource(chrome::kChromeUIDriveInternalsHost);
+ source->add_resource_path("drive_internals.css", IDR_DRIVE_INTERNALS_CSS);
source->add_resource_path("drive_internals.js", IDR_DRIVE_INTERNALS_JS);
source->set_default_resource(IDR_DRIVE_INTERNALS_HTML);

Powered by Google App Engine
This is Rietveld 408576698