Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Side by Side Diff: chrome/browser/resources/predictors/resource_prefetch_predictor.js

Issue 10416002: Seculative resource prefetching for URLs CL. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * Requests the database from the backend.
7 */
8 function requestResourcePrefetchPredictorDb() {
9 chrome.send('requestResourcePrefetchPredictorDb');
10 }
11
12 /**
13 * Callback from backend with the database contents. Sets up some globals and
14 * calls to create the UI.
15 * @param {Dictionary} database Information about ResourcePrefetchPredictor
16 * including the database as a flattened list, a boolean indicating if the
17 * system is enabled.
18 */
19 function updateResourcePrefetchPredictorDb(database) {
20 updateResourcePrefetchPredictorDbView(database);
21 }
22
23 /**
24 * Truncates the string to keep the database readable.
25 * @param {String} str The string to truncate.
26 */
27 function truncateString(str) {
28 return str.length < 100 ? str : str.substring(0, 99);
29 }
30
31 /**
32 * Updates the table from the database.
33 * @param {Dictionary} database Information about ResourcePrefetchPredictor
34 * including the database as a flattened list, a boolean indicating if the
35 * system is enabled and the current hit weight.
36 */
37 function updateResourcePrefetchPredictorDbView(database) {
38 if (!database.enabled) {
39 $('resource_prefetch_predictor_enabled').style.display = 'none';
40 $('resource_prefetch_predictor_disabled').style.display = 'block';
41 return;
42 } else {
43 $('resource_prefetch_predictor_enabled').style.display = 'block';
44 $('resource_prefetch_predictor_disabled').style.display = 'none';
45 }
46
47 if (database.db) {
48 if (database.db.length > 0) {
49 $('resource_prefetch_predictor_db').style.display = 'block';
50 $('empty_resource_prefetch_predictor_db').style.display = 'none';
51 } else {
52 $('resource_prefetch_predictor_db').style.display = 'none';
53 $('empty_resource_prefetch_predictor_db').style.display = 'block';
54 }
55
56 var dbSection = $('resource_prefetch_predictor_db_body');
57 dbSection.textContent = '';
58 for (var i = 0; i < database.db.length; ++i) {
59 var main = database.db[i];
60
61 for (var j = 0; j < main.resources.length; ++j) {
62 var resource = main.resources[j];
63 var row = document.createElement('tr');
64
65 if (j == 0) {
66 var t = document.createElement('td');
67 t.rowSpan = main.resources.length;
68 t.textContent = truncateString(main.main_frame_url);
69 t.className = 'last';
70 row.appendChild(t);
71 }
72
73 if (j == main.resources.length - 1)
74 row.className = 'last';
75
76 row.appendChild(document.createElement('td')).textContent =
77 truncateString(resource.resource_url);
78 row.appendChild(document.createElement('td')).textContent =
79 resource.resource_type;
80 row.appendChild(document.createElement('td')).textContent =
81 resource.number_of_hits;
82 row.appendChild(document.createElement('td')).textContent =
83 resource.number_of_misses;
84 row.appendChild(document.createElement('td')).textContent =
85 resource.consecutive_misses;
86 row.appendChild(document.createElement('td')).textContent =
87 resource.position;
88 row.appendChild(document.createElement('td')).textContent =
89 resource.score;
90 dbSection.appendChild(row);
91 }
92 }
93 }
94 }
95
96 document.addEventListener('DOMContentLoaded',
97 requestResourcePrefetchPredictorDb);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698