Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: promisify contentTracing.getCategories() #16624

Merged
merged 1 commit into from Feb 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 14 additions & 5 deletions atom/browser/api/atom_api_content_tracing.cc
Expand Up @@ -81,11 +81,20 @@ v8::Local<v8::Promise> StopRecording(v8::Isolate* isolate,
return promise->GetHandle();
}

bool GetCategories(
const base::RepeatingCallback<void(const std::set<std::string>&)>&
callback) {
return TracingController::GetInstance()->GetCategories(
base::BindOnce(callback));
void OnCategoriesAvailable(scoped_refptr<atom::util::Promise> promise,
const std::set<std::string>& categories) {
promise->Resolve(categories);
}

v8::Local<v8::Promise> GetCategories(v8::Isolate* isolate) {
scoped_refptr<atom::util::Promise> 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<atom::util::Promise> promise) {
Expand Down
15 changes: 11 additions & 4 deletions docs/api/content-tracing.md
Expand Up @@ -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<String[]>` - 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)`

Expand Down
2 changes: 1 addition & 1 deletion docs/api/promisification.md
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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