Commit e2bfbe7f authored by chili's avatar chili Committed by Commit bot
Browse files

[Offline Pages] Connect the offline page logs to the internals page.

BUG=609570
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2089423002
Cr-Commit-Position: refs/heads/master@{#402363}
parent 09435b7f
......@@ -20,5 +20,25 @@ th {
background-color: navy;
color: white;
font-weight: bold;
padding: 5px;
}
ul {
border: 1px solid;
list-style-type: none;
margin: 0;
max-height: 300px;
overflow: auto;
padding: 5px;
width: 100%;
}
ul li {
list-style-position: outside;
margin: 0 0 0 5px;
padding: 0;
}
li:nth-child(2n) {
background-color: lavender;
}
......@@ -22,6 +22,22 @@
<button id="download">Dump</button>
</div>
<h2>Event Logs</h2>
<div>
<button id="refresh-logs">Refresh Logs</button>
<div>
Page Model Log: <span id="model-status"></span>
<button id="log-model-on">Enable</button>
<button id="log-model-off">Disable</button>
</div>
<div>
Request Queue Log: <span id="request-status"></span>
<button id="log-request-on">Enable</button>
<button id="log-request-off">Disable</button>
</div>
<ul id="logs"></ul>
</div>
<h2>Stored Pages</h2>
<div>
<button id="clear-all">Clear all</button>
......
......@@ -81,12 +81,27 @@ cr.define('offlineInternals', function() {
savePageRequests = requests;
}
/**
* Fills the event logs section.
* @param {!Array<string>} logs A list of log strings.
*/
function fillEventLog(logs) {
var element = $('logs');
element.textContent = '';
for (let log of logs) {
var logItem = document.createElement('li');
logItem.textContent = log;
element.appendChild(logItem);
}
}
/**
* Refresh all displayed information.
*/
function refreshAll() {
browserProxy_.getStoredPages().then(fillStoredPages);
browserProxy_.getRequestQueue().then(fillRequestQueue);
refreshLog();
}
/**
......@@ -120,6 +135,15 @@ cr.define('offlineInternals', function() {
'dump.json');
}
/**
* Updates the status strings.
* @param {!IsLogging} logStatus Status of logging.
*/
function updateLogStatus(logStatus) {
$('model-status').textContent = logStatus.modelIsLogging ? 'On' : 'Off';
$('request-status').textContent = logStatus.queueIsLogging ? 'On' : 'Off';
}
/**
* Delete selected pages from the offline store.
*/
......@@ -135,11 +159,28 @@ cr.define('offlineInternals', function() {
browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted);
}
/**
* Refreshes the logs.
*/
function refreshLog() {
browserProxy_.getEventLogs().then(fillEventLog);
browserProxy_.getLoggingState().then(updateLogStatus);
}
function initialize() {
$('clear-all').onclick = deleteAllPages;
$('clear-selected').onclick = deleteSelectedPages;
$('refresh').onclick = refreshAll;
$('download').onclick = download;
$('log-model-on').onclick =
browserProxy_.setRecordPageModel.bind(browserProxy_, true);
$('log-model-off').onclick =
browserProxy_.setRecordPageModel.bind(browserProxy_, false);
$('log-request-on').onclick =
browserProxy_.setRecordRequestQueue.bind(browserProxy_, true);
$('log-request-off').onclick =
browserProxy_.setRecordRequestQueue.bind(browserProxy_, false);
$('refresh-logs').onclick = refreshLog;
browserProxy_ =
offlineInternals.OfflineInternalsBrowserProxyImpl.getInstance();
refreshAll();
......
......@@ -28,6 +28,14 @@ var OfflinePage;
*/
var SavePageRequest;
/**
* @typedef {{
* modelIsLogging: boolean,
* queueIsLogging: boolean
* }}
*/
var IsLogging;
cr.define('offlineInternals', function() {
/** @interface */
function OfflineInternalsBrowserProxy() {}
......@@ -60,6 +68,32 @@ cr.define('offlineInternals', function() {
* pages are deleted.
*/
deleteSelectedPages: function(ids) {},
/**
* Sets whether to record logs for stored pages.
* @param {boolean} shouldLog True if logging should be enabled.
*/
setRecordPageModel: function(shouldLog) {},
/**
* Sets whether to record logs for scheduled requests.
* @param {boolean} shouldLog True if logging should be enabled.
*/
setRecordRequestQueue: function(shouldLog) {},
/**
* Gets the currently recorded logs.
* @return {!Promise<!Array<string>>} A promise firing when the
* logs are retrieved.
*/
getEventLogs: function() {},
/**
* Gets the state of logging (on/off).
* @return {!Promise<!IsLogging>} A promise firing when the state
* is retrieved.
*/
getLoggingState: function() {},
};
/**
......@@ -88,6 +122,26 @@ cr.define('offlineInternals', function() {
/** @override */
deleteSelectedPages: function(ids) {
return cr.sendWithPromise('deleteSelectedPages', ids);
},
/** @override */
setRecordPageModel: function(shouldLog) {
chrome.send('setRecordPageModel');
},
/** @override */
setRecordRequestQueue: function(shouldLog) {
chrome.send('setRecordRequestQueue');
},
/** @override */
getEventLogs: function() {
return cr.sendWithPromise('getEventLogs');
},
/** @override */
getLoggingState: function() {
return cr.sendWithPromise('getLoggingState');
}
};
......
......@@ -50,6 +50,18 @@ class OfflineInternalsUIMessageHandler : public content::WebUIMessageHandler {
// Load Stored pages info.
void HandleGetStoredPages(const base::ListValue* args);
// Set whether to record offline page model events.
void HandleSetRecordPageModel(const base::ListValue* args);
// Set whether to record request queue events.
void HandleSetRecordRequestQueue(const base::ListValue* args);
// Load both Page Model and Request Queue event logs.
void HandleGetEventLogs(const base::ListValue* args);
// Load whether logs are being recorded.
void HandleGetLoggingState(const base::ListValue* args);
// Callback for async GetAllPages calls.
void HandleStoredPagesCallback(
std::string callback_id,
......@@ -250,6 +262,51 @@ void OfflineInternalsUIMessageHandler::HandleGetStoredPages(
}
}
void OfflineInternalsUIMessageHandler::HandleSetRecordPageModel(
const base::ListValue* args) {
bool should_record;
CHECK(args->GetBoolean(0, &should_record));
offline_page_model_->GetLogger()->SetIsLogging(should_record);
}
void OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue(
const base::ListValue* args) {
bool should_record;
CHECK(args->GetBoolean(0, &should_record));
request_coordinator_->GetLogger()->SetIsLogging(should_record);
}
void OfflineInternalsUIMessageHandler::HandleGetLoggingState(
const base::ListValue* args) {
AllowJavascript();
const base::Value* callback_id;
CHECK(args->Get(0, &callback_id));
base::DictionaryValue result;
result.SetBoolean("modelIsLogging",
offline_page_model_->GetLogger()->GetIsLogging());
result.SetBoolean("queueIsLogging",
request_coordinator_->GetLogger()->GetIsLogging());
ResolveJavascriptCallback(*callback_id, result);
}
void OfflineInternalsUIMessageHandler::HandleGetEventLogs(
const base::ListValue* args) {
AllowJavascript();
const base::Value* callback_id;
CHECK(args->Get(0, &callback_id));
std::vector<std::string> logs;
offline_page_model_->GetLogger()->GetLogs(&logs);
request_coordinator_->GetLogger()->GetLogs(&logs);
std::sort(logs.begin(), logs.end());
base::ListValue result;
result.AppendStrings(logs);
ResolveJavascriptCallback(*callback_id, result);
}
void OfflineInternalsUIMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"deleteAllPages",
......@@ -267,6 +324,22 @@ void OfflineInternalsUIMessageHandler::RegisterMessages() {
"getStoredPages",
base::Bind(&OfflineInternalsUIMessageHandler::HandleGetStoredPages,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"getEventLogs",
base::Bind(&OfflineInternalsUIMessageHandler::HandleGetEventLogs,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"setRecordRequestQueue",
base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordRequestQueue,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"setRecordPageModel",
base::Bind(&OfflineInternalsUIMessageHandler::HandleSetRecordPageModel,
weak_ptr_factory_.GetWeakPtr()));
web_ui()->RegisterMessageCallback(
"getLoggingState",
base::Bind(&OfflineInternalsUIMessageHandler::HandleGetLoggingState,
weak_ptr_factory_.GetWeakPtr()));
// Get the offline page model associated with this web ui.
Profile* profile = Profile::FromWebUI(web_ui());
......
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