Commit 1927f284 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

RC: Move mojo dependencies to mojo_api.html.

Also move one of the functions from discards.js into discards_tab.js
as that's the only user.

Bug: 891310
Change-Id: I434dc950029fb5e526a42dbed999a7dddc4ff6b1
Reviewed-on: https://chromium-review.googlesource.com/c/1324101Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606558}
parent 93cddd08
...@@ -71,20 +71,21 @@ ...@@ -71,20 +71,21 @@
</structures> </structures>
<includes> <includes>
<if expr="is_win or is_macosx or desktop_linux or chromeos"> <if expr="is_win or is_macosx or desktop_linux or chromeos">
<include name="IDR_DISCARDS_DATABASE_TAB_HTML" file="resources\discards\database_tab.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_MOJO_API_HTML" file="resources\discards\mojo_api.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_DATABASE_TAB_HTML" file="resources\discards\database_tab.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_DATABASE_TAB_JS" file="resources\discards\database_tab.js" type="BINDATA" /> <include name="IDR_DISCARDS_DATABASE_TAB_JS" file="resources\discards\database_tab.js" type="BINDATA" />
<include name="IDR_DISCARDS_DISCARDS_MAIN_HTML" file="resources\discards\discards_main.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_DISCARDS_MAIN_HTML" file="resources\discards\discards_main.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_DISCARDS_MAIN_JS" file="resources\discards\discards_main.js" type="BINDATA" /> <include name="IDR_DISCARDS_DISCARDS_MAIN_JS" file="resources\discards\discards_main.js" type="BINDATA" />
<include name="IDR_DISCARDS_DISCARDS_TAB_HTML" file="resources\discards\discards_tab.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_DISCARDS_TAB_HTML" file="resources\discards\discards_tab.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_DISCARDS_TAB_JS" file="resources\discards\discards_tab.js" type="BINDATA" /> <include name="IDR_DISCARDS_DISCARDS_TAB_JS" file="resources\discards\discards_tab.js" type="BINDATA" />
<include name="IDR_DISCARDS_GRAPH_TAB_HTML" file="${root_gen_dir}\chrome\browser\resources\discards\graph_tab.html" use_base_dir="false" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_GRAPH_TAB_HTML" file="${root_gen_dir}\chrome\browser\resources\discards\graph_tab.html" use_base_dir="false" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_GRAPH_TAB_JS" file="resources\discards\graph_tab.js" type="BINDATA" /> <include name="IDR_DISCARDS_GRAPH_TAB_JS" file="resources\discards\graph_tab.js" type="BINDATA" />
<include name="IDR_DISCARDS_HTML" file="resources\discards\discards.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_HTML" file="resources\discards\discards.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_JS" file="resources\discards\discards.js" type="BINDATA" /> <include name="IDR_DISCARDS_JS" file="resources\discards\discards.js" type="BINDATA" />
<include name="IDR_DISCARDS_LIFECYCLE_UNIT_STATE_MOJO_JS" file="${root_gen_dir}\chrome\browser\resource_coordinator\lifecycle_unit_state.mojom.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_DISCARDS_LIFECYCLE_UNIT_STATE_MOJO_JS" file="${root_gen_dir}\chrome\browser\resource_coordinator\lifecycle_unit_state.mojom.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_DISCARDS_MOJO_JS" file="${root_gen_dir}\chrome\browser\ui\webui\discards\discards.mojom.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_DISCARDS_MOJO_JS" file="${root_gen_dir}\chrome\browser\ui\webui\discards\discards.mojom.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_DISCARDS_MOJO_PUBLIC_BASE_PROCESS_ID_MOJOM_JS" file="${root_gen_dir}\mojo\public\mojom\base\process_id.mojom.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_DISCARDS_MOJO_PUBLIC_BASE_PROCESS_ID_MOJOM_JS" file="${root_gen_dir}\mojo\public\mojom\base\process_id.mojom.js" use_base_dir="false" type="BINDATA" />
<include name="IDR_DISCARDS_SORTED_TABLE_BEHAVIOR_HTML" file="resources\discards\sorted_table_behavior.html" flattenhtml="true" allowexternalscript="true" type="BINDATA" /> <include name="IDR_DISCARDS_SORTED_TABLE_BEHAVIOR_HTML" file="resources\discards\sorted_table_behavior.html" allowexternalscript="true" type="BINDATA" />
<include name="IDR_DISCARDS_SORTED_TABLE_BEHAVIOR_JS" file="resources\discards\sorted_table_behavior.js" type="BINDATA" /> <include name="IDR_DISCARDS_SORTED_TABLE_BEHAVIOR_JS" file="resources\discards\sorted_table_behavior.js" type="BINDATA" />
<include name="IDR_DISCARDS_WEBUI_GRAPH_DUMP_MOJO_JS" file="${root_gen_dir}\services\resource_coordinator\public\mojom\webui_graph_dump.mojom.js" use_base_dir="false" type="BINDATA" /> <include name="IDR_DISCARDS_WEBUI_GRAPH_DUMP_MOJO_JS" file="${root_gen_dir}\services\resource_coordinator\public\mojom\webui_graph_dump.mojom.js" use_base_dir="false" type="BINDATA" />
</if> </if>
......
...@@ -13,6 +13,7 @@ general use and is not localized. ...@@ -13,6 +13,7 @@ general use and is not localized.
<link rel="import" href="chrome://resources/html/assert.html"> <link rel="import" href="chrome://resources/html/assert.html">
<link rel="import" href="chrome://resources/html/cr.html"> <link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="mojo_api.html">
<link rel="import" href="sorted_table_behavior.html"> <link rel="import" href="sorted_table_behavior.html">
<dom-module id="database-tab"> <dom-module id="database-tab">
......
...@@ -12,11 +12,6 @@ general use and is not localized.--> ...@@ -12,11 +12,6 @@ general use and is not localized.-->
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="import" href="discards_main.html"> <link rel="import" href="discards_main.html">
<link rel="import" href="chrome://resources/html/cr.html"> <link rel="import" href="chrome://resources/html/cr.html">
<script src="chrome://resources/js/mojo_bindings.js"></script>
<script src="chrome://resources/js/time.mojom.js"></script>
<script src="mojo/public/mojom/base/process_id.mojom.js"></script>
<script src="chrome/browser/ui/webui/discards/discards.mojom.js"></script>
<script src="mojom/webui_graph_dump.mojom.js"></script>
<script src="discards.js"></script> <script src="discards.js"></script>
<link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css"> <link rel="stylesheet" href="chrome://resources/css/text_defaults_md.css">
<style> <style>
......
...@@ -22,74 +22,6 @@ cr.define('discards', function() { ...@@ -22,74 +22,6 @@ cr.define('discards', function() {
return uiHandler; return uiHandler;
} }
/**
* @param {mojom.LifecycleUnitState} state The discard state.
* @return {boolean} Whether the state is related to discarding.
*/
function isDiscardRelatedState(state) {
return state == mojom.LifecycleUnitState.PENDING_DISCARD ||
state == mojom.LifecycleUnitState.DISCARDED;
}
/**
* Compares two TabDiscardsInfos based on the data in the provided sort-key.
* @param {string} sortKey The key of the sort. See the "data-sort-key"
* attribute of the table headers for valid sort-keys.
* @param {boolean|number|string} a The first value being compared.
* @param {boolean|number|string} b The second value being compared.
* @return {number} A negative number if a < b, 0 if a == b, and a positive
* number if a > b.
*/
function compareTabDiscardsInfos(sortKey, a, b) {
let val1 = a[sortKey];
let val2 = b[sortKey];
// Compares strings.
if (sortKey == 'title' || sortKey == 'tabUrl') {
val1 = val1.toLowerCase();
val2 = val2.toLowerCase();
if (val1 == val2)
return 0;
return val1 > val2 ? 1 : -1;
}
// Compares boolean fields.
if (['canFreeze', 'canDiscard', 'isAutoDiscardable'].includes(sortKey)) {
if (val1 == val2)
return 0;
return val1 ? 1 : -1;
}
// Compare lifecycle state. This is actually a compound key.
if (sortKey == 'state') {
// If the keys are discarding state, then break ties using the discard
// reason.
if (val1 == val2 && isDiscardRelatedState(val1)) {
val1 = a['discardReason'];
val2 = b['discardReason'];
}
return val1 - val2;
}
// Compares numeric fields.
// NOTE: visibility, loadingState and state are represented as a numeric
// value.
if ([
'visibility',
'loadingState',
'discardCount',
'utilityRank',
'reactivationScore',
'lastActiveSeconds',
'siteEngagementScore',
].includes(sortKey)) {
return val1 - val2;
}
assertNotReached('Unsupported sort key: ' + sortKey);
return 0;
}
/** /**
* Pluralizes a string according to the given count. Assumes that appending an * Pluralizes a string according to the given count. Assumes that appending an
* 's' is sufficient to make a string plural. * 's' is sufficient to make a string plural.
...@@ -190,7 +122,6 @@ cr.define('discards', function() { ...@@ -190,7 +122,6 @@ cr.define('discards', function() {
// cr.define. This allows unittesting of these functions. // cr.define. This allows unittesting of these functions.
return { return {
boolToString: boolToString, boolToString: boolToString,
compareTabDiscardsInfos: compareTabDiscardsInfos,
durationToString: durationToString, durationToString: durationToString,
getOrCreateUiHandler: getOrCreateUiHandler, getOrCreateUiHandler: getOrCreateUiHandler,
maybeMakePlural: maybeMakePlural, maybeMakePlural: maybeMakePlural,
......
...@@ -13,6 +13,7 @@ general use and is not localized. ...@@ -13,6 +13,7 @@ general use and is not localized.
<link rel="import" href="chrome://resources/html/assert.html"> <link rel="import" href="chrome://resources/html/assert.html">
<link rel="import" href="chrome://resources/html/cr.html"> <link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/icon.html"> <link rel="import" href="chrome://resources/html/icon.html">
<link rel="import" href="mojo_api.html">
<link rel="import" href="sorted_table_behavior.html"> <link rel="import" href="sorted_table_behavior.html">
<dom-module id="discards-tab"> <dom-module id="discards-tab">
......
...@@ -2,6 +2,83 @@ ...@@ -2,6 +2,83 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
cr.define('discards_tab', function() {
'use strict';
/**
* @param {mojom.LifecycleUnitState} state The discard state.
* @return {boolean} Whether the state is related to discarding.
*/
function isDiscardRelatedState(state) {
return state == mojom.LifecycleUnitState.PENDING_DISCARD ||
state == mojom.LifecycleUnitState.DISCARDED;
}
/**
* Compares two TabDiscardsInfos based on the data in the provided sort-key.
* @param {string} sortKey The key of the sort. See the "data-sort-key"
* attribute of the table headers for valid sort-keys.
* @param {boolean|number|string} a The first value being compared.
* @param {boolean|number|string} b The second value being compared.
* @return {number} A negative number if a < b, 0 if a == b, and a positive
* number if a > b.
*/
function compareTabDiscardsInfos(sortKey, a, b) {
let val1 = a[sortKey];
let val2 = b[sortKey];
// Compares strings.
if (sortKey == 'title' || sortKey == 'tabUrl') {
val1 = val1.toLowerCase();
val2 = val2.toLowerCase();
if (val1 == val2)
return 0;
return val1 > val2 ? 1 : -1;
}
// Compares boolean fields.
if (['canFreeze', 'canDiscard', 'isAutoDiscardable'].includes(sortKey)) {
if (val1 == val2)
return 0;
return val1 ? 1 : -1;
}
// Compare lifecycle state. This is actually a compound key.
if (sortKey == 'state') {
// If the keys are discarding state, then break ties using the discard
// reason.
if (val1 == val2 && isDiscardRelatedState(val1)) {
val1 = a['discardReason'];
val2 = b['discardReason'];
}
return val1 - val2;
}
// Compares numeric fields.
// NOTE: visibility, loadingState and state are represented as a numeric
// value.
if ([
'visibility',
'loadingState',
'discardCount',
'utilityRank',
'reactivationScore',
'lastActiveSeconds',
'siteEngagementScore',
].includes(sortKey)) {
return val1 - val2;
}
assertNotReached('Unsupported sort key: ' + sortKey);
return 0;
}
return {
compareTabDiscardsInfos: compareTabDiscardsInfos,
};
});
Polymer({ Polymer({
is: 'discards-tab', is: 'discards-tab',
...@@ -49,7 +126,7 @@ Polymer({ ...@@ -49,7 +126,7 @@ Polymer({
return (a, b) => 0; return (a, b) => 0;
return function(a, b) { return function(a, b) {
const comp = discards.compareTabDiscardsInfos(sortKey, a, b); const comp = discards_tab.compareTabDiscardsInfos(sortKey, a, b);
return sortReverse ? -comp : comp; return sortReverse ? -comp : comp;
}; };
}, },
......
...@@ -8,6 +8,8 @@ general use and is not localized. ...@@ -8,6 +8,8 @@ general use and is not localized.
--> -->
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="mojo_api.html">
<dom-module id="graph-tab"> <dom-module id="graph-tab">
<template> <template>
<webview id="webView" src="${data_url}" on-contentload="onWebViewReady_" <webview id="webView" src="${data_url}" on-contentload="onWebViewReady_"
......
<!--
Copyright 2018 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.
-->
<script src="chrome://resources/js/mojo_bindings.js"></script>
<script src="chrome://resources/js/time.mojom.js"></script>
<script src="mojo/public/mojom/base/process_id.mojom.js"></script>
<script
src="chrome/browser/resource_coordinator/lifecycle_unit_state.mojom.js">
</script>
<script src="chrome/browser/ui/webui/discards/discards.mojom.js"></script>
<script src="mojom/webui_graph_dump.mojom.js"></script>
...@@ -410,6 +410,8 @@ DiscardsUI::DiscardsUI(content::WebUI* web_ui) ...@@ -410,6 +410,8 @@ DiscardsUI::DiscardsUI(content::WebUI* web_ui)
source->AddResourcePath("graph_tab.html", IDR_DISCARDS_GRAPH_TAB_HTML); source->AddResourcePath("graph_tab.html", IDR_DISCARDS_GRAPH_TAB_HTML);
source->AddResourcePath("graph_tab.js", IDR_DISCARDS_GRAPH_TAB_JS); source->AddResourcePath("graph_tab.js", IDR_DISCARDS_GRAPH_TAB_JS);
source->AddResourcePath("mojo_api.html", IDR_DISCARDS_MOJO_API_HTML);
// Full paths (relative to src) are important for Mojom generated files. // Full paths (relative to src) are important for Mojom generated files.
source->AddResourcePath("chrome/browser/ui/webui/discards/discards.mojom.js", source->AddResourcePath("chrome/browser/ui/webui/discards/discards.mojom.js",
IDR_DISCARDS_MOJO_JS); IDR_DISCARDS_MOJO_JS);
......
...@@ -48,13 +48,13 @@ TEST_F('DiscardsTest', 'CompareTabDiscardsInfo', function() { ...@@ -48,13 +48,13 @@ TEST_F('DiscardsTest', 'CompareTabDiscardsInfo', function() {
'isAutoDiscardable', 'discardCount', 'utilityRank', 'lastActiveSeconds'] 'isAutoDiscardable', 'discardCount', 'utilityRank', 'lastActiveSeconds']
.forEach((sortKey) => { .forEach((sortKey) => {
assertTrue( assertTrue(
discards.compareTabDiscardsInfos(sortKey, dummy1, dummy2) < 0); discards_tab.compareTabDiscardsInfos(sortKey, dummy1, dummy2) < 0);
assertTrue( assertTrue(
discards.compareTabDiscardsInfos(sortKey, dummy2, dummy1) > 0); discards_tab.compareTabDiscardsInfos(sortKey, dummy2, dummy1) > 0);
assertTrue( assertTrue(
discards.compareTabDiscardsInfos(sortKey, dummy1, dummy1) == 0); discards_tab.compareTabDiscardsInfos(sortKey, dummy1, dummy1) == 0);
assertTrue( assertTrue(
discards.compareTabDiscardsInfos(sortKey, dummy2, dummy2) == 0); discards_tab.compareTabDiscardsInfos(sortKey, dummy2, dummy2) == 0);
}); });
}); });
......
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