Commit 91c7ea23 authored by Austin Tankiang's avatar Austin Tankiang Committed by Commit Bot

Add startup-arguments field to chrome://drive-internals

These fields will only be enabled when in developer mode.

Bug: 1049071
Change-Id: If592cce7569569a37016f7b92eae0f596beefa9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2178484
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775009}
parent c9358fbf
......@@ -1058,6 +1058,25 @@ void DriveIntegrationService::RestartDrive() {
MaybeRemountFileSystem(base::TimeDelta(), false);
}
void DriveIntegrationService::SetStartupArguments(
std::string arguments,
base::OnceCallback<void(bool)> callback) {
if (!GetDriveFsInterface()) {
std::move(callback).Run(false);
return;
}
GetDriveFsInterface()->SetStartupArguments(arguments, std::move(callback));
}
void DriveIntegrationService::GetStartupArguments(
base::OnceCallback<void(const std::string&)> callback) {
if (!GetDriveFsInterface()) {
std::move(callback).Run("");
return;
}
GetDriveFsInterface()->GetStartupArguments(std::move(callback));
}
//===================== DriveIntegrationServiceFactory =======================
DriveIntegrationServiceFactory::FactoryCallback*
......
......@@ -167,6 +167,16 @@ class DriveIntegrationService : public KeyedService,
void RestartDrive();
// Sets the arguments to be parsed by DriveFS on startup. Should only be
// called in developer mode.
void SetStartupArguments(std::string arguments,
base::OnceCallback<void(bool)> callback);
// Gets the currently set arguments parsed by DriveFS on startup. Should only
// be called in developer mode.
void GetStartupArguments(
base::OnceCallback<void(const std::string&)> callback);
private:
enum State {
NOT_INITIALIZED,
......
......@@ -2,6 +2,10 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file. */
#drive-debug > form {
margin-bottom: 4px;
}
#gcache-contents {
font-size: small;
}
......
......@@ -26,6 +26,12 @@
<section id="drive-debug" hidden>
<h2>Drive Debug</h2>
<form id="startup-arguments-form" hidden>
Startup Arguments
<input id="startup-arguments-input">
<button type="submit">Apply</button>
<span id="arguments-status-text"></span>
</form>
<div>
<button id="button-restart-drive">Restart Drive</button>
<button id="button-reset-drive-filesystem">
......
......@@ -91,6 +91,10 @@ function updateCacheContents(cacheEntry) {
$('cache-contents').appendChild(tr);
}
function updateStartupArguments(args) {
$('startup-arguments-input').value = args;
}
/**
* Updates the Local Storage summary.
* @param {Object} localStorageSummary Dictionary describing the status of local
......@@ -237,6 +241,10 @@ function updateKeyValueList(ul, list) {
}
}
function updateStartupArgumentsStatus(success) {
$('arguments-status-text').textContent = (success ? 'success' : 'failed');
}
/**
* Updates the text next to the 'reset' button to update the status.
* @param {boolean} success whether or not resetting has succeeded.
......@@ -289,6 +297,12 @@ document.addEventListener('DOMContentLoaded', function() {
updateToc();
$('startup-arguments-form').addEventListener('submit', function(e) {
e.preventDefault();
$('arguments-status-text').textContent = 'applying...';
chrome.send('setStartupArguments', [$('startup-arguments-input').value]);
});
$('button-restart-drive').addEventListener('click', function() {
chrome.send('restartDrive');
});
......
......@@ -22,6 +22,7 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/strings/pattern.h"
#include "base/strings/strcat.h"
#include "base/strings/stringprintf.h"
......@@ -217,6 +218,14 @@ std::pair<ino_t, base::ListValue> GetServiceLogContents(
return {inode, std::move(result)};
}
bool GetDeveloperMode() {
std::string output;
if (!base::GetAppOutput({"/usr/bin/crossystem", "cros_debug"}, &output)) {
return false;
}
return output == "1";
}
class DriveInternalsWebUIHandler;
void ZipLogs(Profile* profile,
......@@ -262,6 +271,10 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
"periodicUpdate",
base::BindRepeating(&DriveInternalsWebUIHandler::OnPeriodicUpdate,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"setStartupArguments",
base::BindRepeating(&DriveInternalsWebUIHandler::SetStartupArguments,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"restartDrive",
base::BindRepeating(&DriveInternalsWebUIHandler::RestartDrive,
......@@ -410,6 +423,12 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
void UpdateDriveDebugSection() {
SetSectionEnabled("drive-debug", true);
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(GetDeveloperMode),
base::BindOnce(&DriveInternalsWebUIHandler::OnGetDeveloperMode,
weak_ptr_factory_.GetWeakPtr()));
// Propagate the amount of local free space in bytes.
base::FilePath home_path;
if (base::PathService::Get(base::DIR_HOME, &home_path)) {
......@@ -423,6 +442,31 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
}
}
// Called when GetDeveloperMode() is complete.
void OnGetDeveloperMode(bool enabled) {
developer_mode_ = enabled;
if (!enabled) {
return;
}
// Get the startup arguments.
drive::DriveIntegrationService* integration_service =
GetIntegrationService();
if (integration_service) {
integration_service->GetStartupArguments(
base::BindOnce(&DriveInternalsWebUIHandler::OnGetStartupArguments,
weak_ptr_factory_.GetWeakPtr()));
}
}
// Called when GetStartupArguments() is complete.
void OnGetStartupArguments(const std::string& arguments) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(developer_mode_);
MaybeCallJavascript("updateStartupArguments", base::Value(arguments));
SetSectionEnabled("startup-arguments-form", true);
}
// Called when AmountOfFreeDiskSpace() is complete.
void OnGetFreeDiskSpace(int64_t free_space) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -552,6 +596,41 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
std::move(response.second));
}
// Called when the "Startup Arguments" field on the page is submitted.
void SetStartupArguments(const base::ListValue* args) {
AllowJavascript();
if (!developer_mode_) {
return;
}
if (args->GetList().size() < 1 || !args->GetList()[0].is_string()) {
OnSetStartupArguments(false);
return;
}
drive::DriveIntegrationService* integration_service =
GetIntegrationService();
if (!integration_service) {
OnSetStartupArguments(false);
return;
}
integration_service->SetStartupArguments(
args->GetList()[0].GetString(),
base::BindOnce(&DriveInternalsWebUIHandler::OnSetStartupArguments,
weak_ptr_factory_.GetWeakPtr()));
}
void OnSetStartupArguments(bool success) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(developer_mode_);
if (success) {
RestartDrive(nullptr);
}
MaybeCallJavascript("updateStartupArgumentsStatus", base::Value(success));
}
// Called when the "Restart Drive" button on the page is pressed.
void RestartDrive(const base::ListValue* args) {
AllowJavascript();
......@@ -619,6 +698,9 @@ class DriveInternalsWebUIHandler : public content::WebUIMessageHandler {
// Service log file is being parsed.
bool service_log_file_is_processing_ = false;
// Whether developer mode is enabled for debug commands.
bool developer_mode_ = false;
base::WeakPtrFactory<DriveInternalsWebUIHandler> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(DriveInternalsWebUIHandler);
};
......
......@@ -427,4 +427,13 @@ void FakeDriveFs::SendNativeMessageRequest(
std::move(callback).Run(drive::FILE_ERROR_SERVICE_UNAVAILABLE, "");
}
void FakeDriveFs::SetStartupArguments(const std::string& arguments,
SetStartupArgumentsCallback callback) {
std::move(callback).Run(false);
}
void FakeDriveFs::GetStartupArguments(GetStartupArgumentsCallback callback) {
std::move(callback).Run("");
}
} // namespace drivefs
......@@ -102,6 +102,11 @@ class FakeDriveFs : public drivefs::mojom::DriveFs,
const std::string& request,
SendNativeMessageRequestCallback callback) override;
void SetStartupArguments(const std::string& arguments,
SetStartupArgumentsCallback callback) override;
void GetStartupArguments(GetStartupArgumentsCallback callback) override;
const base::FilePath mount_path_;
std::map<base::FilePath, FileMetadata> metadata_;
......
......@@ -67,6 +67,14 @@ interface DriveFs {
// encoded proto message.
SendNativeMessageRequest(string request) => (
FileError error, string response);
// Sets the arguments to be parsed by DriveFS on startup. Should only be
// called in developer mode.
SetStartupArguments(string arguments) => (bool success);
// Gets the currently set arguments parsed by DriveFS on startup. Should only
// be called in developer mode.
GetStartupArguments() => (string arguments);
};
// Implemented by Chrome, used from DriveFS.
......
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