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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/profiler/ProfilesPanel.js

Issue 2626313002: DevTools: split ProfilesPanel into multiple files. (Closed)
Patch Set: rebaselined Created 3 years, 11 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 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 /** 26 /**
27 * @unrestricted
28 */
29 Profiler.ProfileType = class extends Common.Object {
30 /**
31 * @param {string} id
32 * @param {string} name
33 * @suppressGlobalPropertiesCheck
34 */
35 constructor(id, name) {
36 super();
37 this._id = id;
38 this._name = name;
39 /** @type {!Array.<!Profiler.ProfileHeader>} */
40 this._profiles = [];
41 /** @type {?Profiler.ProfileHeader} */
42 this._profileBeingRecorded = null;
43 this._nextProfileUid = 1;
44
45 if (!window.opener)
46 window.addEventListener('unload', this._clearTempStorage.bind(this), false );
47 }
48
49 /**
50 * @return {string}
51 */
52 typeName() {
53 return '';
54 }
55
56 /**
57 * @return {number}
58 */
59 nextProfileUid() {
60 return this._nextProfileUid;
61 }
62
63 /**
64 * @return {boolean}
65 */
66 hasTemporaryView() {
67 return false;
68 }
69
70 /**
71 * @return {?string}
72 */
73 fileExtension() {
74 return null;
75 }
76
77 get buttonTooltip() {
78 return '';
79 }
80
81 get id() {
82 return this._id;
83 }
84
85 get treeItemTitle() {
86 return this._name;
87 }
88
89 get name() {
90 return this._name;
91 }
92
93 /**
94 * @return {boolean}
95 */
96 buttonClicked() {
97 return false;
98 }
99
100 get description() {
101 return '';
102 }
103
104 /**
105 * @return {boolean}
106 */
107 isInstantProfile() {
108 return false;
109 }
110
111 /**
112 * @return {boolean}
113 */
114 isEnabled() {
115 return true;
116 }
117
118 /**
119 * @return {!Array.<!Profiler.ProfileHeader>}
120 */
121 getProfiles() {
122 /**
123 * @param {!Profiler.ProfileHeader} profile
124 * @return {boolean}
125 * @this {Profiler.ProfileType}
126 */
127 function isFinished(profile) {
128 return this._profileBeingRecorded !== profile;
129 }
130 return this._profiles.filter(isFinished.bind(this));
131 }
132
133 /**
134 * @return {?Element}
135 */
136 decorationElement() {
137 return null;
138 }
139
140 /**
141 * @param {number} uid
142 * @return {?Profiler.ProfileHeader}
143 */
144 getProfile(uid) {
145 for (var i = 0; i < this._profiles.length; ++i) {
146 if (this._profiles[i].uid === uid)
147 return this._profiles[i];
148 }
149 return null;
150 }
151
152 /**
153 * @param {!File} file
154 */
155 loadFromFile(file) {
156 var name = file.name;
157 var fileExtension = this.fileExtension();
158 if (fileExtension && name.endsWith(fileExtension))
159 name = name.substr(0, name.length - fileExtension.length);
160 var profile = this.createProfileLoadedFromFile(name);
161 profile.setFromFile();
162 this.setProfileBeingRecorded(profile);
163 this.addProfile(profile);
164 profile.loadFromFile(file);
165 }
166
167 /**
168 * @param {string} title
169 * @return {!Profiler.ProfileHeader}
170 */
171 createProfileLoadedFromFile(title) {
172 throw new Error('Needs implemented.');
173 }
174
175 /**
176 * @param {!Profiler.ProfileHeader} profile
177 */
178 addProfile(profile) {
179 this._profiles.push(profile);
180 this.dispatchEventToListeners(Profiler.ProfileType.Events.AddProfileHeader, profile);
181 }
182
183 /**
184 * @param {!Profiler.ProfileHeader} profile
185 */
186 removeProfile(profile) {
187 var index = this._profiles.indexOf(profile);
188 if (index === -1)
189 return;
190 this._profiles.splice(index, 1);
191 this._disposeProfile(profile);
192 }
193
194 _clearTempStorage() {
195 for (var i = 0; i < this._profiles.length; ++i)
196 this._profiles[i].removeTempFile();
197 }
198
199 /**
200 * @return {?Profiler.ProfileHeader}
201 */
202 profileBeingRecorded() {
203 return this._profileBeingRecorded;
204 }
205
206 /**
207 * @param {?Profiler.ProfileHeader} profile
208 */
209 setProfileBeingRecorded(profile) {
210 this._profileBeingRecorded = profile;
211 }
212
213 profileBeingRecordedRemoved() {
214 }
215
216 reset() {
217 this._profiles.slice(0).forEach(this._disposeProfile.bind(this));
218 this._profiles = [];
219 this._nextProfileUid = 1;
220 }
221
222 /**
223 * @param {!Profiler.ProfileHeader} profile
224 */
225 _disposeProfile(profile) {
226 this.dispatchEventToListeners(Profiler.ProfileType.Events.RemoveProfileHeade r, profile);
227 profile.dispose();
228 if (this._profileBeingRecorded === profile) {
229 this.profileBeingRecordedRemoved();
230 this.setProfileBeingRecorded(null);
231 }
232 }
233 };
234
235 /** @enum {symbol} */
236 Profiler.ProfileType.Events = {
237 AddProfileHeader: Symbol('add-profile-header'),
238 ProfileComplete: Symbol('profile-complete'),
239 RemoveProfileHeader: Symbol('remove-profile-header'),
240 ViewUpdated: Symbol('view-updated')
241 };
242
243 /**
244 * @interface
245 */
246 Profiler.ProfileType.DataDisplayDelegate = function() {};
247
248 Profiler.ProfileType.DataDisplayDelegate.prototype = {
249 /**
250 * @param {?Profiler.ProfileHeader} profile
251 * @return {?UI.Widget}
252 */
253 showProfile(profile) {},
254
255 /**
256 * @param {!Protocol.HeapProfiler.HeapSnapshotObjectId} snapshotObjectId
257 * @param {string} perspectiveName
258 */
259 showObject(snapshotObjectId, perspectiveName) {}
260 };
261
262 /**
263 * @unrestricted
264 */
265 Profiler.ProfileHeader = class extends Common.Object {
266 /**
267 * @param {?SDK.Target} target
268 * @param {!Profiler.ProfileType} profileType
269 * @param {string} title
270 */
271 constructor(target, profileType, title) {
272 super();
273 this._target = target;
274 this._profileType = profileType;
275 this.title = title;
276 this.uid = profileType._nextProfileUid++;
277 this._fromFile = false;
278 }
279
280 /**
281 * @return {?SDK.Target}
282 */
283 target() {
284 return this._target;
285 }
286
287 /**
288 * @return {!Profiler.ProfileType}
289 */
290 profileType() {
291 return this._profileType;
292 }
293
294 /**
295 * @param {?string} subtitle
296 * @param {boolean=} wait
297 */
298 updateStatus(subtitle, wait) {
299 this.dispatchEventToListeners(
300 Profiler.ProfileHeader.Events.UpdateStatus, new Profiler.ProfileHeader.S tatusUpdate(subtitle, wait));
301 }
302
303 /**
304 * Must be implemented by subclasses.
305 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate
306 * @return {!Profiler.ProfileSidebarTreeElement}
307 */
308 createSidebarTreeElement(dataDisplayDelegate) {
309 throw new Error('Needs implemented.');
310 }
311
312 /**
313 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate
314 * @return {!UI.Widget}
315 */
316 createView(dataDisplayDelegate) {
317 throw new Error('Not implemented.');
318 }
319
320 removeTempFile() {
321 if (this._tempFile)
322 this._tempFile.remove();
323 }
324
325 dispose() {
326 }
327
328 /**
329 * @return {boolean}
330 */
331 canSaveToFile() {
332 return false;
333 }
334
335 saveToFile() {
336 throw new Error('Needs implemented');
337 }
338
339 /**
340 * @param {!File} file
341 */
342 loadFromFile(file) {
343 throw new Error('Needs implemented');
344 }
345
346 /**
347 * @return {boolean}
348 */
349 fromFile() {
350 return this._fromFile;
351 }
352
353 setFromFile() {
354 this._fromFile = true;
355 }
356 };
357
358 /**
359 * @unrestricted
360 */
361 Profiler.ProfileHeader.StatusUpdate = class {
362 /**
363 * @param {?string} subtitle
364 * @param {boolean|undefined} wait
365 */
366 constructor(subtitle, wait) {
367 /** @type {?string} */
368 this.subtitle = subtitle;
369 /** @type {boolean|undefined} */
370 this.wait = wait;
371 }
372 };
373
374 /** @enum {symbol} */
375 Profiler.ProfileHeader.Events = {
376 UpdateStatus: Symbol('UpdateStatus'),
377 ProfileReceived: Symbol('ProfileReceived')
378 };
379
380 /**
381 * @implements {Profiler.ProfileType.DataDisplayDelegate} 27 * @implements {Profiler.ProfileType.DataDisplayDelegate}
382 * @unrestricted 28 * @unrestricted
383 */ 29 */
384 Profiler.ProfilesPanel = class extends UI.PanelWithSidebar { 30 Profiler.ProfilesPanel = class extends UI.PanelWithSidebar {
385 constructor() { 31 constructor() {
386 super('profiles'); 32 super('profiles');
387 this.registerRequiredCSS('ui/panelEnablerView.css'); 33 this.registerRequiredCSS('ui/panelEnablerView.css');
388 this.registerRequiredCSS('profiler/heapProfiler.css'); 34 this.registerRequiredCSS('profiler/heapProfiler.css');
389 this.registerRequiredCSS('profiler/profilesPanel.css'); 35 this.registerRequiredCSS('profiler/profilesPanel.css');
390 this.registerRequiredCSS('components/objectValue.css'); 36 this.registerRequiredCSS('components/objectValue.css');
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 var typeId = profileType.id; 327 var typeId = profileType.id;
682 this._typeIdToSidebarSection[typeId].addProfileHeader(profile); 328 this._typeIdToSidebarSection[typeId].addProfileHeader(profile);
683 if (!this.visibleView || this.visibleView === this._launcherView) 329 if (!this.visibleView || this.visibleView === this._launcherView)
684 this.showProfile(profile); 330 this.showProfile(profile);
685 } 331 }
686 332
687 /** 333 /**
688 * @param {!Profiler.ProfileHeader} profile 334 * @param {!Profiler.ProfileHeader} profile
689 */ 335 */
690 _removeProfileHeader(profile) { 336 _removeProfileHeader(profile) {
691 if (profile.profileType()._profileBeingRecorded === profile) 337 if (profile.profileType().profileBeingRecorded() === profile)
692 this._profileBeingRecordedRemoved(); 338 this._profileBeingRecordedRemoved();
693 339
694 var i = this._indexOfViewForProfile(profile); 340 var i = this._indexOfViewForProfile(profile);
695 if (i !== -1) 341 if (i !== -1)
696 this._profileToView.splice(i, 1); 342 this._profileToView.splice(i, 1);
697 343
698 var profileType = profile.profileType(); 344 var profileType = profile.profileType();
699 var typeId = profileType.id; 345 var typeId = profileType.id;
700 var sectionIsEmpty = this._typeIdToSidebarSection[typeId].removeProfileHeade r(profile); 346 var sectionIsEmpty = this._typeIdToSidebarSection[typeId].removeProfileHeade r(profile);
701 347
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 return -1; 432 return -1;
787 } 433 }
788 434
789 closeVisibleView() { 435 closeVisibleView() {
790 if (this.visibleView) 436 if (this.visibleView)
791 this.visibleView.detach(); 437 this.visibleView.detach();
792 delete this.visibleView; 438 delete this.visibleView;
793 } 439 }
794 440
795 /** 441 /**
796 * @param {!Event} event
797 * @param {!UI.ContextMenu} contextMenu
798 * @param {!Object} target
799 */
800 appendApplicableItems(event, contextMenu, target) {
801 if (!(target instanceof SDK.RemoteObject))
802 return;
803
804 if (!this.isShowing())
805 return;
806
807 var object = /** @type {!SDK.RemoteObject} */ (target);
808 var objectId = object.objectId;
809 if (!objectId)
810 return;
811
812 var heapProfiles = Profiler.ProfileTypeRegistry.instance.heapSnapshotProfile Type.getProfiles();
813 if (!heapProfiles.length)
814 return;
815
816 /**
817 * @this {Profiler.ProfilesPanel}
818 */
819 function revealInView(viewName) {
820 object.target().heapProfilerAgent().getHeapObjectId(objectId, didReceiveHe apObjectId.bind(this, viewName));
821 }
822
823 /**
824 * @this {Profiler.ProfilesPanel}
825 */
826 function didReceiveHeapObjectId(viewName, error, result) {
827 if (!this.isShowing())
828 return;
829 if (!error)
830 this.showObject(result, viewName);
831 }
832
833 contextMenu.appendItem(Common.UIString.capitalize('Reveal in Summary ^view') , revealInView.bind(this, 'Summary'));
834 }
835
836 /**
837 * @override
838 */
839 wasShown() {
840 UI.context.setFlavor(Profiler.ProfilesPanel, this);
841 }
842
843 /**
844 * @override 442 * @override
845 */ 443 */
846 focus() { 444 focus() {
847 this._sidebarTree.focus(); 445 this._sidebarTree.focus();
848 } 446 }
849
850 /**
851 * @override
852 */
853 willHide() {
854 UI.context.setFlavor(Profiler.ProfilesPanel, null);
855 }
856 }; 447 };
857 448
858 /** 449 /**
859 * @unrestricted 450 * @unrestricted
860 */ 451 */
861 Profiler.ProfileTypeSidebarSection = class extends UI.TreeElement { 452 Profiler.ProfileTypeSidebarSection = class extends UI.TreeElement {
862 /** 453 /**
863 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate 454 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate
864 * @param {!Profiler.ProfileType} profileType 455 * @param {!Profiler.ProfileType} profileType
865 */ 456 */
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 Profiler.ProfileTypeSidebarSection.ProfileGroup = class { 593 Profiler.ProfileTypeSidebarSection.ProfileGroup = class {
1003 constructor() { 594 constructor() {
1004 /** @type {!Array<!Profiler.ProfileSidebarTreeElement>} */ 595 /** @type {!Array<!Profiler.ProfileSidebarTreeElement>} */
1005 this.profileSidebarTreeElements = []; 596 this.profileSidebarTreeElements = [];
1006 /** @type {?Profiler.ProfileGroupSidebarTreeElement} */ 597 /** @type {?Profiler.ProfileGroupSidebarTreeElement} */
1007 this.sidebarTreeElement = null; 598 this.sidebarTreeElement = null;
1008 } 599 }
1009 }; 600 };
1010 601
1011 /** 602 /**
1012 * @implements {UI.ContextMenu.Provider}
1013 * @unrestricted
1014 */
1015 Profiler.ProfilesPanel.ContextMenuProvider = class {
1016 /**
1017 * @override
1018 * @param {!Event} event
1019 * @param {!UI.ContextMenu} contextMenu
1020 * @param {!Object} target
1021 */
1022 appendApplicableItems(event, contextMenu, target) {
1023 Profiler.ProfilesPanel._instance().appendApplicableItems(event, contextMenu, target);
1024 }
1025 };
1026
1027 /**
1028 * @unrestricted 603 * @unrestricted
1029 */ 604 */
1030 Profiler.ProfileSidebarTreeElement = class extends UI.TreeElement { 605 Profiler.ProfileSidebarTreeElement = class extends UI.TreeElement {
1031 /** 606 /**
1032 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate 607 * @param {!Profiler.ProfileType.DataDisplayDelegate} dataDisplayDelegate
1033 * @param {!Profiler.ProfileHeader} profile 608 * @param {!Profiler.ProfileHeader} profile
1034 * @param {string} className 609 * @param {string} className
1035 */ 610 */
1036 constructor(dataDisplayDelegate, profile, className) { 611 constructor(dataDisplayDelegate, profile, className) {
1037 super('', false); 612 super('', false);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 */ 788 */
1214 onattach() { 789 onattach() {
1215 this.listItemElement.classList.add('profile-launcher-view-tree-item'); 790 this.listItemElement.classList.add('profile-launcher-view-tree-item');
1216 this.listItemElement.createChild('div', 'icon'); 791 this.listItemElement.createChild('div', 'icon');
1217 this.listItemElement.createChild('div', 'titles no-subtitle') 792 this.listItemElement.createChild('div', 'titles no-subtitle')
1218 .createChild('span', 'title-container') 793 .createChild('span', 'title-container')
1219 .createChild('span', 'title') 794 .createChild('span', 'title')
1220 .textContent = Common.UIString('Profiles'); 795 .textContent = Common.UIString('Profiles');
1221 } 796 }
1222 }; 797 };
1223
1224 /**
1225 * @implements {UI.ActionDelegate}
1226 */
1227 Profiler.ProfilesPanel.RecordActionDelegate = class {
1228 /**
1229 * @override
1230 * @param {!UI.Context} context
1231 * @param {string} actionId
1232 * @return {boolean}
1233 */
1234 handleAction(context, actionId) {
1235 var panel = UI.context.flavor(Profiler.ProfilesPanel);
1236 console.assert(panel && panel instanceof Profiler.ProfilesPanel);
1237 panel.toggleRecord();
1238 return true;
1239 }
1240 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698