#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "services/network/slop_bucket.h"
#include <limits.h>
#include <string.h>
#include <algorithm>
#include <ostream>
#include "base/containers/heap_array.h"
#include "base/containers/queue.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/no_destructor.h"
#include "base/sequence_checker.h"
#include "base/synchronization/atomic_flag.h"
#include "base/system/sys_info.h"
#include "base/thread_annotations.h"
#include "base/types/pass_key.h"
#include "net/base/io_buffer.h"
#include "net/base/request_priority.h"
#include "net/url_request/url_request.h"
#include "url/gurl.h"
namespace network {
BASE_FEATURE(…);
namespace {
constexpr net::RequestPriority kDefaultRequirePriority = …;
constexpr int kDefaultChunkSize = …;
constexpr int kDefaultMinBufferSize = …;
constexpr int kDefaultMaxChunksPerRequest = …;
constexpr int kDefaultMaxChunksTotal = …;
constexpr base::MemoryPressureListener::MemoryPressureLevel
kDefaultMemoryPressureDisableLevel = …;
constexpr base::FeatureParam<net::RequestPriority>::Option
kRequestPriorityOptions[] = …;
constexpr base::FeatureParam<net::RequestPriority> kRequirePriorityParam(
&kSlopBucket,
"require_priority",
net::MEDIUM,
&kRequestPriorityOptions);
constexpr base::FeatureParam<int> kChunkSizeParam(&kSlopBucket,
"chunk_size",
kDefaultChunkSize);
constexpr base::FeatureParam<int> kMinBufferSizeParam(&kSlopBucket,
"min_buffer_size",
kDefaultMinBufferSize);
constexpr base::FeatureParam<int> kMaxChunksPerRequestParam(
&kSlopBucket,
"max_chunks_per_request",
kDefaultMaxChunksPerRequest);
constexpr base::FeatureParam<int> kMaxChunksTotalParam(&kSlopBucket,
"max_chunks_total",
kDefaultMaxChunksTotal);
constexpr base::FeatureParam<
base::MemoryPressureListener::MemoryPressureLevel>::Option
kMemoryPressureLevelOptions[] = …;
constexpr base::FeatureParam<base::MemoryPressureListener::MemoryPressureLevel>
kMemoryPressureDisableLevelParam(
&kSlopBucket,
"memory_pressure_disable_level",
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE,
&kMemoryPressureLevelOptions);
}
class SlopBucket::Configuration { … };
class SlopBucket::Manager { … };
class SlopBucket::ChunkIOBuffer final : public net::IOBuffer { … };
std::unique_ptr<SlopBucket> SlopBucket::RequestSlopBucket(
net::URLRequest* for_request) { … }
SlopBucket::SlopBucket(PassKey, net::URLRequest* request) : … { … }
SlopBucket::~SlopBucket() { … }
std::optional<int> SlopBucket::AttemptRead() { … }
void SlopBucket::OnReadCompleted(int bytes_read) { … }
size_t SlopBucket::Consume(void* buffer, size_t max) { … }
size_t SlopBucket::ConsumeSlowPath(void* buffer, size_t max) { … }
bool SlopBucket::TryToAllocateChunk() { … }
}