blob: dcbe2b13fbb3c41e4d2a012342d106873cf84c52 [file] [log] [blame] [view]
Brett Wilsona5a898f12024-01-25 17:03:381# The architecture of Browser/ChromeOS code
2
3## Overview
4
5We want to have clean code, good architecture, and clear ownership to ensure
6everybody can efficiently deliver high quality products. Toward this goal, this
7document discusses how code in the Chromium git repository is and should be
8architected between the browser and ChromeOS code.
9
10## Background
11
12Originally, ChromeOS was just the Linux Chrome browser with a few extra
13additions for UI system management. As such, and to keep the system requirements
Kyle Horimoto1b7228652024-09-17 02:58:1014very low, the entire ChromeOS UI was built into the Chrome "browser" process.
Brett Wilsona5a898f12024-01-25 17:03:3815Over time, ChromeOS has gotten substantially more sophisticated and capable.
16Many important services run in separate processes, services, or VMs, but most of
17the UI still runs in the main browser process.
18
Kyle Horimoto1b7228652024-09-17 02:58:1019The Lacros project aimed to separate the Linux processes and the software
20releases between the browser and the OS shell by shipping the Chrome web browser
21as a standalone app which could be updated independently of ChromeOS. Lacros
22communicated between the Chrome browser and ChromeOS via an IPC interface called
23crosapi. However, the Lacros project has been deprioritized and relevant code is
24in the process of being deprecated and deleted.
Brett Wilsona5a898f12024-01-25 17:03:3825
26### Definitions
27
28- **Browser:** General term referring to a process with web browsing capabilities.
29
30- **Ash:** The ChromeOS system UI. In this document, this term is used broadly
31 to include most of the non-browser UI features including the app launcher, the
32 system tray and notifications, the window manager, the system compositor, and
33 the login UI.
34
Kyle Horimoto1b7228652024-09-17 02:58:1035- **Lacros (deprecate, being deleted):** The ChromeOS-specific browser that does
36 not include Ash. This is similar to the Linux browser but with ChromeOS-
37 specific features and integrations.
Brett Wilsona5a898f12024-01-25 17:03:3838
Kyle Horimoto1b7228652024-09-17 02:58:1039- **Ash Browser:** The "classic" (non-Lacros) ChromeOS software that includes
Brett Wilsona5a898f12024-01-25 17:03:3840 Ash and the browser in one process.
41
42- **Browser code:** Code required to build a browser. This includes
43 platform-specific integrations with the host OS rather than just the
44 cross-platform parts. For ChromeOS, this includes many important ChromeOS
Kyle Horimoto1b7228652024-09-17 02:58:1045 browser features but does not include anything considered "Ash."
Brett Wilsona5a898f12024-01-25 17:03:3846
Kyle Horimoto1b7228652024-09-17 02:58:1047- **OS code:** Any ChromeOS-specific code that isnt "browser code." This is
Brett Wilsona5a898f12024-01-25 17:03:3848 mostly Ash when referring to code in the Chromium repository.
49
dljames5167ecad2024-11-27 01:00:2850- **Shared code:** Code used in both browser and OS code including `//base`,
51 `//mojo`, `//ui`, and some components.
Brett Wilsona5a898f12024-01-25 17:03:3852
53## Desired state
54
55_This section describes the long-term architectural goal rather than the current
56state or the current requirements. See below for what to do for current work._
57
Kyle Horimoto1b7228652024-09-17 02:58:1058The desired end-state is that "browser code" (including ChromeOS-specific
59browser features) and "OS code" have a clear separation. Communication between
Brett Wilsona5a898f12024-01-25 17:03:3860these layers should be done using well-defined APIs. Function calls in the code
Kyle Horimoto1b7228652024-09-17 02:58:1061happen "down" the stack from the browser to the OS, and any calls "up" from the
Brett Wilsona5a898f12024-01-25 17:03:3862OS to the browser happen via events, observers, and callbacks configured by the
63browser layers.
64
dljames5167ecad2024-11-27 01:00:2865Shared code like `//views` may have ChromeOS-specific parts and take
66contributions from anyone, but the Browser and OS teams should agree that the
67code is appropriate for such sharing.
Brett Wilsona5a898f12024-01-25 17:03:3868
69In this desired state:
70
dljames5167ecad2024-11-27 01:00:2871- The `//chrome` directory is for the implementation of the Chrome browser. It
72 should not have any OS code in it (for example, `//chrome/browser/ash` is
73 undesirable) and OS code should not call directly into `//chrome` code outside
Kyle Horimoto1b7228652024-09-17 02:58:1074 of the above-mentioned callbacks.
Brett Wilsona5a898f12024-01-25 17:03:3875
dljames5167ecad2024-11-27 01:00:2876- The `//content` directory is the API for building a web browser. Even though
77 Ash does use web technology for rendering many things, it is not itself a web
Brett Wilsona5a898f12024-01-25 17:03:3878 browser and there should be no OS code in this directory or calling directly
79 into it.
80
Kyle Horimoto1b7228652024-09-17 02:58:1081- Browser code should only call into OS code through well-defined APIs (e.g.,
82 extension APIs). This provides a conceptual separation between browser and OS
83 concerns.
Brett Wilsona5a898f12024-01-25 17:03:3884
85Not all parts of the product fit neatly into the browser and OS layers, with
86extensions and apps being big examples. How web page embedding should be done
87from Ash is an area of active design and there is not currently good guidance
88for this. In these less well-defined areas, work toward as clear a separation as
89practical given the current state and the long-term requirements of that
90component.
91
92## Current policies
93
dljames5167ecad2024-11-27 01:00:2894New features should be designed to adhere to the "desired state" as closely as
Kyle Horimotof9aea4e2024-05-13 16:51:4195practical. However, it is currently not possible to implement all functionality
96in Ash according to that state:
Brett Wilsona5a898f12024-01-25 17:03:3897
Darren Shen0e1f6212024-12-16 22:12:0398- Some functionality (e.g., the `Profile` or `BrowserContext` classes) are only
99 available in `//chrome` or `//content`, and there are no clear alternatives
100 to use.
Brett Wilsona5a898f12024-01-25 17:03:38101
dljames5167ecad2024-11-27 01:00:28102- Legacy code still has significant `//chrome` dependencies and has not been
Kyle Horimotof9aea4e2024-05-13 16:51:41103 migrated away from this state.
Brett Wilsona5a898f12024-01-25 17:03:38104
Kyle Horimotof9aea4e2024-05-13 16:51:41105Thus, we must be pragmatic about implementing Ash features in the meantime,
106using the following guidance:
Brett Wilsona5a898f12024-01-25 17:03:38107
Kyle Horimotof9aea4e2024-05-13 16:51:41108- Any new Ash functionality should add its core functionality outside of
dljames5167ecad2024-11-27 01:00:28109 `//chrome`.
Kyle Horimotof9aea4e2024-05-13 16:51:41110 - In this context, "core" functionality includes the primary business logic of
111 a feature.
112 - Guidance on where this code should exist:
dljames5167ecad2024-11-27 01:00:28113 - **Ash-only code which is not system UI:** `//chromeos/ash/components`
114 - **Ash-only system UI code:** `//ash`
Kyle Horimotof9aea4e2024-05-13 16:51:41115 - **Shared by both Ash and Lacros:**
dljames5167ecad2024-11-27 01:00:28116 - *UI code:* `//chromeos/ui`
117 - *Non-UI code:* `//chromeos/components`
Kyle Horimoto1b7228652024-09-17 02:58:10118 - **NOTE:** Lacros is in the process of being deprecated. Do not add any
119 new Lacros code.
120 - **Shared between ChromeOS (i.e., ash-chrome) and other platforms:**
dljames5167ecad2024-11-27 01:00:28121 `//components`
Brett Wilsona5a898f12024-01-25 17:03:38122
dljames5167ecad2024-11-27 01:00:28123- For code which must depend on `//chrome`, push logic down lower in the
Kyle Horimotof9aea4e2024-05-13 16:51:41124 dependency graph as much as possible, and only implement a thin wrapper in
dljames5167ecad2024-11-27 01:00:28125 `//chrome`. With this pattern, the code in `//chrome` is mostly "glue" or
Kyle Horimotof9aea4e2024-05-13 16:51:41126 initialization code, which will minimize the effort required in the future to
127 break these dependencies completely.
128 - Example 1: Phone Hub's [`BrowserTabsModelProvider`](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ash/components/phonehub/browser_tabs_model_provider.h;drc=2a153c1bc9f24cae375eee3cc875903866997918)
dljames5167ecad2024-11-27 01:00:28129 is declared in `//chromeos/ash/components` alongside related code logic, but
Kyle Horimotof9aea4e2024-05-13 16:51:41130 [`BrowserTabsModelProviderImpl`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/phonehub/browser_tabs_model_provider_impl.h;drc=fe132eeb21687c455d695d6af346f15454828d01)
dljames5167ecad2024-11-27 01:00:28131 (in `//chrome`) implements the interface using a `//chrome` dependency.
Kyle Horimotof9aea4e2024-05-13 16:51:41132 - Example 2: Phone Hub's [`PhoneHubManagerImpl`](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ash/components/phonehub/phone_hub_manager_impl.h;drc=6b2b6f5aa258a1616fab24634c4e9477cfef5daf)
dljames5167ecad2024-11-27 01:00:28133 is declared in `//chromeos/ash/components` and has dependencies outside of
134 `//chrome`, but the concrete implementations of some of these components are
Kyle Horimotof9aea4e2024-05-13 16:51:41135 [`KeyedService`](https://source.chromium.org/chromium/chromium/src/+/main:components/keyed_service/core/keyed_service.h;drc=d23075f3066f6aab6fd5f8446ea5dde3ebff1097)s
dljames5167ecad2024-11-27 01:00:28136 requiring `//chrome`. In this case, [`PhoneHubManagerFactory`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/phonehub/phone_hub_manager_factory.h;drc=d23075f3066f6aab6fd5f8446ea5dde3ebff1097)
Kyle Horimotof9aea4e2024-05-13 16:51:41137 instantiates [`PhoneHubManagerImpl`](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ash/components/phonehub/phone_hub_manager_impl.h;drc=6b2b6f5aa258a1616fab24634c4e9477cfef5daf)
dljames5167ecad2024-11-27 01:00:28138 in `//chrome` (serving as a thin wrapper around the dependencies), but the
Kyle Horimotof9aea4e2024-05-13 16:51:41139 vast majority of logic is lower in the dependency graph.
140
dljames5167ecad2024-11-27 01:00:28141- A few common `//chrome` dependencies that may be able to be broken easily:
Kyle Horimotof9aea4e2024-05-13 16:51:41142 - Instead of using [`ProfileKeyedServiceFactory`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile_keyed_service_factory.h;drc=77a7a02b1822640e35cac72c0ddd7af7275eeb9b)
dljames5167ecad2024-11-27 01:00:28143 (in `//chrome`), consider using [`BrowserContextKeyedServiceFactory`](https://source.chromium.org/chromium/chromium/src/+/main:components/keyed_service/content/browser_context_keyed_service_factory.h;drc=371515598109bf869e1acbe5ea67813fc1a4cc3d)
144 (in `//components`) instead.
Kyle Horimotof9aea4e2024-05-13 16:51:41145 - Instead of using a [`Profile`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile.h;l=308-311;drc=3f4203f7dca2f7e804f30cfa783e24f90acd9059)
dljames5167ecad2024-11-27 01:00:28146 (in `//chrome`) to access user prefs, consider using
Kyle Horimotof9aea4e2024-05-13 16:51:41147 [`User::GetProfilePrefs()`](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.h;l=127-131;drc=e49b1aec9585b0a527c24502dd4b0ee94b142c3c)
dljames5167ecad2024-11-27 01:00:28148 (in `//components`) instead.
Kyle Horimotof9aea4e2024-05-13 16:51:41149
dljames5167ecad2024-11-27 01:00:28150- For any new code added in `//chrome/browser/ash`, a `DEPS` file must be created
151 which explicitly declares `//chrome` dependencies. People residing in
152 `//chrome/OWNERS` can help suggest alternatives to these dependencies if
153 possible when reviewing the code which adds this new `DEPS` file. See
Kyle Horimotof9aea4e2024-05-13 16:51:41154 [b/332805865](http://b/332805865) for more details.
155
Kyle Horimotof9aea4e2024-05-13 16:51:41156If you need advice to help you make a decision regarding your design, please
157reach out to ash-chrome-refactor@google.com for feedback.
158
159## Path forward
Brett Wilsona5a898f12024-01-25 17:03:38160
161The current policy aims to stop accumulating more undesirable OS/browser
162dependencies while acknowledging there is a large amount of legacy code that
Kyle Horimotof9aea4e2024-05-13 16:51:41163does not follow the guidelines. The team is moving toward the desired state
Kyle Horimoto1b7228652024-09-17 02:58:10164using the following approach outlined in go/ash-chrome-refactor:
Brett Wilsona5a898f12024-01-25 17:03:38165
dljames5167ecad2024-11-27 01:00:28166- Ensure that all Ash code in `//chrome` is defined using granular BUILD.gn
167 files. Each directory should define its own build targets and list dependencies
Kyle Horimoto1b7228652024-09-17 02:58:10168 explicitly.
169 - See https://crbug.com/335314438, https://crbug.com/351889236.
170- ...more to come as the Ash //chrome Refactor makes progress.