chromium/components/translate/core/browser/translate_manager.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/translate/core/browser/translate_manager.h"

#include <map>
#include <memory>
#include <string_view>
#include <tuple>
#include <utility>

#include "base/command_line.h"
#include "base/debug/dump_without_crashing.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/language/core/browser/language_model.h"
#include "components/language/core/common/language_experiments.h"
#include "components/language/core/common/language_util.h"
#include "components/language/core/common/locale_util.h"
#include "components/prefs/pref_service.h"
#include "components/translate/core/browser/language_state.h"
#include "components/translate/core/browser/page_translated_details.h"
#include "components/translate/core/browser/translate_browser_metrics.h"
#include "components/translate/core/browser/translate_client.h"
#include "components/translate/core/browser/translate_download_manager.h"
#include "components/translate/core/browser/translate_driver.h"
#include "components/translate/core/browser/translate_error_details.h"
#include "components/translate/core/browser/translate_init_details.h"
#include "components/translate/core/browser/translate_language_list.h"
#include "components/translate/core/browser/translate_metrics_logger.h"
#include "components/translate/core/browser/translate_metrics_logger_impl.h"
#include "components/translate/core/browser/translate_prefs.h"
#include "components/translate/core/browser/translate_ranker.h"
#include "components/translate/core/browser/translate_script.h"
#include "components/translate/core/browser/translate_trigger_decision.h"
#include "components/translate/core/browser/translate_url_util.h"
#include "components/translate/core/common/language_detection_details.h"
#include "components/translate/core/common/translate_constants.h"
#include "components/translate/core/common/translate_switches.h"
#include "components/translate/core/common/translate_util.h"
#include "components/variations/variations_associated_data.h"
#include "google_apis/google_api_keys.h"
#include "net/base/mime_util.h"
#include "net/base/network_change_notifier.h"
#include "net/base/url_util.h"
#include "net/http/http_status_code.h"
#include "third_party/metrics_proto/translate_event.pb.h"

