diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-16 03:43:16 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-16 03:43:16 +0000 |
commit | 56fc73c863b1e0d111e61ad815ed987d8aa870c2 (patch) | |
tree | 1c62f3e3731832e113c9734c48a81ddf4b6c2667 /chrome/browser/resources/net_internals | |
parent | 7b6eba8c18b0046b959cadc06876f61aa6bdf534 (diff) | |
download | chromium_src-56fc73c863b1e0d111e61ad815ed987d8aa870c2.zip chromium_src-56fc73c863b1e0d111e61ad815ed987d8aa870c2.tar.gz chromium_src-56fc73c863b1e0d111e61ad815ed987d8aa870c2.tar.bz2 |
Fixup style of LogGrouper
BUG=90857
Review URL: http://codereview.chromium.org/8296009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105713 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/resources/net_internals')
-rw-r--r-- | chrome/browser/resources/net_internals/log_grouper.js | 147 |
1 files changed, 78 insertions, 69 deletions
diff --git a/chrome/browser/resources/net_internals/log_grouper.js b/chrome/browser/resources/net_internals/log_grouper.js index 8d7fb32..d78b64e 100644 --- a/chrome/browser/resources/net_internals/log_grouper.js +++ b/chrome/browser/resources/net_internals/log_grouper.js @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -14,80 +14,89 @@ // TODO(eroman): document these methods! -function LogGroupEntry(origEntry, index) { - this.orig = origEntry; - this.index = index; -} - -LogGroupEntry.prototype.isBegin = function() { - return this.orig.phase == LogEventPhase.PHASE_BEGIN; -}; - -LogGroupEntry.prototype.isEnd = function() { - return this.orig.phase == LogEventPhase.PHASE_END -}; - -LogGroupEntry.prototype.getDepth = function() { - var depth = 0; - var p = this.parentEntry; - while (p) { - depth += 1; - p = p.parentEntry; +var LogGroupEntry = (function() { + 'use strict'; + + function LogGroupEntry(origEntry, index) { + this.orig = origEntry; + this.index = index; } - return depth; -}; -function findParentIndex(parentStack, eventType) { - for (var i = parentStack.length - 1; i >= 0; --i) { - if (parentStack[i].orig.type == eventType) - return i; + LogGroupEntry.prototype = { + isBegin: function() { + return this.orig.phase == LogEventPhase.PHASE_BEGIN; + }, + + isEnd: function() { + return this.orig.phase == LogEventPhase.PHASE_END + }, + + getDepth: function() { + var depth = 0; + var p = this.parentEntry; + while (p) { + depth += 1; + p = p.parentEntry; + } + return depth; + } + }; + + function findParentIndex(parentStack, eventType) { + for (var i = parentStack.length - 1; i >= 0; --i) { + if (parentStack[i].orig.type == eventType) + return i; + } + return -1; } - return -1; -} -/** - * Returns a list of LogGroupEntrys. This basically wraps the original log - * entry, but makes it easier to find the start/end of the event. - */ -LogGroupEntry.createArrayFrom = function(origEntries) { - var groupedEntries = []; - - // Stack of enclosing PHASE_BEGIN elements. - var parentStack = []; - - for (var i = 0; i < origEntries.length; ++i) { - var origEntry = origEntries[i]; - - var groupEntry = new LogGroupEntry(origEntry, i); - groupedEntries.push(groupEntry); - - // If this is the end of an event, match it to the start. - if (groupEntry.isEnd()) { - // Walk up the parent stack to find the corresponding BEGIN for this END. - var parentIndex = - findParentIndex(parentStack, groupEntry.orig.type); - - if (parentIndex == -1) { - // Unmatched end. - } else { - groupEntry.begin = parentStack[parentIndex]; - - // Consider this as the terminator for all open BEGINs up until - // parentIndex. - while (parentIndex < parentStack.length) { - var p = parentStack.pop(); - p.end = groupEntry; + /** + * Returns a list of LogGroupEntrys. This basically wraps the original log + * entry, but makes it easier to find the start/end of the event. + */ + LogGroupEntry.createArrayFrom = function(origEntries) { + var groupedEntries = []; + + // Stack of enclosing PHASE_BEGIN elements. + var parentStack = []; + + for (var i = 0; i < origEntries.length; ++i) { + var origEntry = origEntries[i]; + + var groupEntry = new LogGroupEntry(origEntry, i); + groupedEntries.push(groupEntry); + + // If this is the end of an event, match it to the start. + if (groupEntry.isEnd()) { + // Walk up the parent stack to find the corresponding BEGIN for this + // END. + var parentIndex = + findParentIndex(parentStack, groupEntry.orig.type); + + if (parentIndex == -1) { + // Unmatched end. + } else { + groupEntry.begin = parentStack[parentIndex]; + + // Consider this as the terminator for all open BEGINs up until + // parentIndex. + while (parentIndex < parentStack.length) { + var p = parentStack.pop(); + p.end = groupEntry; + } } } - } - // Inherit the current parent. - if (parentStack.length > 0) - groupEntry.parentEntry = parentStack[parentStack.length - 1]; + // Inherit the current parent. + if (parentStack.length > 0) + groupEntry.parentEntry = parentStack[parentStack.length - 1]; - if (groupEntry.isBegin()) - parentStack.push(groupEntry); - } + if (groupEntry.isBegin()) + parentStack.push(groupEntry); + } + + return groupedEntries; + }; - return groupedEntries; -} + return LogGroupEntry; +})(); |