<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2013 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.
-->

<link rel="import" href="/ui/extras/about_tracing/record_selection_dialog.html">

<script>
'use strict';

tr.exportTo('tr.ui.e.about_tracing', function() {
  function beginMonitoring(tracingControllerClient) {
    var finalPromiseResolver;
    var finalPromise = new Promise(function(resolve, reject) {
      finalPromiseResolver = {
        resolve: resolve,
        reject: reject
      };
    });

    // TODO(haraken): Implement a configure dialog to set these options.
    var monitoringOptions = {
      categoryFilter: '*',
      useSystemTracing: false,
      tracingRecordMode: 'record-until-full',
      useSampling: true
    };


    var beginMonitoringPromise = tracingControllerClient.beginMonitoring(
        monitoringOptions);

    beginMonitoringPromise.then(
        function() {
          finalPromiseResolver.resolve();
        },
        function(err) {
          finalPromiseResolver.reject(err);
        });

    return finalPromise;
  }

  function endMonitoring(tracingControllerClient) {
    var endMonitoringPromise = tracingControllerClient.endMonitoring();
    return endMonitoringPromise.then(
        function() {
        },
        function(err) {
        });
  }

  function captureMonitoring(tracingControllerClient) {
    var captureMonitoringPromise =
        tracingControllerClient.captureMonitoring();
    return captureMonitoringPromise;
  }

  function getMonitoringStatus(tracingControllerClient) {
    var getMonitoringStatusPromise =
        tracingControllerClient.getMonitoringStatus();
    return getMonitoringStatusPromise;
  }

  function beginRecording(tracingControllerClient) {
    var finalPromiseResolver;
    var finalPromise = new Promise(function(resolve, reject) {
      finalPromiseResolver = {
        resolve: resolve,
        reject: reject
      };
    });
    finalPromise.selectionDlg = undefined;
    finalPromise.progressDlg = undefined;

    function beginRecordingError(err) {
      finalPromiseResolver.reject(err);
    }

    // Step 0: End recording. This is necessary when the user reloads the
    // about:tracing page when we are recording. Window.onbeforeunload is not
    // reliable to end recording on reload.
    endRecording(tracingControllerClient).then(
        getCategories,
        getCategories);  // Ignore error.

    // But just in case, bind onbeforeunload anyway.
    window.onbeforeunload = function(e) {
      endRecording(tracingControllerClient);
    }

    // Step 1: Get categories.
    function getCategories() {
      tracingControllerClient.getCategories().then(
          showTracingDialog,
          beginRecordingError);
    }

    // Step 2: Show tracing dialog.
    var selectionDlg;
    function showTracingDialog(categories) {
      selectionDlg = new tr.ui.e.about_tracing.RecordSelectionDialog();
      selectionDlg.categories = categories;
      selectionDlg.settings_key =
          'tr.ui.e.about_tracing.record_selection_dialog';
      selectionDlg.addEventListener('recordclick', startTracing);
      selectionDlg.addEventListener('closeclick', cancelRecording);
      selectionDlg.visible = true;

      finalPromise.selectionDlg = selectionDlg;<commit_msg>RecordAndCaptureController did not handle errors in showTracingDialog<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2013 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.
-->

<link rel="import" href="/ui/extras/about_tracing/record_selection_dialog.html">

<script>
'use strict';

tr.exportTo('tr.ui.e.about_tracing', function() {
  function beginMonitoring(tracingControllerClient) {
    var finalPromiseResolver;
    var finalPromise = new Promise(function(resolve, reject) {
      finalPromiseResolver = {
        resolve: resolve,
        reject: reject
      };
    });

    // TODO(haraken): Implement a configure dialog to set these options.
    var monitoringOptions = {
      categoryFilter: '*',
      useSystemTracing: false,
      tracingRecordMode: 'record-until-full',
      useSampling: true
    };


    var beginMonitoringPromise = tracingControllerClient.beginMonitoring(
        monitoringOptions);

    beginMonitoringPromise.then(
        function() {
          finalPromiseResolver.resolve();
        },
        function(err) {
          finalPromiseResolver.reject(err);
        });

    return finalPromise;
  }

  function endMonitoring(tracingControllerClient) {
    var endMonitoringPromise = tracingControllerClient.endMonitoring();
    return endMonitoringPromise.then(
        function() {
        },
        function(err) {
        });
  }

  function captureMonitoring(tracingControllerClient) {
    var captureMonitoringPromise =
        tracingControllerClient.captureMonitoring();
    return captureMonitoringPromise;
  }

  function getMonitoringStatus(tracingControllerClient) {
    var getMonitoringStatusPromise =
        tracingControllerClient.getMonitoringStatus();
    return getMonitoringStatusPromise;
  }

  function beginRecording(tracingControllerClient) {
    var finalPromiseResolver;
    var finalPromise = new Promise(function(resolve, reject) {
      finalPromiseResolver = {
        resolve: resolve,
        reject: reject
      };
    });
    finalPromise.selectionDlg = undefined;
    finalPromise.progressDlg = undefined;

    function beginRecordingError(err) {
      finalPromiseResolver.reject(err);
    }

    // Step 0: End recording. This is necessary when the user reloads the
    // about:tracing page when we are recording. Window.onbeforeunload is not
    // reliable to end recording on reload.
    endRecording(tracingControllerClient).then(
        getCategories,
        getCategories);  // Ignore error.

    // But just in case, bind onbeforeunload anyway.
    window.onbeforeunload = function(e) {
      endRecording(tracingControllerClient);
    }

    // Step 1: Get categories.
    function getCategories() {
      var p = tracingControllerClient.getCategories().then(
          showTracingDialog,
          beginRecordingError);
      p.catch(function(err) {
        beginRecordingError(err);
      });
    }

    // Step 2: Show tracing dialog.
    var selectionDlg;
    function showTracingDialog(categories) {
      selectionDlg = new tr.ui.e.about_tracing.RecordSelectionDialog();
      selectionDlg.categories = categories;
      selectionDlg.settings_key =
          'tr.ui.e.about_tracing.record_selection_dialog';
      selectionDlg.addEventListener('recordclick', startTracing);
      selectionDlg.addEventListener('closeclick', cancelRecording);
      selectionDlg.visible = true;

      finalPromise.selectionDlg = selectionDlg;
{'fraction_non_alphanumeric': 0.08742375835027592, 'fraction_numerical': 0.0020331106593087424, 'mean_word_length': 3.1815421979356406, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1795249', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1796, 'n_words': 409}