blob: 2b10a0671918cd6c69ac362ea863d85fad995d2c [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 isn’t "browser code." This is
Brett Wilsona5a898f12024-01-25 17:03:3848 mostly Ash when referring to code in the Chromium repository.
49
50- **Shared code:** Code used in both browser and OS code including //base,
51 //mojo, //ui, and some components.
52
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
65Shared code like //views may have ChromeOS-specific parts and take contributions
66from anyone, but the Browser and OS teams should agree that the code is
67appropriate for such sharing.
68
69In this desired state:
70
Kyle Horimoto1b7228652024-09-17 02:58:1071- 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
74 of the above-mentioned callbacks.
Brett Wilsona5a898f12024-01-25 17:03:3875
76- The //content directory is the API for building a web browser. Even though Ash
77 does use web technology for rendering many things, it is not itself a web
78 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
Kyle Horimoto1b7228652024-09-17 02:58:1094New features should be designed to adhere to the "desire" 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
Kyle Horimotof9aea4e2024-05-13 16:51:4198- Some functionality (e.g., the `Profile` class) is only available in //chrome,
99 and there is no clear alternative to use.
Brett Wilsona5a898f12024-01-25 17:03:38100
Kyle Horimotof9aea4e2024-05-13 16:51:41101- Legacy code still has significant //chrome dependencies and has not been
102 migrated away from this state.
Brett Wilsona5a898f12024-01-25 17:03:38103
Kyle Horimotof9aea4e2024-05-13 16:51:41104Thus, we must be pragmatic about implementing Ash features in the meantime,
105using the following guidance:
Brett Wilsona5a898f12024-01-25 17:03:38106
Kyle Horimotof9aea4e2024-05-13 16:51:41107- Any new Ash functionality should add its core functionality outside of
108 //chrome.
109 - In this context, "core" functionality includes the primary business logic of
110 a feature.
111 - Guidance on where this code should exist:
112 - **Ash-only code which is not system UI:** //chromeos/ash/components
113 - **Ash-only system UI code:** //ash
Kyle Horimotof9aea4e2024-05-13 16:51:41114 - **Shared by both Ash and Lacros:**
115 - *UI code:* //chromeos/ui
116 - *Non-UI code:* //chromeos/components
Kyle Horimoto1b7228652024-09-17 02:58:10117 - **NOTE:** Lacros is in the process of being deprecated. Do not add any
118 new Lacros code.
119 - **Shared between ChromeOS (i.e., ash-chrome) and other platforms:**
120 //components
Brett Wilsona5a898f12024-01-25 17:03:38121
Kyle Horimotof9aea4e2024-05-13 16:51:41122- For code which must depend on //chrome, push logic down lower in the
123 dependency graph as much as possible, and only implement a thin wrapper in
124 //chrome. With this pattern, the code in //chrome is mostly "glue" or
125 initialization code, which will minimize the effort required in the future to
126 break these dependencies completely.
127 - 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)
128 is declared in //chromeos/ash/components alongside related code logic, but
129 [`BrowserTabsModelProviderImpl`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/ash/phonehub/browser_tabs_model_provider_impl.h;drc=fe132eeb21687c455d695d6af346f15454828d01)
130 (in //chrome) implements the interface using a //chrome dependency.
131 - 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)
132 is declared in //chromeos/ash/components and has dependencies outside of
133 //chrome, but the concrete implementations of some of these components are
134 [`KeyedService`](https://source.chromium.org/chromium/chromium/src/+/main:components/keyed_service/core/keyed_service.h;drc=d23075f3066f6aab6fd5f8446ea5dde3ebff1097)s
135 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)
136 instantiates [`PhoneHubManagerImpl`](https://source.chromium.org/chromium/chromium/src/+/main:chromeos/ash/components/phonehub/phone_hub_manager_impl.h;drc=6b2b6f5aa258a1616fab24634c4e9477cfef5daf)
137 in //chrome (serving as a thin wrapper around the dependencies), but the
138 vast majority of logic is lower in the dependency graph.
139
140- A few common //chrome dependencies that may be able to be broken easily:
141 - Instead of using [`ProfileKeyedServiceFactory`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile_keyed_service_factory.h;drc=77a7a02b1822640e35cac72c0ddd7af7275eeb9b)
142 (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)
143 (in //components) instead.
144 - Instead of using a [`Profile`](https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/profiles/profile.h;l=308-311;drc=3f4203f7dca2f7e804f30cfa783e24f90acd9059)
145 (in //chrome) to access user prefs, consider using
146 [`User::GetProfilePrefs()`](https://source.chromium.org/chromium/chromium/src/+/main:components/user_manager/user.h;l=127-131;drc=e49b1aec9585b0a527c24502dd4b0ee94b142c3c)
147 (in //components) instead.
148
149- For any new code added in //chrome/browser/ash, a DEPS file must be created
150 which explicitly declares //chrome dependencies. People residing in
151 //chrome/OWNERS can help suggest alternatives to these dependencies if
152 possible when reviewing the code which adds this new DEPS file. See
153 [b/332805865](http://b/332805865) for more details.
154
Kyle Horimotof9aea4e2024-05-13 16:51:41155If you need advice to help you make a decision regarding your design, please
156reach out to ash-chrome-refactor@google.com for feedback.
157
158## Path forward
Brett Wilsona5a898f12024-01-25 17:03:38159
160The current policy aims to stop accumulating more undesirable OS/browser
161dependencies while acknowledging there is a large amount of legacy code that
Kyle Horimotof9aea4e2024-05-13 16:51:41162does not follow the guidelines. The team is moving toward the desired state
Kyle Horimoto1b7228652024-09-17 02:58:10163using the following approach outlined in go/ash-chrome-refactor:
Brett Wilsona5a898f12024-01-25 17:03:38164
Kyle Horimoto1b7228652024-09-17 02:58:10165- Ensure that all Ash code in //chrome is defined using granular BUILD.gn files.
166 Each directory should define its own build targets and list dependencies
167 explicitly.
168 - See https://crbug.com/335314438, https://crbug.com/351889236.
169- ...more to come as the Ash //chrome Refactor makes progress.