#include "components/safe_search_api/safe_search/safe_search_url_checker_client.h"
#include <optional>
#include <utility>
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/escape.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/google/core/common/google_util.h"
#include "net/base/load_flags.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "url/url_constants.h"
namespace safe_search_api {
namespace {
const char kSafeSearchApiUrl[] = …;
const char kDataContentType[] = …;
const char kDataFormat[] = …;
std::string BuildRequestData(const std::string& api_key, const GURL& url) { … }
bool ParseResponse(const std::string& response, bool* is_porn) { … }
}
struct SafeSearchURLCheckerClient::Check { … };
SafeSearchURLCheckerClient::Check::Check(
const GURL& url,
std::unique_ptr<network::SimpleURLLoader> simple_url_loader,
ClientCheckCallback callback)
: … { … }
SafeSearchURLCheckerClient::Check::~Check() = default;
SafeSearchURLCheckerClient::SafeSearchURLCheckerClient(
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
const net::NetworkTrafficAnnotationTag& traffic_annotation,
const std::string& api_key)
: … { … }
SafeSearchURLCheckerClient::~SafeSearchURLCheckerClient() = default;
void SafeSearchURLCheckerClient::CheckURL(const GURL& url,
ClientCheckCallback callback) { … }
void SafeSearchURLCheckerClient::OnSimpleLoaderComplete(
CheckList::iterator it,
std::unique_ptr<std::string> response_body) { … }
}