contracts

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package contracts defines the WebKit memory optimization API contracts This file contains the expected function signatures and behavior contracts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheModel

type CacheModel int

CacheModel represents WebKit cache model options

const (
	CacheModelDocumentViewer CacheModel = iota
	CacheModelWebBrowser
	CacheModelPrimaryWebBrowser
)

type ErrInvalidMemoryConfig

type ErrInvalidMemoryConfig struct {
	Field   string
	Message string
}

ErrInvalidMemoryConfig indicates invalid memory configuration parameters

func (ErrInvalidMemoryConfig) Error

func (e ErrInvalidMemoryConfig) Error() string

type ErrMemoryLimitExceeded

type ErrMemoryLimitExceeded struct {
	Limit  int64 // bytes
	Actual int64 // bytes
}

ErrMemoryLimitExceeded indicates memory usage exceeded configured limits

func (ErrMemoryLimitExceeded) Error

func (e ErrMemoryLimitExceeded) Error() string

type ErrWebKitAPIUnavailable

type ErrWebKitAPIUnavailable struct {
	Function string
	Reason   string
}

ErrWebKitAPIUnavailable indicates WebKit memory APIs are not available

func (ErrWebKitAPIUnavailable) Error

func (e ErrWebKitAPIUnavailable) Error() string

type MemoryConfig

type MemoryConfig struct {
	MemoryLimitMB           int     `json:"memory_limit_mb"`
	ConservativeThreshold   float64 `json:"conservative_threshold"`
	StrictThreshold         float64 `json:"strict_threshold"`
	KillThreshold           float64 `json:"kill_threshold"`
	PollIntervalSeconds     float64 `json:"poll_interval_seconds"`
	CacheModel              string  `json:"cache_model"`
	EnablePageCache         bool    `json:"enable_page_cache"`
	EnableOfflineAppCache   bool    `json:"enable_offline_app_cache"`
	ProcessRecycleThreshold int     `json:"process_recycle_threshold"`
	EnableGCInterval        int     `json:"enable_gc_interval"`
	EnableMemoryMonitoring  bool    `json:"enable_memory_monitoring"`
}

MemoryConfig represents memory optimization configuration

type MemoryConfigAPI

type MemoryConfigAPI interface {
	// Configuration Validation
	ValidateMemoryConfig(config MemoryConfig) error

	// Preset Management
	GetMemoryOptimizedPreset() MemoryConfig
	GetBalancedPreset() MemoryConfig
	GetHighPerformancePreset() MemoryConfig

	// Configuration Application
	ApplyMemoryConfig(webview unsafe.Pointer, config MemoryConfig) error
}

MemoryConfigAPI defines the contract for memory configuration management

type MemoryStats

type MemoryStats struct {
	PageLoadCount             int       `json:"page_load_count"`
	LastGCTime                time.Time `json:"last_gc_time"`
	HasMemoryPressureSettings bool      `json:"has_memory_pressure_settings"`
	WebViewID                 uintptr   `json:"webview_id"`
}

MemoryStats represents WebView memory statistics

type MemoryStatsAPI

type MemoryStatsAPI interface {
	// Statistics Retrieval
	GetMemoryStats(webviewID uintptr) (MemoryStats, error)
	GetAllMemoryStats() (map[uintptr]MemoryStats, error)

	// Memory Management Operations
	TriggerMemoryCleanup(webviewID uintptr) error
	ShouldRecycleWebView(webviewID uintptr) (bool, error)

	// Monitoring Operations
	StartMemoryMonitoring(interval time.Duration) error
	StopMemoryMonitoring() error
	GetTotalMemoryUsage() (float64, error) // MB
}

MemoryStatsAPI defines the contract for memory statistics tracking

type ProcessMemoryInfo

type ProcessMemoryInfo struct {
	PID         int    `json:"pid"`
	VmRSS       int64  `json:"vm_rss"`  // KB
	VmSize      int64  `json:"vm_size"` // KB
	VmPeak      int64  `json:"vm_peak"` // KB
	ProcessName string `json:"process_name"`
}

ProcessMemoryInfo represents process memory statistics

type WebKitMemoryAPI

type WebKitMemoryAPI interface {
	// Memory Pressure Settings
	CreateMemoryPressureSettings(memoryLimitMB int, conservativeThreshold, strictThreshold, killThreshold, pollInterval float64) (unsafe.Pointer, error)
	ApplyMemoryPressureSettings(context unsafe.Pointer, settings unsafe.Pointer) error

	// Cache Model Management
	SetCacheModel(context unsafe.Pointer, model CacheModel) error
	GetCurrentCacheModel(context unsafe.Pointer) (CacheModel, error)

	// JavaScript Garbage Collection
	TriggerJavaScriptGC(context unsafe.Pointer) error

	// WebView Settings
	SetPageCacheEnabled(settings unsafe.Pointer, enabled bool) error
	SetOfflineAppCacheEnabled(settings unsafe.Pointer, enabled bool) error

	// Memory Monitoring
	GetProcessMemoryInfo(pid int) (ProcessMemoryInfo, error)
	ListWebKitProcesses() ([]ProcessMemoryInfo, error)
}

WebKitMemoryAPI defines the contract for WebKit memory management functions

type WebViewLifecycleAPI

type WebViewLifecycleAPI interface {
	// WebView Registration
	RegisterWebView(webviewID uintptr, config MemoryConfig) error
	UnregisterWebView(webviewID uintptr) error

	// Lifecycle Events
	OnPageLoad(webviewID uintptr, url string) error
	OnMemoryPressure(webviewID uintptr, pressureLevel int) error
	OnGarbageCollection(webviewID uintptr) error

	// Recycling Operations
	ShouldRecycleWebView(webviewID uintptr) bool
	RequestWebViewRecycling(webviewID uintptr) error
}

WebViewLifecycleAPI defines the contract for WebView lifecycle management

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL