#include "chrome/browser/spellchecker/spellcheck_custom_dictionary.h"
#include <stddef.h>
#include <algorithm>
#include <functional>
#include <sstream>
#include <utility>
#include <vector>
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/files/important_file_writer.h"
#include "base/functional/bind.h"
#include "base/hash/md5.h"
#include "base/observer_list.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "chrome/common/chrome_constants.h"
#include "components/spellcheck/browser/spellcheck_host_metrics.h"
#include "components/spellcheck/common/spellcheck_common.h"
#include "components/sync/model/sync_change.h"
#include "components/sync/model/sync_change_processor.h"
#include "components/sync/protocol/dictionary_specifics.pb.h"
#include "components/sync/protocol/entity_specifics.pb.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
BrowserThread;
namespace {
const base::FilePath::CharType BACKUP_EXTENSION[] = …);
const char CHECKSUM_PREFIX[] = …;
enum ChecksumStatus { … };
enum ChangeSanitationResult { … };
ChecksumStatus LoadFile(const base::FilePath& file_path,
std::set<std::string>* words) { … }
bool IsValidWord(const std::string& word) { … }
int SanitizeWordsToAdd(const std::set<std::string>& existing,
std::set<std::string>* to_add) { … }
std::unique_ptr<SpellcheckCustomDictionary::LoadFileResult>
LoadDictionaryFileReliably(const base::FilePath& path) { … }
void SaveDictionaryFileReliably(const base::FilePath& path,
const std::set<std::string>& custom_words) { … }
void SavePassedWordsToDictionaryFileReliably(
const base::FilePath& path,
std::unique_ptr<SpellcheckCustomDictionary::LoadFileResult>
load_file_result) { … }
int SanitizeWordsToRemove(const std::set<std::string>& existing,
std::set<std::string>* to_remove) { … }
}
SpellcheckCustomDictionary::Change::Change() { … }
SpellcheckCustomDictionary::Change::~Change() { … }
void SpellcheckCustomDictionary::Change::AddWord(const std::string& word) { … }
void SpellcheckCustomDictionary::Change::AddWords(
const std::set<std::string>& words) { … }
void SpellcheckCustomDictionary::Change::RemoveWord(const std::string& word) { … }
void SpellcheckCustomDictionary::Change::Clear() { … }
int SpellcheckCustomDictionary::Change::Sanitize(
const std::set<std::string>& words) { … }
SpellcheckCustomDictionary::SpellcheckCustomDictionary(
const base::FilePath& dictionary_directory_name)
: … { … }
SpellcheckCustomDictionary::~SpellcheckCustomDictionary() { … }
const std::set<std::string>& SpellcheckCustomDictionary::GetWords() const { … }
bool SpellcheckCustomDictionary::AddWord(const std::string& word) { … }
bool SpellcheckCustomDictionary::RemoveWord(const std::string& word) { … }
bool SpellcheckCustomDictionary::HasWord(const std::string& word) const { … }
void SpellcheckCustomDictionary::Clear() { … }
void SpellcheckCustomDictionary::AddObserver(Observer* observer) { … }
void SpellcheckCustomDictionary::RemoveObserver(Observer* observer) { … }
bool SpellcheckCustomDictionary::IsLoaded() { … }
bool SpellcheckCustomDictionary::IsSyncing() { … }
void SpellcheckCustomDictionary::Load() { … }
void SpellcheckCustomDictionary::WaitUntilReadyToSync(base::OnceClosure done) { … }
std::optional<syncer::ModelError>
SpellcheckCustomDictionary::MergeDataAndStartSyncing(
syncer::DataType type,
const syncer::SyncDataList& initial_sync_data,
std::unique_ptr<syncer::SyncChangeProcessor> sync_processor) { … }
void SpellcheckCustomDictionary::StopSyncing(syncer::DataType type) { … }
syncer::SyncDataList SpellcheckCustomDictionary::GetAllSyncDataForTesting(
syncer::DataType type) const { … }
std::optional<syncer::ModelError>
SpellcheckCustomDictionary::ProcessSyncChanges(
const base::Location& from_here,
const syncer::SyncChangeList& change_list) { … }
base::WeakPtr<syncer::SyncableService> SpellcheckCustomDictionary::AsWeakPtr() { … }
SpellcheckCustomDictionary::LoadFileResult::LoadFileResult()
: … { … }
SpellcheckCustomDictionary::LoadFileResult::~LoadFileResult() { … }
std::unique_ptr<SpellcheckCustomDictionary::LoadFileResult>
SpellcheckCustomDictionary::LoadDictionaryFile(const base::FilePath& path) { … }
void SpellcheckCustomDictionary::UpdateDictionaryFile(
std::unique_ptr<Change> dictionary_change,
const base::FilePath& path) { … }
void SpellcheckCustomDictionary::OnLoaded(
std::unique_ptr<LoadFileResult> result) { … }
void SpellcheckCustomDictionary::Apply(const Change& dictionary_change) { … }
void SpellcheckCustomDictionary::FixInvalidFile(
std::unique_ptr<LoadFileResult> load_file_result) { … }
void SpellcheckCustomDictionary::Save(
std::unique_ptr<Change> dictionary_change) { … }
std::optional<syncer::ModelError> SpellcheckCustomDictionary::Sync(
const Change& dictionary_change) { … }
void SpellcheckCustomDictionary::Notify(const Change& dictionary_change) { … }