namespace translate {

namespace {

// Callbacks for translate errors.
TranslateManager::TranslateErrorCallbackList* g_error_callback_list_ =;

// Callbacks for translate initializations.
TranslateManager::TranslateInitCallbackList* g_init_callback_list_ =;

// Callbacks for language detection.
TranslateManager::LanguageDetectedCallbackList* g_detection_callback_list_ =;

}  // namespace

TranslateManager::~TranslateManager() = default;

// static
base::CallbackListSubscription TranslateManager::RegisterTranslateErrorCallback(
    const TranslateManager::TranslateErrorCallback& callback) {}

// static
base::CallbackListSubscription TranslateManager::RegisterTranslateInitCallback(
    const TranslateManager::TranslateInitCallback& callback) {}

// static
base::CallbackListSubscription
TranslateManager::RegisterLanguageDetectedCallback(
    const TranslateManager::LanguageDetectedCallback& callback) {}

TranslateManager::TranslateManager(TranslateClient* translate_client,
                                   TranslateRanker* translate_ranker,
                                   language::LanguageModel* language_model)
    :{}

base::WeakPtr<TranslateManager> TranslateManager::GetWeakPtr() {}

void TranslateManager::InitiateTranslation(const std::string& page_lang) {}

bool TranslateManager::CanManuallyTranslate(bool menuLogging) {}

bool TranslateManager::CanPartiallyTranslateTargetLanguage() {}

bool TranslateManager::IsMimeTypeSupported(const std::string& mime_type) {}

void TranslateManager::ShowTranslateUI(const std::string& target_lang,
                                       bool auto_translate,
                                       bool triggered_from_menu) {}

void TranslateManager::ShowTranslateUI(bool auto_translate,
                                       bool triggered_from_menu) {}

void TranslateManager::TranslatePage(const std::string& original_source_lang,
                                     const std::string& target_lang,
                                     bool triggered_from_menu,
                                     TranslationType translation_type) {}

void TranslateManager::RevertTranslation() {}

void TranslateManager::DoTranslatePage(const std::string& translate_script,
                                       const std::string& source_lang,
                                       const std::string& target_lang) {}

// Notifies |g_error_callback_list_| of translate errors.
void TranslateManager::NotifyTranslateError(TranslateErrors error_type) {}

void TranslateManager::NotifyTranslateInit(std::string page_language_code,
                                           std::string target_lang,
                                           TranslateTriggerDecision decision,
                                           bool ui_shown) {}

void TranslateManager::NotifyLanguageDetected(
    const translate::LanguageDetectionDetails& details) {}

void TranslateManager::PageTranslated(const std::string& source_lang,
                                      const std::string& target_lang,
                                      TranslateErrors error_type) {}

void TranslateManager::OnTranslateScriptFetchComplete(
    const std::string& source_lang,
    const std::string& target_lang,
    bool success) {}

std::string TranslateManager::GetTargetLanguageForDisplay(
    TranslatePrefs* prefs,
    language::LanguageModel* language_model) {}

// static
std::string TranslateManager::GetTargetLanguage(
    TranslatePrefs* prefs,
    language::LanguageModel* language_model,
    const std::string source_lang_code,
    TranslateBrowserMetrics::TargetLanguageOrigin& target_language_origin) {}

// static
std::string TranslateManager::GetTargetLanguage(
    TranslatePrefs* prefs,
    language::LanguageModel* language_model,
    const std::string source_lang_code) {}

// static
std::string TranslateManager::GetAutoTargetLanguage(
    const std::string& source_language,
    TranslatePrefs* translate_prefs) {}

LanguageState* TranslateManager::GetLanguageState() {}

bool TranslateManager::ignore_missing_key_for_testing_ =;

// static
void TranslateManager::SetIgnoreMissingKeyForTesting(bool ignore) {}

// static
bool TranslateManager::IsAvailable(const TranslatePrefs* prefs) {}

void TranslateManager::InitTranslateEvent(const std::string& src_lang,
                                          const std::string& dst_lang,
                                          const TranslatePrefs& prefs) {}

void TranslateManager::RecordTranslateEvent(int event_type) {}

bool TranslateManager::ShouldOverrideMatchesPreviousLanguageDecision() {}

bool TranslateManager::ShouldSuppressBubbleUI(
    const std::string& target_language) {}

void TranslateManager::AddTargetLanguageToAcceptLanguages(
    const std::string& target_language_code) {}

const TranslateTriggerDecision TranslateManager::ComputePossibleOutcomes(
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code,
    const std::string& target_lang) {}

void TranslateManager::FilterIsTranslatePossible(
    TranslateTriggerDecision* decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code,
    const std::string& target_lang) {}

void TranslateManager::FilterAutoTranslate(
    TranslateTriggerDecision* decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code) {}

void TranslateManager::FilterForUserPrefs(
    TranslateTriggerDecision* decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code) {}

void TranslateManager::FilterForHrefTranslate(
    TranslateTriggerDecision* decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code) {}

void TranslateManager::FilterForPredefinedTarget(
    TranslateTriggerDecision* decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code) {}

void TranslateManager::MaybeShowOmniboxIcon(
    const TranslateTriggerDecision& decision) {}

bool TranslateManager::MaterializeDecision(
    const TranslateTriggerDecision& decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code,
    const std::string target_lang) {}

void TranslateManager::RecordDecisionMetrics(
    const TranslateTriggerDecision& decision,
    const std::string& page_language_code,
    bool ui_shown) {}

void TranslateManager::RecordDecisionRankerEvent(
    const TranslateTriggerDecision& decision,
    TranslatePrefs* translate_prefs,
    const std::string& page_language_code,
    const std::string& target_lang) {}

void TranslateManager::SetPredefinedTargetLanguage(
    const std::string& language_code,
    bool should_auto_translate) {}

TranslateMetricsLogger* TranslateManager::GetActiveTranslateMetricsLogger() {}

void TranslateManager::RegisterTranslateMetricsLogger(
    base::WeakPtr<TranslateMetricsLogger> translate_metrics_logger) {}

}  // namespace translate