From 7c83937488374e2b55bca7b6758996f22d296f2b Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 30 Jan 2019 12:39:55 -0800 Subject: [PATCH] feat: promisify contentTracing.getCategories() (#16583) * feat: promisify contentTracing.getCategories() * deprecate contentTracing/getCategories --- atom/browser/api/atom_api_content_tracing.cc | 19 ++++++++++++++----- docs/api/content-tracing.md | 15 +++++++++++---- docs/api/promisification.md | 2 +- lib/browser/api/content-tracing.js | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/atom/browser/api/atom_api_content_tracing.cc b/atom/browser/api/atom_api_content_tracing.cc index dcabedfe60416..7de217beb1fe2 100644 --- a/atom/browser/api/atom_api_content_tracing.cc +++ b/atom/browser/api/atom_api_content_tracing.cc @@ -81,11 +81,20 @@ v8::Local StopRecording(v8::Isolate* isolate, return promise->GetHandle(); } -bool GetCategories( - const base::RepeatingCallback&)>& - callback) { - return TracingController::GetInstance()->GetCategories( - base::BindOnce(callback)); +void OnCategoriesAvailable(scoped_refptr promise, + const std::set& categories) { + promise->Resolve(categories); +} + +v8::Local GetCategories(v8::Isolate* isolate) { + scoped_refptr promise = new atom::util::Promise(isolate); + bool success = TracingController::GetInstance()->GetCategories( + base::BindOnce(&OnCategoriesAvailable, promise)); + + if (!success) + promise->RejectWithErrorMessage("Could not get categories."); + + return promise->GetHandle(); } void OnTracingStarted(scoped_refptr promise) { diff --git a/docs/api/content-tracing.md b/docs/api/content-tracing.md index ac07711bb73fd..5fb78ed6793f8 100644 --- a/docs/api/content-tracing.md +++ b/docs/api/content-tracing.md @@ -42,11 +42,18 @@ The `contentTracing` module has the following methods: * `callback` Function * `categories` String[] -Get a set of category groups. The category groups can change as new code paths -are reached. +Get a set of category groups. The category groups can change as new code paths are reached. + +Once all child processes have acknowledged the `getCategories` request the `callback` is invoked with an array of category groups. + +**[Deprecated Soon](promisification.md)** + +### `contentTracing.getCategories()` + +Returns `Promise` - resolves with an array of category groups once all child processes have acknowledged the `getCategories` request + +Get a set of category groups. The category groups can change as new code paths are reached. -Once all child processes have acknowledged the `getCategories` request the -`callback` is invoked with an array of category groups. ### `contentTracing.startRecording(options, callback)` diff --git a/docs/api/promisification.md b/docs/api/promisification.md index c54624f23afb0..e6fce6628107b 100644 --- a/docs/api/promisification.md +++ b/docs/api/promisification.md @@ -11,7 +11,6 @@ When a majority of affected functions are migrated, this flag will be enabled by - [app.importCertificate(options, callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#importCertificate) - [request.write(chunk[, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#write) - [request.end([chunk][, encoding][, callback])](https://github.com/electron/electron/blob/master/docs/api/client-request.md#end) -- [contentTracing.getCategories(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getCategories) - [contentTracing.getTraceBufferUsage(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getTraceBufferUsage) - [cookies.get(filter, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#get) - [cookies.set(details, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#set) @@ -51,6 +50,7 @@ When a majority of affected functions are migrated, this flag will be enabled by - [webviewTag.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/webview-tag.md#capturePage) - [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage) - [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon) +- [contentTracing.getCategories(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getCategories) - [contentTracing.startRecording(options, callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#startRecording) - [contentTracing.stopRecording(resultFilePath, callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#stopRecording) - [desktopCapturer.getSources(options, callback)](https://github.com/electron/electron/blob/master/docs/api/desktop-capturer.md#getSources) diff --git a/lib/browser/api/content-tracing.js b/lib/browser/api/content-tracing.js index 931ec2ce30810..9a4f480d83c55 100644 --- a/lib/browser/api/content-tracing.js +++ b/lib/browser/api/content-tracing.js @@ -1,9 +1,9 @@ 'use strict' - const { deprecate } = require('electron') const contentTracing = process.atomBinding('content_tracing') contentTracing.startRecording = deprecate.promisify(contentTracing.startRecording) contentTracing.stopRecording = deprecate.promisify(contentTracing.stopRecording) +contentTracing.getCategories = deprecate.promisify(contentTracing.getCategories) module.exports = contentTracing