#pragma once
#include <wtf/HashMap.h>
#include <wtf/RunLoop.h>
#include <wtf/text/WTFString.h>
namespace WebKit {
class WebProcessPool;
class WebProcessProxy;
class WebsiteDataStore;
class WebProcessCache {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit WebProcessCache(WebProcessPool&);
bool addProcessIfPossible(const String& registrableDomain, Ref<WebProcessProxy>&&);
RefPtr<WebProcessProxy> takeProcess(const String& registrableDomain, WebsiteDataStore&);
void updateCapacity(WebProcessPool&);
unsigned capacity() const { return m_capacity; }
unsigned size() const { return m_processesPerRegistrableDomain.size(); }
void setIsDisabled(bool isDisabled) { m_isDisabled = isDisabled; }
void clear();
void setApplicationIsActive(bool);
enum class ShouldShutDownProcess { No, Yes };
void removeProcess(WebProcessProxy&, ShouldShutDownProcess);
private:
static Seconds cachedProcessLifetime;
static Seconds clearingDelayAfterApplicationResignsActive;
class CachedProcess {
WTF_MAKE_FAST_ALLOCATED;
public:
CachedProcess(Ref<WebProcessProxy>&&);
~CachedProcess();
Ref<WebProcessProxy> takeProcess();
WebProcessProxy& process() { ASSERT(m_process); return *m_process; }
private:
void evictionTimerFired();
RefPtr<WebProcessProxy> m_process;
RunLoop::Timer<CachedProcess> m_evictionTimer;
};
bool canCacheProcess(WebProcessProxy&) const;
void platformInitialize();
bool addProcess(std::unique_ptr<CachedProcess>&&);
unsigned m_capacity { 0 };
bool m_isDisabled { false };
HashMap<uint64_t, std::unique_ptr<CachedProcess>> m_pendingAddRequests;
HashMap<String, std::unique_ptr<CachedProcess>> m_processesPerRegistrableDomain;
RunLoop::Timer<WebProcessCache> m_evictionTimer;
};
}