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

Side by Side Diff: content/browser/resources/media/new/main.js

Issue 23536020: Adds cache and buffer graphs to the properties pane. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: got tests running Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 /** 5 /**
6 * A global object that gets used by the C++ interface. 6 * A global object that gets used by the C++ interface.
7 */ 7 */
8 var media = (function() { 8 var media = (function() {
9 'use strict'; 9 'use strict';
10 10
11 var manager_ = null; 11 var manager_ = null;
12 12
13 // A number->string mapping that is populated through the backend that
14 // describes the phase that the network entity is in.
15 var eventPhases_ = {};
arv (Not doing code reviews) 2013/09/09 18:02:19 no underscores for variable names
Ty Overby 2013/09/09 18:28:35 Done.
16
17 // A number->string mapping that is populated through the backend that
18 // describes the type of event sent from the network.
19 var eventTypes_ = {};
20
21 // A mapping of number->CacheEntry where the number is a unique id for that
22 // network request.
23 var cacheEntries_ = {};
24
25 // A mapping of url->CacheEntity where the url is the url of the resource.
26 var cacheEntriesByKey_ = {};
27
28 var requestURLs_ = {};
29
30 var media = {
31 BAR_WIDTH: 200,
32 BAR_HEIGHT: 25
33 };
34
13 /** 35 /**
14 * Users of |media| must call initialize prior to calling other methods. 36 * Users of |media| must call initialize prior to calling other methods.
15 */ 37 */
16 media.initialize = function(manager) { 38 media.initialize = function(manager) {
17 manager_ = manager; 39 manager_ = manager;
18 }; 40 };
19 41
20 media.onReceiveEverything = function(everything) { 42 media.onReceiveEverything = function(everything) {
21 for (var key in everything.audio_streams) { 43 for (var key in everything.audio_streams) {
22 media.updateAudioStream(everything.audio_streams[key]); 44 media.updateAudioStream(everything.audio_streams[key]);
23 } 45 }
24 }; 46 };
25 47
26 media.onNetUpdate = function(update) { 48 media.onReceiveConstants = function(constants) {
27 // TODO(tyoverby): Implement 49 for (var key in constants.eventTypes) {
50 var value = constants.eventTypes[key];
51 eventTypes_[value] = key;
52 }
53
54 for (var key in constants.eventPhases) {
55 var value = constants.eventPhases[key];
56 eventPhases_[value] = key;
57 }
58 };
59
60 media.cacheForUrl = function(url) {
61 return cacheEntriesByKey_[url];
62 };
63
64 media.onNetUpdate = function(updates) {
65 updates.forEach(function(update) {
66 var id = update.source.id;
67 if (!cacheEntries_[id])
68 cacheEntries_[id] = new media.CacheEntry;
69
70 switch (eventPhases_[update.phase] + '.' + eventTypes_[update.type]) {
71 case 'PHASE_BEGIN.DISK_CACHE_ENTRY_IMPL':
72 var key = update.params.key;
73
74 // Merge this source with anything we already know about this key.
75 if (cacheEntriesByKey_[key]) {
76 cacheEntriesByKey_[key].merge(cacheEntries_[id]);
77 cacheEntries_[id] = cacheEntriesByKey_[key];
78 } else {
79 cacheEntriesByKey_[key] = cacheEntries_[id];
80 }
81 cacheEntriesByKey_[key].key = key;
82 break;
83
84 case 'PHASE_BEGIN.SPARSE_READ':
85 cacheEntries_[id].readBytes(update.params.offset,
86 update.params.buff_len);
87 cacheEntries_[id].sparse = true;
88 break;
89
90 case 'PHASE_BEGIN.SPARSE_WRITE':
91 cacheEntries_[id].writeBytes(update.params.offset,
92 update.params.buff_len);
93 cacheEntries_[id].sparse = true;
94 break;
95
96 case 'PHASE_BEGIN.URL_REQUEST_START_JOB':
97 requestURLs_[update.source.id] = update.params.url;
98 break;
99
100 case 'PHASE_NONE.HTTP_TRANSACTION_READ_RESPONSE_HEADERS':
101 // Record the total size of the file if this was a range request.
102 var range = /content-range:\s*bytes\s*\d+-\d+\/(\d+)/i.exec(
103 update.params.headers);
104 var key = requestURLs_[update.source.id];
105 delete requestURLs_[update.source.id];
106 if (range && key) {
107 if (!cacheEntriesByKey_[key]) {
108 cacheEntriesByKey_[key] = new media.CacheEntry;
109 cacheEntriesByKey_[key].key = key;
110 }
111 cacheEntriesByKey_[key].size = range[1];
112 }
113 break;
114 }
115 });
28 }; 116 };
29 117
30 media.onRendererTerminated = function(renderId) { 118 media.onRendererTerminated = function(renderId) {
31 util.object.forEach(manager_.players_, function(playerInfo, id) { 119 util.object.forEach(manager_.players_, function(playerInfo, id) {
32 if (playerInfo.properties['render_id'] == renderId) { 120 if (playerInfo.properties['render_id'] == renderId) {
33 manager_.removePlayer(id); 121 manager_.removePlayer(id);
34 } 122 }
35 }); 123 });
36 }; 124 };
37 125
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 180 }
93 propertyCount += 1; 181 propertyCount += 1;
94 }); 182 });
95 183
96 if (propertyCount === 0) { 184 if (propertyCount === 0) {
97 manager_.updatePlayerInfo( 185 manager_.updatePlayerInfo(
98 source, event.ticksMillis, 'EVENT', event.type); 186 source, event.ticksMillis, 'EVENT', event.type);
99 } 187 }
100 }; 188 };
101 189
190 // |chrome| is not defiend during tests.
arv (Not doing code reviews) 2013/09/09 18:02:19 Please define chrome in your test instead.
Charlie Reis 2013/09/09 18:02:22 nit: defined
Ty Overby 2013/09/09 18:28:13 Done.
Ty Overby 2013/09/09 18:28:13 This file is loaded after cr.js but before any tes
arv (Not doing code reviews) 2013/09/09 18:59:57 We are controlling that file too. It can add "var
191 if(window.chrome !== undefined) {
arv (Not doing code reviews) 2013/09/09 18:02:19 ws after if
Charlie Reis 2013/09/09 18:02:22 nit: Space after if
Ty Overby 2013/09/09 18:28:13 Done.
Ty Overby 2013/09/09 18:28:13 Done.
192 chrome.send('getEverything');
193 }
102 return media; 194 return media;
103 }()); 195 }());
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698