#include "components/spellcheck/browser/spelling_service_client.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/string_escape.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/values.h"
#include "components/prefs/pref_service.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/spellcheck/common/spellcheck_common.h"
#include "components/spellcheck/common/spellcheck_result.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "google_apis/google_api_keys.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 "services/network/public/mojom/url_response_head.mojom.h"
#include "url/gurl.h"
namespace {
const char kSpellingServiceRestURL[] = …;
const char kMisspellingsRestPath[] = …;
const char kErrorPath[] = …;
const char* const kValidLanguages[] = …;
}
SpellingServiceClient::SpellingServiceClient() = default;
SpellingServiceClient::~SpellingServiceClient() = default;
bool SpellingServiceClient::RequestTextCheck(
content::BrowserContext* context,
ServiceType type,
const std::u16string& text,
TextCheckCompleteCallback callback) { … }
bool SpellingServiceClient::IsAvailable(content::BrowserContext* context,
ServiceType type) { … }
void SpellingServiceClient::SetURLLoaderFactoryForTesting(
scoped_refptr<network::SharedURLLoaderFactory>
url_loader_factory_for_testing) { … }
GURL SpellingServiceClient::BuildEndpointUrl(int type) { … }
bool SpellingServiceClient::ParseResponse(
const std::string& data,
std::vector<SpellCheckResult>* results) { … }
SpellingServiceClient::TextCheckCallbackData::TextCheckCallbackData(
std::unique_ptr<network::SimpleURLLoader> simple_url_loader,
TextCheckCompleteCallback callback,
std::u16string text)
: … { … }
SpellingServiceClient::TextCheckCallbackData::~TextCheckCallbackData() { … }
void SpellingServiceClient::OnSimpleLoaderComplete(
SpellCheckLoaderList::iterator it,
base::TimeTicks request_start,
std::unique_ptr<std::string> response_body) { … }