feat: promisify contentTracing.getCategories() (#16583)
* feat: promisify contentTracing.getCategories() * deprecate contentTracing/getCategories
This commit is contained in:
parent
9ed89ace97
commit
641b47f384
4 changed files with 32 additions and 11 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/value_converter.h"
|
#include "atom/common/native_mate_converters/value_converter.h"
|
||||||
|
#include "atom/common/promise_util.h"
|
||||||
#include "base/bind.h"
|
#include "base/bind.h"
|
||||||
#include "base/files/file_util.h"
|
#include "base/files/file_util.h"
|
||||||
#include "content/public/browser/tracing_controller.h"
|
#include "content/public/browser/tracing_controller.h"
|
||||||
|
@ -71,11 +72,20 @@ void StopRecording(const base::FilePath& path,
|
||||||
GetTraceDataEndpoint(path, callback));
|
GetTraceDataEndpoint(path, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetCategories(
|
void OnCategoriesAvailable(scoped_refptr<atom::util::Promise> promise,
|
||||||
const base::RepeatingCallback<void(const std::set<std::string>&)>&
|
const std::set<std::string>& categories) {
|
||||||
callback) {
|
promise->Resolve(categories);
|
||||||
return TracingController::GetInstance()->GetCategories(
|
}
|
||||||
base::BindOnce(callback));
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StartTracing(const base::trace_event::TraceConfig& trace_config,
|
bool StartTracing(const base::trace_event::TraceConfig& trace_config,
|
||||||
|
|
|
@ -43,11 +43,18 @@ The `contentTracing` module has the following methods:
|
||||||
* `callback` Function
|
* `callback` Function
|
||||||
* `categories` String[]
|
* `categories` String[]
|
||||||
|
|
||||||
Get a set of category groups. The category groups can change as new code paths
|
Get a set of category groups. The category groups can change as new code paths are reached.
|
||||||
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)`
|
### `contentTracing.startRecording(options, callback)`
|
||||||
|
|
||||||
|
|
|
@ -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)
|
- [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.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)
|
- [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.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.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)
|
- [contentTracing.getTraceBufferUsage(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getTraceBufferUsage)
|
||||||
|
@ -45,6 +44,7 @@ When a majority of affected functions are migrated, this flag will be enabled by
|
||||||
|
|
||||||
- [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
|
- [app.getFileIcon(path[, options], callback)](https://github.com/electron/electron/blob/master/docs/api/app.md#getFileIcon)
|
||||||
- [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
|
- [contents.capturePage([rect, ]callback)](https://github.com/electron/electron/blob/master/docs/api/web-contents.md#capturePage)
|
||||||
|
- [contentTracing.getCategories(callback)](https://github.com/electron/electron/blob/master/docs/api/content-tracing.md#getCategories)
|
||||||
- [cookies.flushStore(callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#flushStore)
|
- [cookies.flushStore(callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#flushStore)
|
||||||
- [cookies.get(filter, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#get)
|
- [cookies.get(filter, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#get)
|
||||||
- [cookies.remove(url, name, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#remove)
|
- [cookies.remove(url, name, callback)](https://github.com/electron/electron/blob/master/docs/api/cookies.md#remove)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
'use strict'
|
'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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue