Commit 5cc49ab3 authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

[fsp] Introduce chrome://fsp-internals for logging and debugging.

Similarly to chrome://drive-internals, this patch introduce a webui page
showing what's going on in the system.

Currently, only mounted file systems, and number of active requests are shown,
however more is coming soon.

TEST=Tested manually by invoking chrome://fsp-internals with a running
     providing extension.
BUG=376095

Review URL: https://codereview.chromium.org/296003012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272886 0039d316-1c4b-4281-b951-d872f2087c98
parent f9f5c936
......@@ -304,7 +304,10 @@
<include name="IDR_DRIVE_INTERNALS_CSS" file="resources\chromeos\drive_internals.css" type="BINDATA" />
<include name="IDR_DRIVE_INTERNALS_HTML" file="resources\chromeos\drive_internals.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_DRIVE_INTERNALS_JS" file="resources\chromeos\drive_internals.js" type="BINDATA" />
<include name="IDR_GUEST_SESSION_TAB_HTML" file="resources\chromeos\guest_session_tab.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_FSP_INTERNALS_CSS" file="resources\chromeos\fsp_internals.css" type="BINDATA" />
<include name="IDR_FSP_INTERNALS_HTML" file="resources\chromeos\fsp_internals.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_FSP_INTERNALS_JS" file="resources\chromeos\fsp_internals.js" flattenhtml="true" type="BINDATA" />
<include name="IDR_GUEST_SESSION_TAB_HTML" file="resources\chromeos\guest_session_tab.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_IMAGEBURNER_HTML" file="resources\chromeos\image_burner.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" />
<include name="IDR_IMAGEBURNER_JS" file="resources\chromeos\image_burner.js" type="BINDATA" />
<include name="IDR_KEYBOARD_OVERLAY_CSS" file="resources\chromeos\keyboard_overlay.css" flattenhtml="true" type="BINDATA" />
......
......@@ -107,6 +107,10 @@ void RequestManager::OnRequestTimeout(int request_id) {
RejectRequest(request_id, base::File::FILE_ERROR_ABORT);
}
size_t RequestManager::GetActiveRequestsForLogging() const {
return requests_.size();
}
RequestManager::Request::Request() {}
RequestManager::Request::~Request() {}
......
......@@ -67,6 +67,10 @@ class RequestManager {
// new requests
void SetTimeoutForTests(const base::TimeDelta& timeout);
// Gets number of active requests for logging purposes.
// TODO(mtomasz): Introduce a logger class to gather more information
size_t GetActiveRequestsForLogging() const;
private:
struct Request {
Request();
......
......@@ -18,6 +18,12 @@ Service* ServiceFactory::Get(content::BrowserContext* context) {
GetInstance()->GetServiceForBrowserContext(context, true));
}
// static
Service* ServiceFactory::FindExisting(content::BrowserContext* context) {
return static_cast<Service*>(
GetInstance()->GetServiceForBrowserContext(context, false));
}
ServiceFactory* ServiceFactory::GetInstance() {
return Singleton<ServiceFactory>::get();
}
......
......@@ -21,7 +21,14 @@ class Service;
// Creates services per profile.
class ServiceFactory : public BrowserContextKeyedServiceFactory {
public:
// Returns a service instance singleton, after creating it (if necessary).
static Service* Get(content::BrowserContext* context);
// Returns a service instance for the context if exists. Otherwise, returns
// NULL.
static Service* FindExisting(content::BrowserContext* context);
// Gets a singleton instance of the factory.
static ServiceFactory* GetInstance();
private:
......
/* Copyright 2014 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
body {
font-family: 'Verdana', 'Arial';
font-size: 14px;
margin: 20px;
}
h1 {
font-size: 20px;
font-weight: normal;
}
table {
border-collapse: collapse;
width: 100%;
}
table th {
background-color: rgb(92, 107, 192);
color: white;
font-weight: normal;
height: 50px;
}
table td {
border-bottom: 1px solid #eee;
height: 40px;
line-height: 24px;
text-align: center;
}
table td .icon {
display: inline-block;
height: 24px;
vertical-align: middle;
width: 24px;
}
<!doctype html>
<html>
<head>
<title>File System Provider API - internals</title>
<meta charset="utf-8">
<link rel="stylesheet" href="fsp_internals.css">
<script src="chrome://fsp-internals/fsp_internals.js"></script>
</head>
<body>
<polymer-element name="file-systems">
<template>
<link rel="stylesheet"
href="chrome://fsp-internals/fsp_internals.css"></link>
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Extension ID</th>
<th>Active Requests</th>
</tr>
</thead>
<tbody>
<template id="file-system" repeat="{{item in model}}">
<tr>
<td>{{item.id}}</td>
<td>{{item.name}}</td>
<td>
<div class="icon" style="background-image: -webkit-image-set(
url(chrome://extension-icon/{{item.extensionId}}/24/1) 1x,
url(chrome://extension-icon/{{item.extensionId}}/48/1)
2x)"></div>
{{item.extensionId}}
</td>
<td>{{item.activeRequests}}</td>
</tr>
</template>
</tbody>
</table>
</template>
</polymer-element>
<h1>Mounted provided file systems</h1>
<file-systems id="mounted-file-systems">
</file-systems>
</body>
</html>
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
<include src="../../../../third_party/polymer/platform/platform.js">
<include src="../../../../third_party/polymer/polymer/polymer.js">
// Define the file-systems element.
Polymer('file-systems', {
ready: function() {
},
/**
* List of provided file system information maps.
* @type {Array.<Object>}
*/
model: []
});
/*
* Updates the mounted file system list.
* @param {Object} fileSystems Dictionary containing provided file system
* information.
*
*/
function updateFileSystems(fileSystems) {
var mountedFileSystems = document.querySelector('#mounted-file-systems');
mountedFileSystems.model = fileSystems;
Platform.performMicrotaskCheckpoint();
}
document.addEventListener('DOMContentLoaded', function() {
chrome.send('updateFileSystems');
// Refresh periodically.
setInterval(function() {
chrome.send('updateFileSystems');
}, 1000);
});
......@@ -115,6 +115,7 @@
#include "chrome/browser/ui/webui/chromeos/cryptohome_ui.h"
#include "chrome/browser/ui/webui/chromeos/drive_internals_ui.h"
#include "chrome/browser/ui/webui/chromeos/first_run/first_run_ui.h"
#include "chrome/browser/ui/webui/chromeos/fsp_internals_ui.h"
#include "chrome/browser/ui/webui/chromeos/imageburner/imageburner_ui.h"
#include "chrome/browser/ui/webui/chromeos/keyboard_overlay_ui.h"
#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
......@@ -413,6 +414,8 @@ WebUIFactoryFunction GetWebUIFactoryFunction(WebUI* web_ui,
return &NewWebUI<chromeos::CryptohomeUI>;
if (url.host() == chrome::kChromeUIDriveInternalsHost)
return &NewWebUI<chromeos::DriveInternalsUI>;
if (url.host() == chrome::kChromeUIFSPInternalsHost)
return &NewWebUI<chromeos::FSPInternalsUI>;
if (url.host() == chrome::kChromeUIFirstRunHost)
return &NewWebUI<chromeos::FirstRunUI>;
if (url.host() == chrome::kChromeUIImageBurnerHost)
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/chromeos/fsp_internals_ui.h"
#include "base/bind.h"
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
#include "chrome/browser/chromeos/file_system_provider/request_manager.h"
#include "chrome/browser/chromeos/file_system_provider/service.h"
#include "chrome/browser/chromeos/file_system_provider/service_factory.h"
#include "chrome/browser/profiles/profile.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_data_source.h"
#include "content/public/browser/web_ui_message_handler.h"
#include "grit/browser_resources.h"
using content::BrowserThread;
namespace chromeos {
namespace {
// Class to handle messages from chrome://fsp-internals.
class FSPInternalsWebUIHandler : public content::WebUIMessageHandler {
public:
FSPInternalsWebUIHandler() : weak_ptr_factory_(this) {}
virtual ~FSPInternalsWebUIHandler() {}
private:
// content::WebUIMessageHandler overrides.
virtual void RegisterMessages() OVERRIDE;
// Gets a file system provider service for the current profile. If not found,
// then NULL.
file_system_provider::Service* GetService();
// Invoked when updating file system list is requested.
void OnUpdateFileSystems(const base::ListValue* args);
base::WeakPtrFactory<FSPInternalsWebUIHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(FSPInternalsWebUIHandler);
};
void FSPInternalsWebUIHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"updateFileSystems",
base::Bind(&FSPInternalsWebUIHandler::OnUpdateFileSystems,
weak_ptr_factory_.GetWeakPtr()));
}
file_system_provider::Service* FSPInternalsWebUIHandler::GetService() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
Profile* const profile = Profile::FromWebUI(web_ui());
return file_system_provider::ServiceFactory::FindExisting(profile);
}
void FSPInternalsWebUIHandler::OnUpdateFileSystems(
const base::ListValue* args) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
file_system_provider::Service* const service = GetService();
if (!service)
return;
base::ListValue items;
const std::vector<file_system_provider::ProvidedFileSystemInfo>
file_system_info_list = service->GetProvidedFileSystemInfoList();
for (size_t i = 0; i < file_system_info_list.size(); ++i) {
const file_system_provider::ProvidedFileSystemInfo file_system_info =
file_system_info_list[i];
file_system_provider::ProvidedFileSystemInterface* const file_system =
service->GetProvidedFileSystem(file_system_info.extension_id(),
file_system_info.file_system_id());
DCHECK(file_system);
file_system_provider::RequestManager* const request_manager =
file_system->GetRequestManager();
DCHECK(request_manager);
base::DictionaryValue* item_value = new base::DictionaryValue();
item_value->SetString("id", file_system_info.file_system_id());
item_value->SetString("name", file_system_info.file_system_name());
item_value->SetString("extensionId", file_system_info.extension_id());
item_value->SetString("mountPath",
file_system_info.mount_path().AsUTF8Unsafe());
item_value->SetInteger("activeRequests",
request_manager->GetActiveRequestsForLogging());
items.Append(item_value);
}
web_ui()->CallJavascriptFunction("updateFileSystems", items);
}
} // namespace
FSPInternalsUI::FSPInternalsUI(content::WebUI* web_ui)
: WebUIController(web_ui) {
web_ui->AddMessageHandler(new FSPInternalsWebUIHandler());
content::WebUIDataSource* source =
content::WebUIDataSource::Create(chrome::kChromeUIFSPInternalsHost);
source->AddResourcePath("fsp_internals.css", IDR_FSP_INTERNALS_CSS);
source->AddResourcePath("fsp_internals.js", IDR_FSP_INTERNALS_JS);
source->SetDefaultResource(IDR_FSP_INTERNALS_HTML);
Profile* profile = Profile::FromWebUI(web_ui);
content::WebUIDataSource::Add(profile, source);
}
} // namespace chromeos
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_FSP_INTERNALS_UI_H_
#define CHROME_BROWSER_UI_WEBUI_CHROMEOS_FSP_INTERNALS_UI_H_
#include "content/public/browser/web_ui_controller.h"
namespace chromeos {
// The WebUI controller for chrome:://fsp-internals, that is used for diagnosing
// issues of file systems provided via chrome.fileSystemProvider API.
class FSPInternalsUI : public content::WebUIController {
public:
explicit FSPInternalsUI(content::WebUI* web_ui);
private:
DISALLOW_COPY_AND_ASSIGN(FSPInternalsUI);
};
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_FSP_INTERNALS_UI_H_
......@@ -2022,6 +2022,8 @@
'browser/ui/webui/chromeos/first_run/first_run_handler.h',
'browser/ui/webui/chromeos/first_run/first_run_ui.cc',
'browser/ui/webui/chromeos/first_run/first_run_ui.h',
'browser/ui/webui/chromeos/fsp_internals_ui.cc',
'browser/ui/webui/chromeos/fsp_internals_ui.h',
'browser/ui/webui/chromeos/imageburner/imageburner_ui.cc',
'browser/ui/webui/chromeos/imageburner/imageburner_ui.h',
'browser/ui/webui/chromeos/keyboard_overlay_ui.cc',
......
......@@ -177,6 +177,7 @@ const char kChromeUIExtensionIconHost[] = "extension-icon";
const char kChromeUIExtensionInfoHost[] = "extension-info";
const char kChromeUIExtensionsFrameHost[] = "extensions-frame";
const char kChromeUIExtensionsHost[] = "extensions";
const char kChromeUIFSPInternalsHost[] = "fsp-internals";
const char kChromeUIFaviconHost[] = "favicon";
const char kChromeUIFeedbackHost[] = "feedback";
const char kChromeUIFlagsHost[] = "flags";
......
......@@ -169,6 +169,7 @@ extern const char kChromeUIExtensionIconHost[];
extern const char kChromeUIExtensionInfoHost[];
extern const char kChromeUIExtensionsFrameHost[];
extern const char kChromeUIExtensionsHost[];
extern const char kChromeUIFSPInternalsHost[];
extern const char kChromeUIFaviconHost[];
extern const char kChromeUIFeedbackHost[];
extern const char kChromeUIFlagsHost[];
......
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