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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_ASH_COMPONENTS_DBUS_RESOURCED_FAKE_RESOURCED_CLIENT_H_
#define CHROMEOS_ASH_COMPONENTS_DBUS_RESOURCED_FAKE_RESOURCED_CLIENT_H_
#include "base/component_export.h"
#include "base/observer_list.h"
#include "base/time/time.h"
#include "chromeos/ash/components/dbus/resourced/resourced_client.h"
namespace ash {
class COMPONENT_EXPORT(RESOURCED) FakeResourcedClient : public ResourcedClient {
public:
FakeResourcedClient();
~FakeResourcedClient() override;
FakeResourcedClient(const FakeResourcedClient&) = delete;
FakeResourcedClient& operator=(const FakeResourcedClient&) = delete;
struct SetThreadStateRequest {
base::ProcessId process_id;
base::PlatformThreadId thread_id;
resource_manager::ThreadState state;
};
// ResourcedClient:
void SetGameModeWithTimeout(
GameMode game_mode,
uint32_t refresh_seconds,
chromeos::DBusMethodCallback<GameMode> callback) override;
void SetMemoryMargins(MemoryMargins margins) override;
void ReportBrowserProcesses(const std::vector<Process>& processes) override;
void SetProcessState(base::ProcessId,
resource_manager::ProcessState,
SetQoSStateCallback) override;
void SetThreadState(base::ProcessId,
base::PlatformThreadId,
resource_manager::ThreadState,
SetQoSStateCallback) override;
void set_total_system_memory(uint64_t mem_kb) {
total_system_memory_kb_ = mem_kb;
}
void set_set_game_mode_response(std::optional<GameMode> response) {
set_game_mode_response_ = response;
}
void set_set_game_mode_with_timeout_response(
std::optional<GameMode> response) {
previous_game_mode_state_ = response;
}
int get_enter_game_mode_count() const { return enter_game_mode_count_; }
int get_exit_game_mode_count() const { return exit_game_mode_count_; }
uint32_t get_moderate_margin_bps() const { return moderate_margin_bps_; }
uint32_t get_critical_margin_bps() const { return critical_margin_bps_; }
uint32_t get_critical_protected_margin_bps() const {
return critical_protected_margin_bps_;
}
std::vector<int32_t> get_ash_background_pids() {
return ash_background_pids_;
}
std::vector<int32_t> get_lacros_background_pids() {
return lacros_background_pids_;
}
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
void WaitForServiceToBeAvailable(
dbus::ObjectProxy::WaitForServiceToBeAvailableCallback callback) override;
void AddArcContainerObserver(ArcContainerObserver* observer) override;
void RemoveArcContainerObserver(ArcContainerObserver* observer) override;
// Unblock registered WaitForServiceToBeAvailable() calls.
//
// Return `true` if at least 1 WaitForServiceToBeAvailable() has been
// called.
bool TriggerServiceAvailable(bool available);
// Return the list of process states that have been requested via
// SetProcessState().
const std::vector<std::pair<base::ProcessId, resource_manager::ProcessState>>&
GetProcessStateHistory() const;
// Return the list of thread states that have been requested via
// SetThreadState().
const std::vector<SetThreadStateRequest>& GetThreadStateHistory() const;
// Set response for next SetProcessState() calls.
void SetProcessStateResult(dbus::DBusResult);
// Set response for next SetThreadState() calls.
void SetThreadStateResult(dbus::DBusResult);
// Delays the response of the next SetProcessStateResult calls.
void DelaySetProcessStateResult(base::TimeDelta);
// Delays the response of the next SetThreadStateResult calls.
void DelaySetThreadStateResult(base::TimeDelta);
private:
std::optional<GameMode> set_game_mode_response_;
std::optional<GameMode> previous_game_mode_state_ = GameMode::OFF;
int enter_game_mode_count_ = 0;
int exit_game_mode_count_ = 0;
uint64_t total_system_memory_kb_ = 1000 * 1000; /* 1 gb */
uint32_t moderate_margin_bps_ = 4000;
uint32_t critical_margin_bps_ = 520;
uint32_t critical_protected_margin_bps_ = 520;
std::vector<int32_t> ash_background_pids_;
std::vector<int32_t> lacros_background_pids_;
std::vector<Process> ash_browser_processes_;
std::vector<Process> lacros_browser_processes_;
std::vector<dbus::ObjectProxy::WaitForServiceToBeAvailableCallback>
pending_service_available_;
std::vector<std::pair<base::ProcessId, resource_manager::ProcessState>>
process_state_history_;
std::vector<SetThreadStateRequest> thread_state_history_;
dbus::DBusResult set_process_state_result_ = dbus::DBusResult::kSuccess;
dbus::DBusResult set_thread_state_result_ = dbus::DBusResult::kSuccess;
base::TimeDelta set_process_state_delay_;
base::TimeDelta set_thread_state_delay_;
base::ObserverList<Observer> observers_;
base::ObserverList<ArcContainerObserver> arc_container_observers_;
};
} // namespace ash
#endif // CHROMEOS_ASH_COMPONENTS_DBUS_RESOURCED_FAKE_RESOURCED_CLIENT_H_
|