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
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERFORMANCE_MANAGER_GRAPH_POLICIES_PROCESS_PRIORITY_POLICY_H_
#define COMPONENTS_PERFORMANCE_MANAGER_GRAPH_POLICIES_PROCESS_PRIORITY_POLICY_H_
#include "base/functional/callback.h"
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/process_node.h"
#include "components/performance_manager/public/render_process_host_proxy.h"
namespace performance_manager {
namespace policies {
// Policy that observes priority changes on ProcessNodes, and applies these
// to the actual processes via RenderProcessHost::SetPriorityOverride. There
// is no need for more than one of these to be instantiated at a time (enforced
// by a DCHECK). This policy expects to be attached to an empty graph (also
// enforced by a DCHECK).
class ProcessPriorityPolicy : public GraphOwned, public ProcessNodeObserver {
public:
using SetPriorityOnUiThreadCallback =
base::RepeatingCallback<void(RenderProcessHostProxy rph_proxy,
base::Process::Priority priority)>;
ProcessPriorityPolicy();
ProcessPriorityPolicy(const ProcessPriorityPolicy&) = delete;
ProcessPriorityPolicy(ProcessPriorityPolicy&&) = delete;
ProcessPriorityPolicy& operator=(const ProcessPriorityPolicy&) = delete;
ProcessPriorityPolicy& operator=(ProcessPriorityPolicy&&) = delete;
~ProcessPriorityPolicy() override;
// Testing seams. This allows testing this class without requiring a full
// browser test.
static void SetCallbackForTesting(SetPriorityOnUiThreadCallback callback);
static void ClearCallbackForTesting();
private:
// GraphOwned implementation:
void OnPassedToGraph(Graph* graph) override;
void OnTakenFromGraph(Graph* graph) override;
// ProcessNodeObserver implementation:
void OnProcessNodeAdded(const ProcessNode* process_node) override;
void OnPriorityChanged(const ProcessNode* process_node,
base::TaskPriority previous_value) override;
};
} // namespace policies
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_GRAPH_POLICIES_PROCESS_PRIORITY_POLICY_H_
|