cros: Remove default pinned apps trial.
[chromium-blink-merge.git] / chrome / browser / resources / net_internals / capture_status_view.js
bloba5edac70919ddff76428e30d1ba759cdab6a7300
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.
5 /**
6  * The status view at the top of the page when in capturing mode.
7  */
8 var CaptureStatusView = (function() {
9   'use strict';
11   // We inherit from DivView.
12   var superClass = DivView;
14   function CaptureStatusView() {
15     superClass.call(this, CaptureStatusView.MAIN_BOX_ID);
17     this.getDropdown_().onchange = this.onSelectAction_.bind(this);
18     this.getDropdown_().selectedIndex = -1;
20     this.capturedEventsCountBox_ =
21         $(CaptureStatusView.CAPTURED_EVENTS_COUNT_ID);
22     this.updateEventCounts_();
24     EventsTracker.getInstance().addLogEntryObserver(this);
25   }
27   // IDs for special HTML elements in status_view.html
28   CaptureStatusView.MAIN_BOX_ID = 'capture-status-view';
29   CaptureStatusView.ACTIONS_DROPDOWN_ID = 'capture-status-view-actions';
30   CaptureStatusView.CAPTURED_EVENTS_COUNT_ID =
31       'capture-status-view-captured-events-count';
33   CaptureStatusView.prototype = {
34     // Inherit the superclass's methods.
35     __proto__: superClass.prototype,
37     /**
38      * Called whenever new log entries have been received.
39      */
40     onReceivedLogEntries: function(logEntries) {
41       this.updateEventCounts_();
42     },
44     /**
45      * Called whenever all log events are deleted.
46      */
47     onAllLogEntriesDeleted: function() {
48       this.updateEventCounts_();
49     },
51     /**
52      * Updates the counters showing how many events have been captured.
53      */
54     updateEventCounts_: function() {
55       this.capturedEventsCountBox_.textContent =
56           EventsTracker.getInstance().getNumCapturedEvents();
57     },
59     getDropdown_: function() {
60       return $(CaptureStatusView.ACTIONS_DROPDOWN_ID);
61     },
63     onSelectAction_: function() {
64       var dropdown = this.getDropdown_();
65       var action = dropdown.value;
66       dropdown.selectedIndex = -1;
68       if (action == 'stop') {
69         $(CaptureView.STOP_BUTTON_ID).click();
70       } else if (action == 'reset') {
71         $(CaptureView.RESET_BUTTON_ID).click();
72       } else if (action == 'clear-cache') {
73         g_browser.sendClearAllCache();
74       } else if (action == 'flush-sockets') {
75         g_browser.sendFlushSocketPools();
76       } else {
77         throw Error('Unrecognized action: ' + action);
78       }
79     },
80   };
82   return CaptureStatusView;
83 })();