From 29ab381dc1dd9d8e015b4b8e434345ea7c9f2c8a Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Thu, 19 Feb 2026 17:10:45 -0800 Subject: [PATCH] Move local_ai/browser/ and local_ai/common to local_ai/core/ (#34068) * Move local_ai/browser/ to local_ai/core/ Split the local_ai component directory to separate core (platform-agnostic) code from content-dependent code that will follow in subsequent PRs. This removes the browser/ subdirectory since all local_ai code runs in the browser process. * Move local_ai/common/ to local_ai/core/ --- browser/BUILD.gn | 2 +- browser/DEPS | 3 +-- browser/about_flags.cc | 2 +- browser/component_updater/BUILD.gn | 2 +- chromium_src/chrome/browser/component_updater/DEPS | 2 +- .../browser/component_updater/registration.cc | 2 +- components/BUILD.gn | 2 +- components/local_ai/common/BUILD.gn | 13 ------------- components/local_ai/{browser => core}/BUILD.gn | 10 ++++++---- components/local_ai/{browser => core}/DEPS | 1 + components/local_ai/{common => core}/features.cc | 2 +- components/local_ai/{common => core}/features.h | 6 +++--- .../{browser => core}/local_models_updater.cc | 4 ++-- .../{browser => core}/local_models_updater.h | 6 +++--- .../local_models_updater_unittest.cc | 4 ++-- 15 files changed, 25 insertions(+), 36 deletions(-) delete mode 100644 components/local_ai/common/BUILD.gn rename components/local_ai/{browser => core}/BUILD.gn (87%) rename components/local_ai/{browser => core}/DEPS (82%) rename components/local_ai/{common => core}/features.cc (87%) rename components/local_ai/{common => core}/features.h (71%) rename components/local_ai/{browser => core}/local_models_updater.cc (97%) rename components/local_ai/{browser => core}/local_models_updater.h (94%) rename components/local_ai/{browser => core}/local_models_updater_unittest.cc (97%) diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 4665550cf7f..eedcddf7df5 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -32,7 +32,7 @@ source_set("browser_process") { deps = [ "//brave/components/brave_ads/buildflags", "//brave/components/brave_vpn/common/buildflags", - "//brave/components/local_ai/common", + "//brave/components/local_ai/core", "//brave/components/request_otr/common/buildflags", "//brave/components/speedreader/common/buildflags", "//brave/components/tor/buildflags", diff --git a/browser/DEPS b/browser/DEPS index 8570c7fbaf6..b3270236269 100644 --- a/browser/DEPS +++ b/browser/DEPS @@ -58,8 +58,7 @@ include_rules += [ "+brave/components/email_aliases/browser", "+brave/components/global_privacy_control", "+brave/components/google_sign_in_permission", - "+brave/components/local_ai/browser", - "+brave/components/local_ai/common", + "+brave/components/local_ai/core", "+brave/components/ntp_background_images/browser", "+brave/components/ntp_background_images/common", "+brave/components/ntp_background_images/buildflags", diff --git a/browser/about_flags.cc b/browser/about_flags.cc index 1be8a3cb1c3..c30224fdda8 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -26,7 +26,7 @@ #include "brave/components/de_amp/common/features.h" #include "brave/components/debounce/core/common/features.h" #include "brave/components/google_sign_in_permission/features.h" -#include "brave/components/local_ai/common/features.h" +#include "brave/components/local_ai/core/features.h" #include "brave/components/playlist/core/common/features.h" #include "brave/components/psst/buildflags/buildflags.h" #include "brave/components/request_otr/common/buildflags/buildflags.h" diff --git a/browser/component_updater/BUILD.gn b/browser/component_updater/BUILD.gn index d795534385e..56296be8beb 100644 --- a/browser/component_updater/BUILD.gn +++ b/browser/component_updater/BUILD.gn @@ -12,7 +12,7 @@ source_set("component_updater") { deps = [ "//base", "//brave/components/constants", - "//brave/components/local_ai/browser", + "//brave/components/local_ai/core", "//chrome/common", "//components/component_updater", "//components/prefs", diff --git a/chromium_src/chrome/browser/component_updater/DEPS b/chromium_src/chrome/browser/component_updater/DEPS index 292de7dd45f..351bf5e30f7 100644 --- a/chromium_src/chrome/browser/component_updater/DEPS +++ b/chromium_src/chrome/browser/component_updater/DEPS @@ -2,7 +2,7 @@ include_rules = [ "+brave/components/brave_component_updater/browser", "+brave/components/brave_origin/buildflags", "+brave/components/brave_user_agent/browser", - "+brave/components/local_ai/browser", + "+brave/components/local_ai/core", "+brave/components/psst/buildflags", "+brave/components/brave_wallet", "+brave/components/p3a", diff --git a/chromium_src/chrome/browser/component_updater/registration.cc b/chromium_src/chrome/browser/component_updater/registration.cc index 948b689ae66..8de0add0fcb 100644 --- a/chromium_src/chrome/browser/component_updater/registration.cc +++ b/chromium_src/chrome/browser/component_updater/registration.cc @@ -15,7 +15,7 @@ #include "brave/browser/brave_browser_process.h" #include "brave/components/brave_user_agent/browser/brave_user_agent_component_installer.h" #include "brave/components/brave_wallet/common/buildflags/buildflags.h" -#include "brave/components/local_ai/browser/local_models_updater.h" +#include "brave/components/local_ai/core/local_models_updater.h" #include "brave/components/p3a/component_installer.h" #include "brave/components/p3a/p3a_service.h" #include "brave/components/psst/buildflags/buildflags.h" diff --git a/components/BUILD.gn b/components/BUILD.gn index b8c3ce9ff29..111eda56230 100644 --- a/components/BUILD.gn +++ b/components/BUILD.gn @@ -35,7 +35,7 @@ test("brave_components_unittests") { "//brave/components/component_updater:unit_tests", "//brave/components/email_aliases:unit_tests", "//brave/components/json:unit_tests", - "//brave/components/local_ai/browser:unit_tests", + "//brave/components/local_ai/core:unit_tests", "//brave/components/static_redirect_helper:unit_tests", "//brave/components/update_client:unit_tests", "//brave/components/url_sanitizer/core/browser:unit_tests", diff --git a/components/local_ai/common/BUILD.gn b/components/local_ai/common/BUILD.gn deleted file mode 100644 index 3101a060cd9..00000000000 --- a/components/local_ai/common/BUILD.gn +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright (c) 2024 The Brave Authors. All rights reserved. -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this file, -# You can obtain one at https://mozilla.org/MPL/2.0/. - -source_set("common") { - sources = [ - "features.cc", - "features.h", - ] - - deps = [ "//base" ] -} diff --git a/components/local_ai/browser/BUILD.gn b/components/local_ai/core/BUILD.gn similarity index 87% rename from components/local_ai/browser/BUILD.gn rename to components/local_ai/core/BUILD.gn index 280bd7664ce..628ba33464e 100644 --- a/components/local_ai/browser/BUILD.gn +++ b/components/local_ai/core/BUILD.gn @@ -3,8 +3,12 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at https://mozilla.org/MPL/2.0/. -static_library("browser") { +static_library("core") { + assert_no_deps = [ "//content/public/*" ] + sources = [ + "features.cc", + "features.h", "local_models_updater.cc", "local_models_updater.h", ] @@ -13,7 +17,6 @@ static_library("browser") { deps = [ "//brave/components/brave_component_updater/browser:public", - "//brave/components/local_ai/common", "//components/component_updater", "//components/component_updater:component_updater_paths", "//components/update_client", @@ -26,11 +29,10 @@ source_set("unit_tests") { sources = [ "local_models_updater_unittest.cc" ] deps = [ - ":browser", + ":core", "//base", "//base/test:test_support", "//brave/components/brave_component_updater/browser:test_support", - "//brave/components/local_ai/common", "//components/component_updater:test_support", "//testing/gmock", "//testing/gtest", diff --git a/components/local_ai/browser/DEPS b/components/local_ai/core/DEPS similarity index 82% rename from components/local_ai/browser/DEPS rename to components/local_ai/core/DEPS index f285b3ef4ea..62c1bec6723 100644 --- a/components/local_ai/browser/DEPS +++ b/components/local_ai/core/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "!content/public", "+components/component_updater", "+components/update_client", "+crypto", diff --git a/components/local_ai/common/features.cc b/components/local_ai/core/features.cc similarity index 87% rename from components/local_ai/common/features.cc rename to components/local_ai/core/features.cc index 34968135cae..69580f36648 100644 --- a/components/local_ai/common/features.cc +++ b/components/local_ai/core/features.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/local_ai/common/features.h" +#include "brave/components/local_ai/core/features.h" namespace local_ai::features { diff --git a/components/local_ai/common/features.h b/components/local_ai/core/features.h similarity index 71% rename from components/local_ai/common/features.h rename to components/local_ai/core/features.h index 6ef0486b9c5..6168cc76c26 100644 --- a/components/local_ai/common/features.h +++ b/components/local_ai/core/features.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_LOCAL_AI_COMMON_FEATURES_H_ -#define BRAVE_COMPONENTS_LOCAL_AI_COMMON_FEATURES_H_ +#ifndef BRAVE_COMPONENTS_LOCAL_AI_CORE_FEATURES_H_ +#define BRAVE_COMPONENTS_LOCAL_AI_CORE_FEATURES_H_ #include "base/feature_list.h" @@ -14,4 +14,4 @@ BASE_DECLARE_FEATURE(kLocalAIModels); } // namespace local_ai::features -#endif // BRAVE_COMPONENTS_LOCAL_AI_COMMON_FEATURES_H_ +#endif // BRAVE_COMPONENTS_LOCAL_AI_CORE_FEATURES_H_ diff --git a/components/local_ai/browser/local_models_updater.cc b/components/local_ai/core/local_models_updater.cc similarity index 97% rename from components/local_ai/browser/local_models_updater.cc rename to components/local_ai/core/local_models_updater.cc index 88f0b2aa9b3..be61d5ae84a 100644 --- a/components/local_ai/browser/local_models_updater.cc +++ b/components/local_ai/core/local_models_updater.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/local_ai/browser/local_models_updater.h" +#include "brave/components/local_ai/core/local_models_updater.h" #include #include @@ -22,7 +22,7 @@ #include "base/values.h" #include "base/version.h" #include "brave/components/brave_component_updater/browser/brave_on_demand_updater.h" -#include "brave/components/local_ai/common/features.h" +#include "brave/components/local_ai/core/features.h" #include "components/component_updater/component_installer.h" #include "components/component_updater/component_updater_paths.h" #include "components/component_updater/component_updater_service.h" diff --git a/components/local_ai/browser/local_models_updater.h b/components/local_ai/core/local_models_updater.h similarity index 94% rename from components/local_ai/browser/local_models_updater.h rename to components/local_ai/core/local_models_updater.h index 5cbaf71d69d..01ab9ef05b6 100644 --- a/components/local_ai/browser/local_models_updater.h +++ b/components/local_ai/core/local_models_updater.h @@ -3,8 +3,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#ifndef BRAVE_COMPONENTS_LOCAL_AI_BROWSER_LOCAL_MODELS_UPDATER_H_ -#define BRAVE_COMPONENTS_LOCAL_AI_BROWSER_LOCAL_MODELS_UPDATER_H_ +#ifndef BRAVE_COMPONENTS_LOCAL_AI_CORE_LOCAL_MODELS_UPDATER_H_ +#define BRAVE_COMPONENTS_LOCAL_AI_CORE_LOCAL_MODELS_UPDATER_H_ #include #include @@ -96,4 +96,4 @@ void ManageLocalModelsComponentRegistration( } // namespace local_ai -#endif // BRAVE_COMPONENTS_LOCAL_AI_BROWSER_LOCAL_MODELS_UPDATER_H_ +#endif // BRAVE_COMPONENTS_LOCAL_AI_CORE_LOCAL_MODELS_UPDATER_H_ diff --git a/components/local_ai/browser/local_models_updater_unittest.cc b/components/local_ai/core/local_models_updater_unittest.cc similarity index 97% rename from components/local_ai/browser/local_models_updater_unittest.cc rename to components/local_ai/core/local_models_updater_unittest.cc index 3acaf00fed6..bb530b65493 100644 --- a/components/local_ai/browser/local_models_updater_unittest.cc +++ b/components/local_ai/core/local_models_updater_unittest.cc @@ -3,7 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ -#include "brave/components/local_ai/browser/local_models_updater.h" +#include "brave/components/local_ai/core/local_models_updater.h" #include @@ -20,7 +20,7 @@ #include "base/values.h" #include "base/version.h" #include "brave/components/brave_component_updater/browser/mock_on_demand_updater.h" -#include "brave/components/local_ai/common/features.h" +#include "brave/components/local_ai/core/features.h" #include "components/component_updater/component_updater_paths.h" #include "components/component_updater/mock_component_updater_service.h" #include "testing/gmock/include/gmock/gmock.h"