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

Unified Diff: chrome/browser/resources/net_export/net_export.js

Issue 11635023: First cut at UI for saving net_logs data into a temporary file on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/net_export/net_export.js
===================================================================
--- chrome/browser/resources/net_export/net_export.js (revision 0)
+++ chrome/browser/resources/net_export/net_export.js (revision 0)
@@ -0,0 +1,175 @@
+// Copyright (c) 2012 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.
+
+var g_mainExportView;
+
+/**
+ * Object to communicate between the renderer and the browser.
+ * @type {!BrowserBridge}
+ */
+var g_exportBrowserBridge = null;
+
+/**
+ * Main entry point called once the page has loaded.
+ */
+function onLoad() {
+ g_exportBrowserBridge = new BrowserBridge();
+ g_mainExportView = new MainView();
+}
+
+document.addEventListener('DOMContentLoaded', onLoad);
+
+
+/**
+ * This class provides a "bridge" for communicating between the javascript and
+ * the browser.
+ */
+var BrowserBridge = (function() {
+ 'use strict';
+
+ /**
+ * Delay in milliseconds between updates of certain browser information.
+ */
+ var POLL_INTERVAL_MS = 5000;
+
+ /**
+ * @constructor
+ */
+ function BrowserBridge() {
+ }
+
+ BrowserBridge.prototype = {
+
+ //--------------------------------------------------------------------------
+ // Messages sent to the browser
+ //--------------------------------------------------------------------------
+
+ setPollInterval: function() {
+ window.setInterval(this.sendGetMobileNetLogInfo.bind(this),
+ POLL_INTERVAL_MS);
+ },
+
+ sendGetMobileNetLogInfo: function() {
+ chrome.send('getMobileNetLogInfo');
+ },
+
+ sendStartNetLog: function() {
+ chrome.send('startNetLog');
+ },
+
+ sendStopNetLog: function() {
+ chrome.send('stopNetLog');
+ },
+
+ sendSendNetLog: function() {
+ chrome.send('sendNetLog');
+ },
+
+ //--------------------------------------------------------------------------
+ // Messages received from the browser.
+ //--------------------------------------------------------------------------
+
+ receivedData: function(data) {
+ g_mainExportView.onMobileNetLogInfoChanged(data);
+ }
+ };
+
+ return BrowserBridge;
+})();
+
+/**
+ * This class handles the presentation of our profiler view. Used as a
+ * singleton.
+ */
+var MainView = (function() {
+ 'use strict';
+
+ // --------------------------------------------------------------------------
+ // Important IDs in the HTML document
+ // --------------------------------------------------------------------------
+
+ var START_DATA_BUTTON_ID = 'mobile-view-start-data';
+ var STOP_DATA_BUTTON_ID = 'mobile-view-stop-data';
+ var SEND_DATA_BUTTON_ID = 'mobile-view-send-data';
+ var FILE_PATH_TEXT_ID = 'mobile-view-file-path-text';
+
+ // --------------------------------------------------------------------------
+
+ /**
+ * @constructor
+ */
+ function MainView() {
+ this.init_();
+
+ g_exportBrowserBridge.setPollInterval();
+
+ g_exportBrowserBridge.sendGetMobileNetLogInfo();
+ }
+
+ MainView.prototype = {
+ init_: function() {
+ this.startDataButton_ = $(START_DATA_BUTTON_ID);
+ this.startDataButton_.onclick = this.onStartData_.bind(this);
+ this.stopDataButton_ = $(STOP_DATA_BUTTON_ID);
+ this.stopDataButton_.onclick = this.onStopData_.bind(this);
+ this.sendDataButton_ = $(SEND_DATA_BUTTON_ID);
+ this.sendDataButton_.onclick = this.onSendData_.bind(this);
+ this.filePathText_ = $(FILE_PATH_TEXT_ID);
+ },
+
+ /**
+ * Starts saving NetLog data to a file.
+ */
+ onStartData_: function() {
+ g_exportBrowserBridge.sendStartNetLog();
+ g_exportBrowserBridge.sendGetMobileNetLogInfo();
+ },
+
+ /**
+ * Stops saving NetLog data to a file.
+ */
+ onStopData_: function() {
+ g_exportBrowserBridge.sendStopNetLog();
+ g_exportBrowserBridge.sendGetMobileNetLogInfo();
+ },
+
+ /**
+ * Sends NetLog data via email from browser.
+ */
+ onSendData_: function() {
+ g_exportBrowserBridge.sendSendNetLog();
+ g_exportBrowserBridge.sendGetMobileNetLogInfo();
+ },
+
+ onMobileNetLogInfoChanged: function(mobileNetLogInfo) {
+ this.filePathText_.textContent = '';
+ if (mobileNetLogInfo.file) {
+ var message = '';
+ if (mobileNetLogInfo.state == 'ALLOW_STOP') {
+ message = 'NetLog data is collected in: ';
+ } else if (mobileNetLogInfo.state == 'ALLOW_START_SEND') {
+ message = 'NetLog data to send is in: ';
+ }
+ this.filePathText_.textContent = message + mobileNetLogInfo.file;
+ } else {
+ this.filePathText_.textContent = '';
+ }
+ this.startDataButton_.disabled = false;
+ this.stopDataButton_.disabled = false;
+ this.sendDataButton_.disabled = false;
+ if (mobileNetLogInfo.state == 'ALLOW_START') {
+ this.stopDataButton_.disabled = true;
+ this.sendDataButton_.disabled = true;
+ } else if (mobileNetLogInfo.state == 'ALLOW_STOP') {
+ this.startDataButton_.disabled = true;
+ this.sendDataButton_.disabled = true;
+ } else if (mobileNetLogInfo.state == 'ALLOW_START_SEND') {
+ this.stopDataButton_.disabled = true;
+ }
+ return true;
+ }
+ };
+
+ return MainView;
+})();
« no previous file with comments | « chrome/browser/resources/net_export/net_export.html ('k') | chrome/browser/resources/web_dev_style/js_checker.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698