#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_SERVICE_HANDLER_H_
#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_HTTP_SERVICE_HANDLER_H_
#include <compare>
#include "base/containers/flat_set.h"
#include "base/functional/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/unguessable_token.h"
#include "chrome/browser/devtools/devtools_dispatch_http_request_params.h"
#include "components/signin/public/identity_manager/access_token_fetcher.h"
#include "components/signin/public/identity_manager/scope_set.h"
#include "google_apis/gaia/google_service_auth_error.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/public/cpp/simple_url_loader.h"
class GURL;
class Profile;
namespace signin {
class AccessTokenFetcher;
struct AccessTokenInfo;
}
class DevToolsHttpServiceHandler {
public:
struct Result {
enum class Error {
kNone,
kServiceNotFound,
kAccessDenied,
kValidationFailed,
kTokenFetchFailed,
kNetworkError,
kHttpError,
};
Result();
~Result();
Result(Result&&);
Result& operator=(Result&&);
Error error = Error::kNone;
int net_error = 0;
int http_status = -1;
std::optional<std::string> response_body;
std::string error_detail;
};
using Callback = base::OnceCallback<void(std::unique_ptr<Result> result)>;
DevToolsHttpServiceHandler();
virtual ~DevToolsHttpServiceHandler();
void Request(Profile* profile,
const DevToolsDispatchHttpRequestParams& params,
Callback callback);
protected:
virtual void CanMakeRequest(Profile* profile,
base::OnceCallback<void(bool success)> callback);
private:
virtual GURL BaseURL() const = 0;
virtual signin::ScopeSet OAuthScopes() const = 0;
virtual net::NetworkTrafficAnnotationTag NetworkTrafficAnnotationTag()
const = 0;
void OnValidationDone(Callback callback,
Profile* profile,
const DevToolsDispatchHttpRequestParams& params,
bool validation_success);
void OnTokenFetched(Callback callback,
Profile* profile,
const DevToolsDispatchHttpRequestParams& params,
base::UnguessableToken fetcher_id,
GoogleServiceAuthError error,
signin::AccessTokenInfo access_token_info);
void OnRequestComplete(
Callback callback,
std::unique_ptr<network::SimpleURLLoader> simple_url_loader,
std::optional<std::string> response_body);
std::map<base::UnguessableToken, std::unique_ptr<signin::AccessTokenFetcher>>
access_token_fetchers_;
base::WeakPtrFactory<DevToolsHttpServiceHandler> weak_factory_{this};
};
#endif