#ifndef SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_
#define SERVICES_NETWORK_WEBSOCKET_INTERCEPTOR_H_
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/unguessable_token.h"
#include "services/network/throttling/scoped_throttling_token.h"
#include "services/network/throttling/throttling_network_interceptor.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace network {
class COMPONENT_EXPORT(NETWORK_SERVICE) WebSocketInterceptor {
public:
enum FrameDirection {
kIncoming,
kOutgoing,
};
WebSocketInterceptor(
uint32_t net_log_source_id,
const absl::optional<base::UnguessableToken>& throttling_profile_id);
virtual ~WebSocketInterceptor();
enum InterceptResult {
kContinue,
kShouldWait,
};
InterceptResult Intercept(FrameDirection direction,
size_t size,
base::OnceClosure retry_callback);
private:
void ThrottleCallback(FrameDirection direction, int result, int64_t bytes);
ThrottlingNetworkInterceptor::ThrottleCallback throttle_callbacks_[2];
const uint32_t net_log_source_id_;
const std::unique_ptr<ScopedThrottlingToken> throttling_token_;
base::OnceClosure pending_callbacks_[2];
};
}
#endif