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 d667a36cb5924ac062a16e3a3c91815f76ad5ad0..c04562ea3433f258a47fcab41423d63bec9609d9 100644 |
--- a/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
+++ b/chrome/browser/ui/webui/chromeos/drive_internals_ui.cc |
@@ -6,10 +6,14 @@ |
#include "base/bind.h" |
#include "base/file_util.h" |
+#include "base/format_macros.h" |
+#include "base/stringprintf.h" |
#include "base/memory/weak_ptr.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" |
#include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
+#include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
#include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
#include "chrome/browser/chromeos/gdata/gdata_util.h" |
#include "chrome/browser/profiles/profile.h" |
@@ -96,11 +100,15 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { |
weak_ptr_factory_.GetWeakPtr())); |
} |
+ // Returns a GDataSystemService. |
+ gdata::GDataSystemService* GetSystemService() { |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
+ return gdata::GDataSystemServiceFactory::GetForProfile(profile); |
+ } |
+ |
// Called when the page is first loaded. |
void OnPageLoaded(const base::ListValue* args) { |
- Profile* profile = Profile::FromWebUI(web_ui()); |
- gdata::GDataSystemService* system_service = |
- gdata::GDataSystemServiceFactory::GetForProfile(profile); |
+ gdata::GDataSystemService* system_service = GetSystemService(); |
// |system_service| may be NULL in the guest/incognito mode. |
if (!system_service) |
return; |
@@ -118,6 +126,7 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { |
web_ui()->CallJavascriptFunction("UpdateAuthStatus", auth_status); |
// Start updating the GCache contents section. |
+ Profile* profile = Profile::FromWebUI(web_ui()); |
const FilePath root_path = |
gdata::GDataCache::GetCacheRootPath(profile); |
base::ListValue* gcache_contents = new ListValue; |
@@ -133,8 +142,111 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler { |
void OnGetGCacheContents(base::ListValue* gcache_contents) { |
DCHECK(gcache_contents); |
web_ui()->CallJavascriptFunction("UpdateGCacheContents", *gcache_contents); |
+ |
+ // Start updating the file system tree section, if we have access token. |
+ gdata::GDataSystemService* system_service = GetSystemService(); |
+ if (!system_service->docs_service()->HasAccessToken()) |
+ return; |
+ |
+ // Start rendering the file system tree as text. |
+ const FilePath root_path = FilePath(gdata::kGDataRootDirectory); |
+ system_service->file_system()->ReadDirectoryByPath( |
+ root_path, |
+ base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ root_path)); |
+ } |
+ |
+ // Called when ReadDirectoryByPath() is complete. |
+ void OnReadDirectoryByPath( |
achuithb
2012/07/26 23:00:23
I think it's more readable to split the definition
satorux1
2012/07/27 16:13:44
Done.
|
+ const FilePath& parent_path, |
+ gdata::GDataFileError error, |
+ bool hide_hosted_documents, |
+ scoped_ptr<gdata::GDataEntryProtoVector> entries) { |
+ if (error != gdata::GDATA_FILE_OK) |
+ return; |
+ |
+ DCHECK(entries.get()); |
+ for (size_t i = 0; i < entries->size(); ++i) { |
+ const gdata::GDataEntryProto& entry = (*entries)[i]; |
+ const FilePath current_path = parent_path.Append( |
+ FilePath::FromUTF8Unsafe(entry.base_name())); |
+ |
+ file_system_as_text_.append(FormatEntry(current_path, entry) + "\n"); |
+ |
+ if (entry.file_info().is_directory()) { |
+ GetSystemService()->file_system()->ReadDirectoryByPath( |
+ current_path, |
+ base::Bind(&DriveInternalsWebUIHandler::OnReadDirectoryByPath, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ current_path)); |
+ } |
+ } |
+ |
+ // There may be pending ReadDirectoryByPath() calls, but we can update |
+ // the page with what we have now. This results in progressive |
+ // updates, which is good for a large file system. |
+ const base::StringValue value(file_system_as_text_); |
+ web_ui()->CallJavascriptFunction("UpdateFileSystemContents", value); |
+ } |
+ |
+ // Formats |entry| into text. |
+ std::string FormatEntry(const FilePath& path, |
satorux1
2012/07/27 16:13:44
moved this out of the class.
|
+ const gdata::GDataEntryProto& entry) { |
+ using base::StringAppendF; |
+ using gdata::util::FormatTimeAsString; |
+ |
+ std::string out; |
+ StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str()); |
+ StringAppendF(&out, " title: %s\n", entry.title().c_str()); |
+ StringAppendF(&out, " resource_id: %s\n", entry.resource_id().c_str()); |
+ StringAppendF(&out, " edit_url: %s\n", entry.edit_url().c_str()); |
+ StringAppendF(&out, " content_url: %s\n", entry.content_url().c_str()); |
+ StringAppendF(&out, " parent_resource_id: %s\n", |
+ entry.parent_resource_id().c_str()); |
+ StringAppendF(&out, " upload_url: %s\n", entry.upload_url().c_str()); |
+ |
+ const gdata::PlatformFileInfoProto& file_info = entry.file_info(); |
+ StringAppendF(&out, " file_info\n"); |
+ StringAppendF(&out, " size: %"PRId64"\n", file_info.size()); |
+ StringAppendF(&out, " is_directory: %d\n", file_info.is_directory()); |
+ StringAppendF(&out, " is_symbolic_link: %d\n", |
+ file_info.is_symbolic_link()); |
+ |
+ const base::Time last_modified = base::Time::FromInternalValue( |
+ file_info.last_modified()); |
+ const base::Time last_accessed = base::Time::FromInternalValue( |
+ file_info.last_accessed()); |
+ const base::Time creation_time = base::Time::FromInternalValue( |
+ file_info.creation_time()); |
+ StringAppendF(&out, " last_modified: %s\n", |
+ FormatTimeAsString(last_modified).c_str()); |
+ StringAppendF(&out, " last_accessed: %s\n", |
+ FormatTimeAsString(last_accessed).c_str()); |
+ StringAppendF(&out, " creation_time: %s\n", |
+ FormatTimeAsString(creation_time).c_str()); |
+ |
+ if (entry.has_file_specific_info()) { |
+ const gdata::GDataFileSpecificInfo& file_specific_info = |
+ entry.file_specific_info(); |
+ StringAppendF(&out, " thumbnail_url: %s\n", |
+ file_specific_info.thumbnail_url().c_str()); |
+ StringAppendF(&out, " alternate_url: %s\n", |
+ file_specific_info.alternate_url().c_str()); |
+ StringAppendF(&out, " content_mime_type: %s\n", |
+ file_specific_info.content_mime_type().c_str()); |
+ StringAppendF(&out, " file_md5: %s\n", |
+ file_specific_info.file_md5().c_str()); |
+ StringAppendF(&out, " document_extension: %s\n", |
+ file_specific_info.document_extension().c_str()); |
+ StringAppendF(&out, " is_hosted_document: %d\n", |
+ file_specific_info.is_hosted_document()); |
+ } |
+ |
+ return out; |
} |
+ std::string file_system_as_text_; |
satorux1
2012/07/27 16:13:44
removed this. instead of sending the entire file
|
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_; |
DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler); |
}; |