0

Introduce ENABLE_ON_DEVICE_TRANSLATION build flag

Currently, the BUILDFLAG check for OnDeviceTranslation functionality is
implemented using win|macOS|Linux and !Android.

However, OnDeviceTranslation only works on Windows, macOS, and Linux, so
the !Android check is incorrect.

To clean up this BUILDFLAG check, this CL introduces a new build flag
called ENABLE_ON_DEVICE_TRANSLATION. This flag is equivalent to
win|macOS|Linux.

This CL includes the following behavioral changes:
On OSes other than Win/Mac/Linux, even if EnableTranslationAPI feature
is enabled, the TranslationManager interface will no longer be bound in
the browser process, and OnDeviceTranslationService will no longer be
bound on the service process.

Change-Id: Ibd913e2f931ba7f4890d2b4c625883cb02e6d470
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5925293
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
Reviewed-by: Ming-Ying Chung <mych@chromium.org>
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1369343}
This commit is contained in:
Tsuyoshi Horo
2024-10-16 13:32:29 +00:00
committed by Chromium LUCI CQ
parent 61a9ecc883
commit 358ff3f5f3
18 changed files with 128 additions and 60 deletions

@ -26,6 +26,7 @@ import("//components/nacl/features.gni")
import("//components/offline_pages/buildflags/features.gni")
import("//components/optimization_guide/features.gni")
import("//components/os_crypt/sync/features.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
import("//components/spellcheck/spellcheck_build_features.gni")
import("//crypto/features.gni")
import("//device/vr/buildflags/buildflags.gni")
@ -868,8 +869,6 @@ static_library("browser") {
"ntp_tiles/chrome_popular_sites_factory.h",
"offline_items_collection/offline_content_aggregator_factory.cc",
"offline_items_collection/offline_content_aggregator_factory.h",
"on_device_translation/translation_manager_impl.cc",
"on_device_translation/translation_manager_impl.h",
"optimization_guide/model_execution/chrome_on_device_model_service_controller.cc",
"optimization_guide/model_execution/chrome_on_device_model_service_controller.h",
"optimization_guide/prediction/prediction_model_download_client.cc",
@ -2300,7 +2299,6 @@ static_library("browser") {
"//components/services/heap_profiling",
"//components/services/language_detection/public/cpp",
"//components/services/language_detection/public/mojom",
"//components/services/on_device_translation:on_device_translation_service",
"//components/services/paint_preview_compositor/public/mojom:mojom",
"//components/services/patch/content",
"//components/services/quarantine",
@ -3895,10 +3893,6 @@ static_library("browser") {
"notifications/screen_capture_notification_blocker.cc",
"notifications/screen_capture_notification_blocker.h",
"obsolete_system/obsolete_system.h",
"on_device_translation/service_controller.cc",
"on_device_translation/service_controller.h",
"on_device_translation/translator.cc",
"on_device_translation/translator.h",
"page_info/about_this_site_side_panel_throttle.cc",
"page_info/about_this_site_side_panel_throttle.h",
"page_load_metrics/observers/non_tab_webui_page_load_metrics_observer.cc",
@ -4235,9 +4229,6 @@ static_library("browser") {
"//chrome/browser/media/router/discovery/access_code:access_code_sink_service",
"//chrome/browser/metrics/desktop_session_duration",
"//chrome/browser/new_tab_page/chrome_colors",
"//chrome/browser/on_device_translation:constants",
"//chrome/browser/on_device_translation:language_pack_util",
"//chrome/browser/on_device_translation:prefs",
"//chrome/browser/policy:path_parser",
"//chrome/browser/resources:component_extension_resources",
"//chrome/browser/screen_ai:prefs",
@ -8042,6 +8033,22 @@ static_library("browser") {
]
}
}
if (enable_on_device_translation) {
sources += [
"on_device_translation/service_controller.cc",
"on_device_translation/service_controller.h",
"on_device_translation/translation_manager_impl.cc",
"on_device_translation/translation_manager_impl.h",
"on_device_translation/translator.cc",
"on_device_translation/translator.h",
]
deps += [
"//chrome/browser/on_device_translation:constants",
"//chrome/browser/on_device_translation:language_pack_util",
"//chrome/browser/on_device_translation:prefs",
"//components/services/on_device_translation:on_device_translation_service",
]
}
if (enable_pdf) {
sources += [
@ -8541,6 +8548,7 @@ static_library("browser_public_dependencies") {
"//components/reporting/proto:configuration_file_proto",
"//components/safe_browsing:buildflags",
"//components/search_engines",
"//components/services/on_device_translation/buildflags",
"//components/services/storage/public/mojom",
"//components/session_proto_db:session_proto_db",
"//components/sharing_message",

@ -332,6 +332,7 @@ include_rules = [
"+components/services/heap_profiling",
"+components/services/language_detection/public/cpp",
"+components/services/language_detection/public/mojom",
"+components/services/on_device_translation/buildflags",
"+components/services/on_device_translation/public",
"+components/services/paint_preview_compositor/public/mojom",
"+components/services/patch/content",

@ -23,7 +23,6 @@
#include "chrome/browser/history_clusters/history_clusters_service_factory.h"
#include "chrome/browser/media/media_engagement_score_details.mojom.h"
#include "chrome/browser/navigation_predictor/navigation_predictor.h"
#include "chrome/browser/on_device_translation/translation_manager_impl.h"
#include "chrome/browser/optimization_guide/optimization_guide_internals_ui.h"
#include "chrome/browser/password_manager/chrome_password_manager_client.h"
#include "chrome/browser/predictors/lcp_critical_path_predictor/lcp_critical_path_predictor_host.h"
@ -89,6 +88,7 @@
#include "components/security_state/content/content_utils.h"
#include "components/security_state/content/security_state_tab_helper.h"
#include "components/security_state/core/security_state.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/site_engagement/core/mojom/site_engagement_details.mojom.h"
#include "components/translate/content/common/translate.mojom.h"
@ -110,7 +110,6 @@
#include "third_party/blink/public/mojom/facilitated_payments/payment_link_handler.mojom.h"
#include "third_party/blink/public/mojom/lcp_critical_path_predictor/lcp_critical_path_predictor.mojom.h"
#include "third_party/blink/public/mojom/loader/navigation_predictor.mojom.h"
#include "third_party/blink/public/mojom/on_device_translation/translation_manager.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_credential.mojom.h"
#include "third_party/blink/public/mojom/payments/payment_request.mojom.h"
#include "third_party/blink/public/mojom/prerender/prerender.mojom.h"
@ -509,6 +508,11 @@
#include "components/signin/public/base/signin_switches.h"
#endif // BUILDFLAG(ENABLE_DICE_SUPPORT)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#include "chrome/browser/on_device_translation/translation_manager_impl.h"
#include "third_party/blink/public/mojom/on_device_translation/translation_manager.mojom.h"
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
namespace chrome::internal {
using content::RegisterWebUIControllerInterfaceBinder;
@ -1109,10 +1113,12 @@ void PopulateChromeFrameBinders(
base::BindRepeating(&printing::CreateWebPrintingServiceForFrame));
#endif
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
if (base::FeatureList::IsEnabled(blink::features::kEnableTranslationAPI)) {
map->Add<blink::mojom::TranslationManager>(
base::BindRepeating(&TranslationManagerImpl::Create));
}
#endif
#if BUILDFLAG(IS_ANDROID)
if (base::FeatureList::IsEnabled(blink::features::kPaymentLinkDetection)) {

@ -108,7 +108,6 @@
#include "chrome/browser/net/profile_network_context_service.h"
#include "chrome/browser/net/profile_network_context_service_factory.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/on_device_translation/service_controller.h"
#include "chrome/browser/optimization_guide/chrome_browser_main_extra_parts_optimization_guide.h"
#include "chrome/browser/payments/payment_request_display_manager_factory.h"
#include "chrome/browser/performance_manager/public/chrome_browser_main_extra_parts_performance_manager.h"
@ -312,6 +311,7 @@
#include "components/security_interstitials/content/ssl_error_handler.h"
#include "components/security_interstitials/content/ssl_error_navigation_throttle.h"
#include "components/security_state/core/security_state.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "components/site_isolation/pref_names.h"
#include "components/site_isolation/preloaded_isolated_origins.h"
#include "components/site_isolation/site_isolation_policy.h"
@ -807,6 +807,10 @@
#include "components/feed/feed_feature_list.h"
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#include "chrome/browser/on_device_translation/service_controller.h"
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
using blink::mojom::EffectiveConnectionType;
using blink::web_pref::WebPreferences;
using content::BrowserThread;

@ -51,6 +51,7 @@
#include "components/history_embeddings/history_embeddings_features.h"
#include "components/nacl/common/buildflags.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "device/vr/buildflags/buildflags.h"
#include "ppapi/buildflags/buildflags.h"
#include "third_party/widevine/cdm/buildflags.h"
@ -82,11 +83,6 @@
#include "media/base/media_switches.h"
#endif // !BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#include "chrome/browser/component_updater/translate_kit_component_installer.h"
#include "chrome/browser/component_updater/translate_kit_language_pack_component_installer.h"
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/component_updater/smart_dim_component_installer.h"
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
@ -95,6 +91,11 @@
#include "chrome/browser/component_updater/media_foundation_widevine_cdm_component_installer.h"
#endif
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#include "chrome/browser/component_updater/translate_kit_component_installer.h"
#include "chrome/browser/component_updater/translate_kit_language_pack_component_installer.h"
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#if BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
#include "chrome/browser/component_updater/widevine_cdm_component_installer.h"
#endif // BUILDFLAG(ENABLE_WIDEVINE_CDM_COMPONENT)
@ -232,14 +233,14 @@ void RegisterComponentsForUpdate() {
RegisterPlusAddressBlocklistComponent(cus);
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
// TODO(crbug.com/364795294): Support other platforms.
RegisterTranslateKitComponent(cus, g_browser_process->local_state(),
/*force_install=*/false,
/*registered_callback=*/base::OnceClosure());
RegisterTranslateKitLanguagePackComponentsForUpdate(
cus, g_browser_process->local_state());
#endif // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
RegisterOpenCookieDatabaseComponent(cus);
}

@ -21,14 +21,11 @@
#include "chrome/browser/on_device_translation/pref_names.h"
#include "components/component_updater/component_updater_service.h"
#include "components/crx_file/id_util.h"
#include "components/services/on_device_translation/public/cpp/features.h"
#include "components/update_client/update_client_errors.h"
#include "content/public/browser/browser_thread.h"
#include "crypto/sha2.h"
#if !BUILDFLAG(IS_ANDROID)
#include "components/services/on_device_translation/public/cpp/features.h"
#endif // !BUILDFLAG(IS_ANDROID)
namespace component_updater {
namespace {

@ -36,3 +36,26 @@ source_set("language_pack_util") {
deps = [ "//base" ]
}
source_set("unit_tests") {
testonly = true
sources = [
"../component_updater/translate_kit_component_installer_unittest.cc",
"../component_updater/translate_kit_language_pack_component_installer_unittest.cc",
"language_pack_util_unittest.cc",
"translation_manager_impl_unittest.cc",
]
deps = [
":language_pack_util",
":prefs",
"//base",
"//base/test:test_support",
"//chrome/browser",
"//components/component_updater:test_support",
"//components/crx_file",
"//components/prefs",
"//components/services/on_device_translation/public/cpp",
"//components/sync_preferences:test_support",
"//content/test:test_support",
]
}

@ -6,7 +6,6 @@
#include <string_view>
#if !BUILDFLAG(IS_ANDROID)
#include "base/feature_list.h"
#include "base/strings/string_split.h"
#include "chrome/browser/on_device_translation/language_pack_util.h"
@ -16,15 +15,13 @@
#include "components/language/core/browser/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/services/on_device_translation/public/cpp/features.h"
#include "ui/base/l10n/l10n_util.h"
#endif // !BUILDFLAG(IS_ANDROID)
#include "content/public/browser/render_frame_host.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/mojom/on_device_translation/translation_manager.mojom.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
#if !BUILDFLAG(IS_ANDROID)
using on_device_translation::SupportedLanguage;
bool IsInAcceptLanguage(const std::vector<std::string_view>& accept_languages,
@ -44,7 +41,6 @@ bool IsSupportedPopularLanguage(const std::string& lang) {
}
return on_device_translation::IsPopularLanguage(*supported_lang);
}
#endif // !BUILDFLAG(IS_ANDROID)
} // namespace
@ -70,8 +66,6 @@ void TranslationManagerImpl::CanCreateTranslator(
const std::string& source_lang,
const std::string& target_lang,
CanCreateTranslatorCallback callback) {
// The API is not supported on Android yet.
#if !BUILDFLAG(IS_ANDROID)
CHECK(browser_context_);
if (!PassAcceptLanguagesCheck(
Profile::FromBrowserContext(browser_context_.get())
@ -83,9 +77,6 @@ void TranslationManagerImpl::CanCreateTranslator(
}
OnDeviceTranslationServiceController::GetInstance()->CanTranslate(
source_lang, target_lang, std::move(callback));
#else
std::move(callback).Run(false);
#endif // !BUILDFLAG(IS_ANDROID)
}
void TranslationManagerImpl::CreateTranslator(
@ -93,8 +84,6 @@ void TranslationManagerImpl::CreateTranslator(
const std::string& target_lang,
mojo::PendingReceiver<blink::mojom::Translator> receiver,
CreateTranslatorCallback callback) {
// The API is not supported on Android yet.
#if !BUILDFLAG(IS_ANDROID)
CHECK(browser_context_);
if (!PassAcceptLanguagesCheck(
Profile::FromBrowserContext(browser_context_.get())
@ -108,12 +97,8 @@ void TranslationManagerImpl::CreateTranslator(
std::make_unique<Translator>(source_lang, target_lang,
std::move(callback)),
std::move(receiver));
#else
std::move(callback).Run(false);
#endif // !BUILDFLAG(IS_ANDROID)
}
#if !BUILDFLAG(IS_ANDROID)
// static
bool TranslationManagerImpl::PassAcceptLanguagesCheck(
const std::string& accept_languages_str,
@ -152,4 +137,3 @@ bool TranslationManagerImpl::PassAcceptLanguagesCheck(
}
return true;
}
#endif // !BUILDFLAG(IS_ANDROID)

@ -49,11 +49,9 @@ class TranslationManagerImpl
mojo::PendingReceiver<blink::mojom::Translator> receiver,
CreateTranslatorCallback callback) override;
#if !BUILDFLAG(IS_ANDROID)
static bool PassAcceptLanguagesCheck(const std::string& accept_languages_str,
const std::string& source_lang,
const std::string& target_lang);
#endif // !BUILDFLAG(IS_ANDROID)
base::WeakPtr<content::BrowserContext> browser_context_;
mojo::Receiver<blink::mojom::TranslationManager> receiver_{this};

@ -98,6 +98,7 @@
#include "chrome/browser/ui/webui/print_preview/policy_settings.h"
#include "components/plus_addresses/plus_address_prefs.h"
#include "components/privacy_sandbox/tpcd_pref_names.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "components/sharing_message/sharing_sync_preference.h"
#include "components/signin/core/browser/active_primary_accounts_metrics_recorder.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
@ -287,7 +288,6 @@
#include "chrome/browser/new_tab_page/modules/v2/calendar/google_calendar_page_handler.h"
#include "chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption/most_relevant_tab_resumption_page_handler.h"
#include "chrome/browser/new_tab_page/promos/promo_service.h"
#include "chrome/browser/on_device_translation/pref_names.h"
#include "chrome/browser/policy/developer_tools_policy_handler.h"
#include "chrome/browser/promos/promos_utils.h"
#include "chrome/browser/screen_ai/pref_names.h"
@ -543,6 +543,10 @@
#include "chrome/browser/ash/wallpaper_handlers/wallpaper_prefs.h"
#endif
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#include "chrome/browser/on_device_translation/pref_names.h"
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#if BUILDFLAG(ENTERPRISE_DATA_CONTROLS)
#include "components/enterprise/data_controls/core/browser/prefs.h"
#endif
@ -1751,9 +1755,12 @@ void RegisterLocalState(PrefRegistrySimple* registry) {
task_manager::TaskManagerInterface::RegisterPrefs(registry);
UpgradeDetector::RegisterPrefs(registry);
registry->RegisterIntegerPref(prefs::kLastWhatsNewVersion, 0);
on_device_translation::RegisterLocalStatePrefs(registry);
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
on_device_translation::RegisterLocalStatePrefs(registry);
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
WhatsNewUI::RegisterLocalStatePrefs(registry);
#endif

@ -31,6 +31,7 @@ import("//components/offline_pages/buildflags/features.gni")
import("//components/optimization_guide/features.gni")
import("//components/os_crypt/sync/features.gni")
import("//components/safe_browsing/buildflags.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
import("//components/soda/buildflags.gni")
import("//components/spellcheck/spellcheck_build_features.gni")
import("//crypto/features.gni")
@ -7284,8 +7285,6 @@ test("unit_tests") {
"../browser/new_tab_page/promos/promo_service_unittest.cc",
"../browser/notifications/muted_notification_handler_unittest.cc",
"../browser/notifications/screen_capture_notification_blocker_unittest.cc",
"../browser/on_device_translation/language_pack_util_unittest.cc",
"../browser/on_device_translation/translation_manager_impl_unittest.cc",
"../browser/password_manager/generated_password_leak_detection_pref_unittest.cc",
"../browser/platform_util_unittest.cc",
"../browser/policy/policy_path_parser_unittest.cc",
@ -7620,13 +7619,10 @@ test("unit_tests") {
if (is_linux || is_mac || is_win) {
sources += [
"../browser/component_updater/translate_kit_component_installer_unittest.cc",
"../browser/component_updater/translate_kit_language_pack_component_installer_unittest.cc",
"../browser/supervised_user/linux_mac_windows/supervised_user_extensions_metrics_delegate_impl_unittest.cc",
"../browser/ui/sync/sync_passphrase_dialog_unittest.cc",
"../browser/ui/webui/settings/accessibility_main_handler_unittest.cc",
]
deps += [ "//chrome/browser/on_device_translation:prefs" ]
}
sources += [
@ -7766,7 +7762,6 @@ test("unit_tests") {
"//chrome/browser/new_tab_page/chrome_colors",
"//chrome/browser/new_tab_page/modules/v2/calendar:mojo_bindings",
"//chrome/browser/new_tab_page/modules/v2/most_relevant_tab_resumption:mojo_bindings",
"//chrome/browser/on_device_translation:language_pack_util",
"//chrome/browser/profile_resetter:fake_profile_resetter",
"//chrome/browser/resource_coordinator:tab_manager_features",
"//chrome/browser/resources:component_extension_resources_grit",
@ -7866,7 +7861,7 @@ test("unit_tests") {
"//components/services/app_service",
"//components/services/app_service/public/cpp:test_support",
"//components/services/app_service/public/cpp:unit_tests",
"//components/services/on_device_translation/public/cpp",
"//components/services/on_device_translation/buildflags",
"//components/session_proto_db:session_proto_db",
"//components/signin/public/base:signin_buildflags",
"//components/soda:constants",
@ -9292,6 +9287,9 @@ test("unit_tests") {
"../services/system_signals:unit_tests",
]
}
if (enable_on_device_translation) {
deps += [ "//chrome/browser/on_device_translation:unit_tests" ]
}
if (enable_pdf) {
sources += [

@ -8,6 +8,7 @@ import("//build/config/sysroot.gni")
import("//chrome/common/features.gni")
import("//chrome/services/speech/buildflags/buildflags.gni")
import("//chromeos/ash/components/assistant/assistant.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
import("//crypto/features.gni")
import("//extensions/buildflags/buildflags.gni")
import("//pdf/features.gni")
@ -47,7 +48,7 @@ static_library("utility") {
"//components/safe_browsing:buildflags",
"//components/search_engines",
"//components/services/language_detection",
"//components/services/on_device_translation:on_device_translation_service",
"//components/services/on_device_translation/buildflags",
"//components/services/paint_preview_compositor",
"//components/services/patch:lib",
"//components/services/unzip:lib",
@ -269,4 +270,8 @@ static_library("utility") {
if (enable_browser_speech_service) {
deps += [ "//chrome/services/speech:lib" ]
}
if (enable_on_device_translation) {
deps += [ "//components/services/on_device_translation:on_device_translation_service" ]
}
}

@ -17,7 +17,7 @@
#include "components/safe_browsing/buildflags.h"
#include "components/services/language_detection/language_detection_service_impl.h"
#include "components/services/language_detection/public/mojom/language_detection.mojom.h"
#include "components/services/on_device_translation/on_device_translation_service.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "components/services/patch/file_patcher_impl.h"
#include "components/services/patch/public/mojom/file_patcher.mojom.h"
#include "components/services/unzip/public/mojom/unzipper.mojom.h"
@ -144,6 +144,10 @@ static_assert(BUILDFLAG(ENABLE_PRINTING), "ChromeOS Ash must enable Printing");
#include "chromeos/components/quick_answers/public/mojom/spell_check.mojom.h"
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#include "components/services/on_device_translation/on_device_translation_service.h"
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
namespace {
auto RunFilePatcher(mojo::PendingReceiver<patch::mojom::FilePatcher> receiver) {
@ -433,12 +437,14 @@ auto RunMahiContentExtractionServiceFactory(
}
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
auto RunOnDeviceTranslationService(
mojo::PendingReceiver<
on_device_translation::mojom::OnDeviceTranslationService> receiver) {
return std::make_unique<on_device_translation::OnDeviceTranslationService>(
std::move(receiver));
}
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
#if BUILDFLAG(IS_CHROMEOS_ASH)
auto RunBabelOrcaTachyonParsingService(
@ -555,7 +561,9 @@ void RegisterMainThreadServices(mojo::ServiceFactory& services) {
services.Add(RunMahiContentExtractionServiceFactory);
#endif // BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
services.Add(RunOnDeviceTranslationService);
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION)
}
void RegisterIOThreadServices(mojo::ServiceFactory& services) {

@ -12,6 +12,7 @@ import("//components/enterprise/buildflags/buildflags.gni")
import("//components/nacl/features.gni")
import("//components/optimization_guide/features.gni")
import("//components/safe_browsing/buildflags.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
import("//components/supervised_user/buildflags.gni")
import("//extensions/buildflags/buildflags.gni")
import("//media/media_options.gni")
@ -871,7 +872,7 @@ test("components_unittests") {
deps += [ "//components/tpcd/enterprise_reporting:unit_tests" ]
}
if (is_linux || is_win || is_mac) {
if (enable_on_device_translation) {
deps += [ "//components/services/on_device_translation:unit_tests" ]
}

@ -0,0 +1,11 @@
# Copyright 2024 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/buildflag_header.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
buildflag_header("buildflags") {
header = "buildflags.h"
flags = [ "ENABLE_ON_DEVICE_TRANSLATION=$enable_on_device_translation" ]
}

@ -0,0 +1,9 @@
# Copyright 2024 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
declare_args() {
# On Device Translation is still not supported on other platforms.
# TODO(crbug.com/364795294): Support other platforms.
enable_on_device_translation = is_mac || is_win || is_linux
}

@ -4,6 +4,7 @@
import("//build/config/chromeos/ui_mode.gni")
import("//chromeos/ash/components/assistant/assistant.gni")
import("//components/services/on_device_translation/buildflags/features.gni")
import("//device/vr/buildflags/buildflags.gni")
import("//media/gpu/args.gni")
import("//media/media_options.gni")
@ -43,7 +44,7 @@ source_set("utility") {
"//build:branding_buildflags",
"//build:chromeos_buildflags",
"//components/optimization_guide/core:features",
"//components/services/on_device_translation:on_device_translation_service",
"//components/services/on_device_translation/buildflags",
"//components/services/storage",
"//components/services/storage/public/mojom",
"//content:export",
@ -155,6 +156,10 @@ source_set("utility") {
deps += [ "//services/accessibility:lib" ]
}
if (enable_on_device_translation) {
deps += [ "//components/services/on_device_translation:on_device_translation_service" ]
}
if (enable_vr && !is_android) {
deps += [
"//content/services/isolated_xr_device:lib",

@ -19,6 +19,7 @@
#include "base/timer/hi_res_timer_manager.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/services/on_device_translation/buildflags/buildflags.h"
#include "content/child/child_process.h"
#include "content/common/content_switches_internal.h"
#include "content/common/features.h"
@ -102,9 +103,10 @@
sandbox::TargetServices* g_utility_target_services = nullptr;
#endif // BUILDFLAG(IS_WIN)
#if BUILDFLAG(IS_LINUX)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
#include "components/services/on_device_translation/sandbox_hook.h"
#endif // BUILDFLAG(IS_LINUX)
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
namespace content {
namespace {
@ -292,12 +294,12 @@ int UtilityMain(MainFunctionParams parameters) {
pre_sandbox_hook =
base::BindOnce(&speech::SpeechRecognitionPreSandboxHook);
break;
#if BUILDFLAG(IS_LINUX)
#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
case sandbox::mojom::Sandbox::kOnDeviceTranslation:
pre_sandbox_hook = base::BindOnce(
&on_device_translation::OnDeviceTranslationSandboxHook);
break;
#endif // BUILDFLAG(IS_LINUX)
#endif // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
case sandbox::mojom::Sandbox::kScreenAI:
pre_sandbox_hook =