diff --git a/atom/browser/api/atom_api_content_tracing.cc b/atom/browser/api/atom_api_content_tracing.cc index 46eb1cac2c2d6..409725c67e641 100644 --- a/atom/browser/api/atom_api_content_tracing.cc +++ b/atom/browser/api/atom_api_content_tracing.cc @@ -8,6 +8,7 @@ #include "atom/common/native_mate_converters/callback.h" #include "atom/common/native_mate_converters/file_path_converter.h" #include "atom/common/native_mate_converters/value_converter.h" +#include "atom/common/promise_util.h" #include "base/bind.h" #include "base/files/file_util.h" #include "content/public/browser/tracing_controller.h" @@ -71,11 +72,20 @@ void StopRecording(const base::FilePath& path, GetTraceDataEndpoint(path, callback)); } -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(); } bool StartTracing(const base::trace_event::TraceConfig& trace_config, diff --git a/docs/api/content-tracing.md b/docs/api/content-tracing.md index 6d1729689b02b..fb11da1ab7619 100644 --- a/docs/api/content-tracing.md +++ b/docs/api/content-tracing.md @@ -43,11 +43,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 1e79b55eb62de..1a61013c2c604 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.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) - [contentTracing.getTraceBufferUsage(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getTraceBufferUsage) @@ -53,6 +52,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) - [shell.openExternal(url[, options, callback])](https://github.com/electron/electron/blob/master/docs/api/shell.md#openExternal) - [protocol.isProtocolHandled(scheme, callback)](https://github.com/electron/electron/blob/master/docs/api/protocol.md#isProtocolHandled) - [desktopCapturer.getSources(options, callback)](https://github.com/electron/electron/blob/master/docs/api/desktop-capturer.md#getSources) \ No newline at end of file diff --git a/lib/browser/api/content-tracing.js b/lib/browser/api/content-tracing.js index 81bd70f1ebbfb..5558451f03daa 100644 --- a/lib/browser/api/content-tracing.js +++ b/lib/browser/api/content-tracing.js @@ -1,3 +1,7 @@ 'use strict' +const { deprecate } = require('electron') +const contentTracing = process.atomBinding('content_tracing') -module.exports = process.atomBinding('content_tracing') +contentTracing.getCategories = deprecate.promisify(contentTracing.getCategories) + +module.exports = contentTracing