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

Side by Side Diff: chrome/browser/resources/snippets_internals.js

Issue 2346263002: Extending the UserClassifier to actually support classification. (Closed)
Patch Set: Removing unnecessary static_casts Created 4 years, 3 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('chrome.SnippetsInternals', function() { 5 cr.define('chrome.SnippetsInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 // Stores the list of suggestions we received in receiveContentSuggestions. 8 // Stores the list of suggestions we received in receiveContentSuggestions.
9 var lastSuggestions = []; 9 var lastSuggestions = [];
10 10
(...skipping 10 matching lines...) Expand all
21 21
22 $('last-json-button').addEventListener('click', function(event) { 22 $('last-json-button').addEventListener('click', function(event) {
23 $('last-json-container').classList.toggle('hidden'); 23 $('last-json-container').classList.toggle('hidden');
24 }); 24 });
25 25
26 $('last-json-dump').addEventListener('click', function(event) { 26 $('last-json-dump').addEventListener('click', function(event) {
27 downloadJson($('last-json-text').innerText); 27 downloadJson($('last-json-text').innerText);
28 event.preventDefault(); 28 event.preventDefault();
29 }); 29 });
30 30
31 $('clear-classification').addEventListener('click', function(event) {
32 chrome.send('clearClassification');
33 event.preventDefault();
34 });
35
31 window.addEventListener('focus', refreshContent); 36 window.addEventListener('focus', refreshContent);
32 window.setInterval(refreshContent, 1000); 37 window.setInterval(refreshContent, 1000);
33 38
34 refreshContent(); 39 refreshContent();
35 } 40 }
36 41
37 function setHostRestricted(restricted) { 42 function setHostRestricted(restricted) {
38 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False'); 43 receiveProperty('switch-restrict-to-hosts', restricted ? 'True' : 'False');
39 if (!restricted) { 44 if (!restricted) {
40 $('hosts-restrict').classList.add('hidden'); 45 $('hosts-restrict').classList.add('hidden');
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 var hasContent = (trimmed && trimmed != '{}'); 107 var hasContent = (trimmed && trimmed != '{}');
103 108
104 if (hasContent) { 109 if (hasContent) {
105 receiveProperty('last-json-text', trimmed); 110 receiveProperty('last-json-text', trimmed);
106 $('last-json').classList.remove('hidden'); 111 $('last-json').classList.remove('hidden');
107 } else { 112 } else {
108 $('last-json').classList.add('hidden'); 113 $('last-json').classList.add('hidden');
109 } 114 }
110 } 115 }
111 116
117 function receiveClassification(
118 userClass, timeToOpenNTP, timeToShow, timeToUse) {
119 receiveProperty('user-class', userClass);
120 receiveProperty('avg-time-to-open-ntp', timeToOpenNTP);
121 receiveProperty('avg-time-to-show', timeToShow);
122 receiveProperty('avg-time-to-use', timeToUse);
123 }
124
112 function downloadJson(json) { 125 function downloadJson(json) {
113 // Redirect the browser to download data in |json| as a file "snippets.json" 126 // Redirect the browser to download data in |json| as a file "snippets.json"
114 // (Setting Content-Disposition: attachment via a data: URL is not possible; 127 // (Setting Content-Disposition: attachment via a data: URL is not possible;
115 // create a link with download attribute and simulate a click, instead.) 128 // create a link with download attribute and simulate a click, instead.)
116 var link = document.createElement('a'); 129 var link = document.createElement('a');
117 link.download = 'snippets.json'; 130 link.download = 'snippets.json';
118 link.href = 'data:,' + json; 131 link.href = 'data:,' + json;
119 link.click(); 132 link.click();
120 } 133 }
121 134
(...skipping 30 matching lines...) Expand all
152 } 165 }
153 166
154 // Return an object with all of the exports. 167 // Return an object with all of the exports.
155 return { 168 return {
156 initialize: initialize, 169 initialize: initialize,
157 setHostRestricted: setHostRestricted, 170 setHostRestricted: setHostRestricted,
158 receiveProperty: receiveProperty, 171 receiveProperty: receiveProperty,
159 receiveHosts: receiveHosts, 172 receiveHosts: receiveHosts,
160 receiveContentSuggestions: receiveContentSuggestions, 173 receiveContentSuggestions: receiveContentSuggestions,
161 receiveJson: receiveJson, 174 receiveJson: receiveJson,
175 receiveClassification: receiveClassification,
162 }; 176 };
163 }); 177 });
164 178
165 document.addEventListener('DOMContentLoaded', 179 document.addEventListener('DOMContentLoaded',
166 chrome.SnippetsInternals.initialize); 180 chrome.SnippetsInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698