Commit ca447a19 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Remove legacy drive related code in drive-internals

Bug: 1003238
Change-Id: I4e981339394c3ff7140b54db0e7dad8a4245cb10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1806158
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697094}
parent 79376c45
......@@ -6,10 +6,6 @@
font-size: small;
}
#file-system-contents {
font-size: small;
}
#cache-contents {
font-size: small;
}
......
......@@ -21,14 +21,6 @@
<li>Push notifications enabled:
<span id="push-notification-enabled"></span>
</li>
<li>
Has refresh token: <span id="has-refresh-token"></span>
<button id="button-clear-refresh-token">clear</button>
</li>
<li>
Has access token: <span id="has-access-token"></span>
<button id="button-clear-access-token">clear</button>
</li>
</ul>
</section>
......@@ -89,12 +81,6 @@
</table>
</section>
<section id="file-system-contents-section" hidden>
<h2>File System Contents</h2>
<button id="button-show-file-entries">Show</button>
<div id="file-system-contents"></div>
</section>
<section id="path-configurations-section" hidden>
<h2>Path Configurations</h2>
<ul id="path-configurations">
......
......@@ -34,8 +34,6 @@ function updateConnectionStatus(connStatus) {
$('connection-status').textContent = connStatus['status'];
$('push-notification-enabled').textContent =
connStatus['push-notification-enabled'];
$('has-refresh-token').textContent = connStatus['has-refresh-token'];
$('has-access-token').textContent = connStatus['has-access-token'];
}
/**
......@@ -77,17 +75,6 @@ function updateGCacheContents(gcacheContents, gcacheSummary) {
toMegaByteString(gcacheSummary['total_size']);
}
/**
* Updates the File System Contents section. The function is called from the
* C++ side repeatedly with contents of a directory.
* @param {string} directoryContentsAsText Pre-formatted string representation
* of contents a directory in the file system.
*/
function updateFileSystemContents(directoryContentsAsText) {
var div = $('file-system-contents');
div.appendChild(createElementFromText('pre', directoryContentsAsText));
}
/**
* Updates the Cache Contents section.
* @param {Object} cacheEntry Dictionary describing a cache entry.
......@@ -302,25 +289,11 @@ document.addEventListener('DOMContentLoaded', function() {
updateToc();
$('button-clear-access-token').addEventListener('click', function() {
chrome.send('clearAccessToken');
});
$('button-clear-refresh-token').addEventListener('click', function() {
chrome.send('clearRefreshToken');
});
$('button-reset-drive-filesystem').addEventListener('click', function() {
$('reset-status-text').textContent = 'resetting...';
chrome.send('resetDriveFileSystem');
});
$('button-show-file-entries').addEventListener('click', function() {
var button = $('button-show-file-entries');
button.parentNode.removeChild(button);
chrome.send('listFileEntries');
});
$('button-export-logs').addEventListener('click', function() {
$('button-export-logs').setAttribute('disabled', 'true');
chrome.send('zipLogs');
......
......@@ -29,7 +29,6 @@
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "chrome/browser/chromeos/drive/debug_info_collector.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/file_manager/path_util.h"
......@@ -43,13 +42,9 @@
#include "chromeos/constants/chromeos_features.h"
#include "components/download/content/public/all_download_item_notifier.h"
#include "components/download/public/common/download_item.h"
#include "components/drive/drive.pb.h"
#include "components/drive/drive_api_util.h"
#include "components/drive/drive_notification_manager.h"
#include "components/drive/drive_pref_names.h"
#include "components/drive/event_logger.h"
#include "components/drive/job_list.h"
#include "components/drive/service/drive_service_interface.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
......@@ -152,74 +147,6 @@ std::pair<base::ListValue, base::DictionaryValue> GetGCacheContents(
return result;
}
// Formats |entry| into text.
std::string FormatEntry(const base::FilePath& path,
const drive::ResourceEntry& entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
using base::StringAppendF;
std::string out;
StringAppendF(&out, "%s\n", path.AsUTF8Unsafe().c_str());
StringAppendF(&out, " title: %s\n", entry.title().c_str());
StringAppendF(&out, " local_id: %s\n", entry.local_id().c_str());
StringAppendF(&out, " resource_id: %s\n", entry.resource_id().c_str());
StringAppendF(&out, " parent_local_id: %s\n",
entry.parent_local_id().c_str());
StringAppendF(&out, " shared: %s\n", entry.shared() ? "true" : "false");
StringAppendF(&out, " shared_with_me: %s\n",
entry.shared_with_me() ? "true" : "false");
StringAppendF(&out, " alternate_url: %s\n", entry.alternate_url().c_str());
const drive::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_modified_by_me =
base::Time::FromInternalValue(entry.last_modified_by_me());
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",
google_apis::util::FormatTimeAsString(last_modified).c_str());
StringAppendF(
&out, " last_modified_by_me: %s\n",
google_apis::util::FormatTimeAsString(last_modified_by_me).c_str());
StringAppendF(&out, " last_accessed: %s\n",
google_apis::util::FormatTimeAsString(last_accessed).c_str());
StringAppendF(&out, " creation_time: %s\n",
google_apis::util::FormatTimeAsString(creation_time).c_str());
if (entry.has_file_specific_info()) {
const drive::FileSpecificInfo& file_specific_info =
entry.file_specific_info();
StringAppendF(&out, " content_mime_type: %s\n",
file_specific_info.content_mime_type().c_str());
StringAppendF(&out, " file_md5: %s\n",
file_specific_info.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());
}
if (entry.has_directory_specific_info()) {
StringAppendF(&out, " directory_info\n");
const drive::DirectorySpecificInfo& directory_specific_info =
entry.directory_specific_info();
StringAppendF(&out, " changestamp: %" PRId64 "\n",
directory_specific_info.changestamp());
}
return out;
}
// Appends {'key': key, 'value': value, 'class': clazz} dictionary to the
// |list|.
void AppendKeyValue(base::ListValue* list,
......@@ -334,22 +261,10 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
"periodicUpdate",
base::BindRepeating(&DriveInternalsWebUIHandler::OnPeriodicUpdate,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"clearAccessToken",
base::BindRepeating(&DriveInternalsWebUIHandler::ClearAccessToken,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"clearRefreshToken",
base::BindRepeating(&DriveInternalsWebUIHandler::ClearRefreshToken,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"resetDriveFileSystem",
base::BindRepeating(&DriveInternalsWebUIHandler::ResetDriveFileSystem,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"listFileEntries",
base::BindRepeating(&DriveInternalsWebUIHandler::ListFileEntries,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"zipLogs",
base::BindRepeating(&DriveInternalsWebUIHandler::ZipDriveFsLogs,
......@@ -441,13 +356,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
drive_notification_manager
? drive_notification_manager->push_notification_enabled()
: false);
auto* drive_service = GetDriveService();
if (drive_service) {
connection_status.SetBoolean("has-refresh-token",
drive_service->HasRefreshToken());
connection_status.SetBoolean("has-access-token",
drive_service->HasAccessToken());
}
MaybeCallJavascript("updateConnectionStatus", std::move(connection_status));
}
......@@ -457,138 +365,16 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
SetSectionEnabled("account-information-section", false);
}
// Called when GetAboutResource() call to DriveService is complete.
void OnGetAboutResource(
google_apis::DriveApiErrorCode status,
std::unique_ptr<google_apis::AboutResource> about_resource) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (status != google_apis::HTTP_SUCCESS) {
LOG(ERROR) << "Failed to get about resource";
return;
}
DCHECK(about_resource);
base::DictionaryValue data;
data.SetDouble("account-quota-total", about_resource->quota_bytes_total());
data.SetDouble("account-quota-used",
about_resource->quota_bytes_used_aggregate());
data.SetDouble("account-largest-changestamp-remote",
about_resource->largest_change_id());
data.SetString("root-resource-id", about_resource->root_folder_id());
MaybeCallJavascript("updateAboutResource", std::move(data));
}
void UpdateDeltaUpdateStatusSection() {
// TODO(crbug.com/896123): Maybe worth implementing.
SetSectionEnabled("delta-update-status-section", false);
}
// Callback for DebugInfoCollector::GetMetadata for delta update.
void OnGetFilesystemMetadataForDeltaUpdate(
const drive::FileSystemMetadata& metadata,
const std::map<std::string, drive::FileSystemMetadata>&
team_drive_metadata) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto items = std::make_unique<base::ListValue>();
// Users default corpus first.
auto app_data = std::make_unique<base::DictionaryValue>();
app_data->SetString("id", "default corpus");
app_data->SetString("root_entry_path", metadata.path);
app_data->SetString("start_page_token", metadata.start_page_token);
app_data->SetString("last_check_time",
google_apis::util::FormatTimeAsStringLocaltime(
metadata.last_update_check_time));
app_data->SetString(
"last_check_result",
drive::FileErrorToString(metadata.last_update_check_error));
app_data->SetString("refreshing", metadata.refreshing ? "Yes" : "No");
items->Append(std::move(app_data));
for (const auto& team_drive : team_drive_metadata) {
app_data = std::make_unique<base::DictionaryValue>();
app_data->SetString("id", team_drive.first);
app_data->SetString("root_entry_path", team_drive.second.path);
app_data->SetString("start_page_token",
team_drive.second.start_page_token);
app_data->SetString("last_check_time",
google_apis::util::FormatTimeAsStringLocaltime(
team_drive.second.last_update_check_time));
app_data->SetString(
"last_check_result",
drive::FileErrorToString(team_drive.second.last_update_check_error));
app_data->SetString("refreshing",
team_drive.second.refreshing ? "Yes" : "No");
items->Append(std::move(app_data));
}
base::DictionaryValue delta_update_status;
delta_update_status.Set("items", std::move(items));
MaybeCallJavascript("updateDeltaUpdateStatus",
std::move(delta_update_status));
}
void UpdateInFlightOperationsSection() {
// TODO(crbug.com/896123): Maybe worth implementing.
SetSectionEnabled("in-flight-operations-section", false);
}
void UpdateFileSystemContentsSection() {
SetSectionEnabled("file-system-contents-section", false);
}
// Called when GetResourceEntryByPath() is complete.
void OnGetResourceEntryByPath(const base::FilePath& path,
drive::FileError error,
std::unique_ptr<drive::ResourceEntry> entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (error == drive::FILE_ERROR_OK) {
DCHECK(entry.get());
MaybeCallJavascript("updateFileSystemContents",
base::Value(FormatEntry(path, *entry) + "\n"));
}
}
// Called when ReadDirectoryByPath() is complete.
void OnReadDirectoryByPath(
const base::FilePath& parent_path,
drive::FileError error,
std::unique_ptr<drive::ResourceEntryVector> entries) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (error == drive::FILE_ERROR_OK) {
DCHECK(entries.get());
drive::DebugInfoCollector* debug_info_collector = GetDebugInfoCollector();
std::string file_system_as_text;
for (size_t i = 0; i < entries->size(); ++i) {
const drive::ResourceEntry& entry = (*entries)[i];
const base::FilePath current_path = parent_path.Append(
base::FilePath::FromUTF8Unsafe(entry.base_name()));
file_system_as_text.append(FormatEntry(current_path, entry) + "\n");
if (entry.file_info().is_directory()) {
debug_info_collector->ReadDirectory(
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.
MaybeCallJavascript("updateFileSystemContents",
base::Value(file_system_as_text));
}
}
void UpdatePathConfigurationsSection() {
SetSectionEnabled("path-configurations-section", true);
......@@ -744,22 +530,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
SetSectionEnabled("cache-contents-section", false);
}
// Called as the iterator for DebugInfoCollector::IterateFileCache().
void OnUpdateCacheEntry(const std::string& local_id,
const drive::FileCacheEntry& cache_entry) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Convert |cache_entry| into a dictionary.
base::DictionaryValue value;
value.SetString("local_id", local_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());
MaybeCallJavascript("updateCacheContents", std::move(value));
}
void UpdateGCacheContentsSection() {
SetSectionEnabled("gcache-contents-section", true);
......@@ -782,24 +552,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
std::move(response.second));
}
// Called when the corresponding button on the page is pressed.
void ClearAccessToken(const base::ListValue* args) {
AllowJavascript();
drive::DriveServiceInterface* drive_service = GetDriveService();
if (drive_service)
drive_service->ClearAccessToken();
}
// Called when the corresponding button on the page is pressed.
void ClearRefreshToken(const base::ListValue* args) {
AllowJavascript();
drive::DriveServiceInterface* drive_service = GetDriveService();
if (drive_service)
drive_service->ClearRefreshToken();
}
// Called when the corresponding button on the page is pressed.
void ResetDriveFileSystem(const base::ListValue* args) {
AllowJavascript();
......@@ -813,13 +565,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
}
}
// Called when the corresponding button on the page is pressed.
void ListFileEntries(const base::ListValue* args) {
AllowJavascript();
UpdateFileSystemContentsSection();
}
void ZipDriveFsLogs(const base::ListValue* args) {
AllowJavascript();
......@@ -851,19 +596,6 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
return service;
}
// Returns a DriveService instance.
drive::DriveServiceInterface* GetDriveService() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
return drive::util::GetDriveServiceByProfile(profile());
}
// Returns a DebugInfoCollector instance.
drive::DebugInfoCollector* GetDebugInfoCollector() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
drive::DriveIntegrationService* service = GetIntegrationService();
return service ? service->debug_info_collector() : NULL;
}
// The last event sent to the JavaScript side.
int last_sent_event_id_;
......
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