#ifndef CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
#define CHROMEOS_PROCESS_PROXY_PROCESS_PROXY_REGISTRY_H_
#include <map>
#include <memory>
#include <string>
#include "base/command_line.h"
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h"
#include "base/task/sequenced_task_runner.h"
#include "base/threading/thread.h"
#include "chromeos/process_proxy/process_proxy.h"
namespace chromeos {
class COMPONENT_EXPORT(CHROMEOS_PROCESS_PROXY) ProcessProxyRegistry {
public:
using OutputCallback =
base::RepeatingCallback<void(const std::string& id,
const std::string& output_type,
const std::string& output_data)>;
struct ProcessProxyInfo {
scoped_refptr<ProcessProxy> proxy;
OutputCallback callback;
ProcessProxyInfo();
ProcessProxyInfo(const ProcessProxyInfo& other);
~ProcessProxyInfo();
};
static ProcessProxyRegistry* Get();
ProcessProxyRegistry(const ProcessProxyRegistry&) = delete;
ProcessProxyRegistry& operator=(const ProcessProxyRegistry&) = delete;
static int ConvertToSystemPID(const std::string& id);
static scoped_refptr<base::SequencedTaskRunner> GetTaskRunner();
bool OpenProcess(const base::CommandLine& cmdline,
const std::string& user_id_hash,
const OutputCallback& callback,
std::string* id);
void SendInput(const std::string& id,
const std::string& data,
base::OnceCallback<void(bool)> callback);
bool CloseProcess(const std::string& id);
bool OnTerminalResize(const std::string& id, int width, int height);
void AckOutput(const std::string& id);
void ShutDown();
const base::Process* GetProcessForTesting(const std::string& id);
private:
friend struct ::base::LazyInstanceTraitsBase<ProcessProxyRegistry>;
ProcessProxyRegistry();
~ProcessProxyRegistry();
void OnProcessOutput(const std::string& id,
ProcessOutputType type,
const std::string& data);
bool EnsureWatcherThreadStarted();
std::map<std::string, ProcessProxyInfo> proxy_map_;
std::unique_ptr<base::Thread> watcher_thread_;
SEQUENCE_CHECKER(sequence_checker_);
};
}
#endif