Skip to content

CefTaskManager

Header: cef_task_manager.h
Category: System Utilities

Overview

Tasks, threads, parsers, streams, cookies, URL requests, scheme registration, and constant tables.

CefTaskManager

Source File: include/cef_task_manager.h

Process / Thread Context: Browser Process / UI Thread only. Every method (including the static accessor) returns a safe default (nullptr / 0 / false) if called from the wrong thread.

Purpose: Library-provided singleton that exposes the Chromium task/process manager: enumeration of currently running browser-related tasks (processes), retrieval of per-task info (CefTaskInfo), termination of tasks, and mapping a CefBrowser identifier to its associated main task.

Methods

static CefRefPtr<CefTaskManager> GetTaskManager()

Parameters:

  • None.

Return Value: The global task manager, or nullptr if called from a non-UI thread.

Usage Instruction: Cache the result on the UI thread; never call off-thread.

Threading Constraint: UI thread.

virtual size_t GetTasksCount()

Parameters:

  • None.

Return Value: Number of tasks currently tracked by the task manager; 0 if called from the wrong thread.

Usage Instruction: Use to pre-size containers before GetTaskIdsList.

Threading Constraint: UI thread.

virtual bool GetTaskIdsList(TaskIdList& task_ids)

Parameters:

  • task_ids — output vector that will be cleared and populated with all task IDs.

Return Value: false if called from the wrong thread; otherwise true. The list is sorted to reflect the process tree: browser process first, then GPU process (if any), then related processes kept together where possible. Task IDs are unique over the application lifespan.

Usage Instruction: Iterate the returned IDs and call GetTaskInfo for each.

Threading Constraint: UI thread.

virtual bool GetTaskInfo(int64_t task_id, CefTaskInfo& info)

Parameters:

  • task_id — task ID from GetTaskIdsList or GetTaskIdForBrowserId. info — output CefTaskInfo struct populated with task information.

Return Value: true if the info was retrieved; false if task_id is invalid or the wrong thread was used.

Usage Instruction: The struct definition lives in cef_types.h; consult that header for available fields.

Threading Constraint: UI thread.

virtual bool KillTask(int64_t task_id)

Parameters:

  • task_id — task ID to terminate.

Return Value: false if task_id is invalid, the call is from the wrong thread, or the task cannot be terminated; true on success.

Usage Instruction: Use carefully; terminating the browser or GPU process will crash the application.

Threading Constraint: UI thread.

virtual int64_t GetTaskIdForBrowserId(int browser_id)

Parameters:

  • browser_id — value from CefBrowser::GetIdentifier().

Return Value: The task ID associated with the browser's main task, or -1 if browser_id is invalid, has no associated task, or the wrong thread was used.

Usage Instruction: Bridge from a CefBrowser instance to its underlying renderer-process task for diagnostics/termination.

Threading Constraint: UI thread.

Usage Example

cpp
// Build a "Chromium-style" task list view, UI thread only.
CefRefPtr<CefTaskManager> tm = CefTaskManager::GetTaskManager();
if (tm) {
  CefTaskManager::TaskIdList ids;
  if (tm->GetTaskIdsList(ids)) {
    for (int64_t id : ids) {
      CefTaskInfo info;
      if (tm->GetTaskInfo(id, info)) {
        DLOG(INFO) << "Task " << id << " title=" << info.title
                   << " pid=" << info.pid;
      }
    }
  }
}

// Bridge from a browser to its renderer task.
int64_t renderer_task = tm->GetTaskIdForBrowserId(browser->GetIdentifier());
if (renderer_task != -1 && user_clicked_kill) {
  tm->KillTask(renderer_task);
}

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.