File: task_provider.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (81 lines) | stat: -rw-r--r-- 3,448 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_TASK_PROVIDER_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_TASK_PROVIDER_H_

#include "base/memory/raw_ptr.h"
#include "chrome/browser/task_manager/providers/task_provider_observer.h"

namespace task_manager {

// Defines the interface for task providers. A concrete task provider must be
// able to collect all the tasks of a particular type which this provider
// supports as well as track any tasks addition / removal. Once StartUpdating()
// is called, the provider is responsible for notifying the observer about the
// tasks it's tracking. The TaskProviders own the tasks they provide.
class TaskProvider {
 public:
  TaskProvider();
  TaskProvider(const TaskProvider&) = delete;
  TaskProvider& operator=(const TaskProvider&) = delete;
  virtual ~TaskProvider();

  // Should return the task associated to the specified IDs from a
  // |content::ResourceRequestInfo| that represents a |URLRequest|. A value of
  // nullptr will be returned if the desired task does not belong to this
  // provider.
  //
  // |child_id| is the unique ID of the host of the child process requestor.
  // |route_id| is the ID of the IPC route for the URLRequest (this identifies
  // the RenderFrame in the renderer that initiated the request). |route_id|
  // may be ignored if |child_id| is not a renderer process.
  virtual Task* GetTaskOfUrlRequest(int child_id, int route_id) = 0;

  // Set the sole observer of this provider. It's an error to set an observer
  // if there's already one there.
  void SetObserver(TaskProviderObserver* observer);

  // Clears the currently set observer for this provider. It's an error to clear
  // the observer if there's no one set.
  void ClearObserver();

 protected:
  // Indicates if this instance is currently tracking tasks. Will return true
  // between the calls to StartUpdating() and StopUpdating().
  bool IsUpdating() const;

  // Used by concrete task providers to notify the observer of tasks addition/
  // removal/renderer unresponsive. These methods should only be called after
  // StartUpdating() has been called and before StopUpdating() is called.
  void NotifyObserverTaskAdded(Task* task) const;
  void NotifyObserverTaskRemoved(Task* task) const;
  void NotifyObserverTaskUnresponsive(Task* task) const;
  void UpdateTaskProcessInfoAndNotifyObserver(
      Task* existing_task,
      base::ProcessHandle new_process_handle,
      base::ProcessId new_process_id) const;
#if BUILDFLAG(IS_CHROMEOS)
  void NotifyObserverTaskIdsListToBeInvalidated() const;
#endif

 private:
  // This will be called once an observer is set for this provider. When it is
  // called, the concrete provider must notify the observer of all pre-existing
  // tasks as well as track new addition and terminations and notify the
  // observer of these changes.
  virtual void StartUpdating() = 0;

  // This will be called once the observer is cleared, at which point the
  // provider can stop tracking tasks addition / removal and can clear its own
  // resources.
  virtual void StopUpdating() = 0;

  // We support only one single obsever which will be the sampler in this case.
  raw_ptr<TaskProviderObserver> observer_;
};

}  // namespace task_manager

#endif  // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_TASK_PROVIDER_H_