Commit Graph
94 Commits
Author SHA1 Message Date
cdesouza-chromium ffa95ab18c [best-practices] Simple fixes to the 🩹 best practices (#36653)
This document was mentioning `plaster` keys with the wrong name.
2026-05-22 15:21:13 +01:00
cdesouza-chromium a651e03a79 [plaster] Introducing a 🩹 YAML frontend (#36651)
This PR introduces the YAML frontend for plaster that is meant to
eventually become the only frontend, once all `.toml` Plaster files are
migrated.

This change covers all places where the assumption about `.toml` files
was being used, inclusing `brockit`, and `git-cr` tools.

Most of the code that should be deleted in the future is well guarded
with comments leading back to the issue tracking, so the TOML parser can
be dropped eventually.

With this change, a dependency to `pyyaml` has been introduced. This
dependency has wheels provided by `vpython`, which is already the
expected python runtime for Plaster.

 - Rationale for this change

We have experimented at length with `.toml` files, in order to
understand some of the shortcomings they have that would be addressed
with `.yaml` files.

 * `prettier` offers YAML formatting out-of-the-box. On the other hand,
   formatters for TOML files are not easy to find, as both `prettier`
   and `vpython` have their own challanges with the current options
 * YAML's sytanx works better with codeblocks, as it doesn't require
   quoting. This makes the content seen less noisy. Looking on some of
   the migrated plasters, the YAML substitutions look more readable.
 * YAML has better sytanx highlight support in some editors.

Bug: https://github.com/brave/brave-browser/issues/55738
2026-05-22 15:20:51 +01:00
Aleksei Khoroshilov 050ac1649b Remove TA-007, it was an upstream bug. (#36644)
Remove outdated best practice. It was an upstream bug.

https://issues.chromium.org/issues/482060882
2026-05-22 16:33:44 +07:00
Serg eb5146d630 Updates Android best practices to prefer using Material design components versus custom (#36575) 2026-05-20 12:56:01 -04:00
cdesouza-chromium 78129286ae [docs] Include docs/ to md auto-format (#36521)
This is in conformance with the guidelines that `.md` files under
`docs/` must use 80-columns.
2026-05-19 20:02:22 +01:00
Sangwoo Ko e2924e8944 Add documentation for tree tab session restore (#36506)
For the first step, add documentation explaining how the existing group
and split tab metadata is persisted across browser restarts.

Part of https://github.com/brave/brave-browser/issues/49792
2026-05-19 14:03:57 +09:00
Brian R. Bondy efcb8ecc11 Allow *ForTesting() methods as exception to ARCH-020 (#36487) 2026-05-15 18:24:27 +00:00
Sangwoo KoandCursor a1d24eda44 Add best practice: prefer AsViewClass/IsViewClass over static_cast for views (#36438)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-14 08:45:28 +00:00
Brian R. Bondy 6f91301cb0 Add best practice CS-070: Use *.mojom-forward.h in headers (#36219)
Add best practice: Use *.mojom-forward.h in headers

CS-070: prefer the auto-generated *.mojom-forward.h over the full
*.mojom.h bindings when a header only references mojom types as
pointers, references, or function parameters. Reduces compile times
and transitive dependencies.

Source: PR #35622 review comment by netzenbot.
2026-05-07 06:52:19 -04:00
Brian R. Bondy b3d33bcc98 Add best practice: factory return value must be stable across the browser session (#36217)
Adds ARCH-072 to docs/best-practices/architecture.md. A KeyedServiceFactory
may only return nullptr based on session-stable attributes (profile type,
buildflags, base::Feature). Gating creation on user-toggleable prefs forces
restarts and was repeatedly flagged in PR reviews.
2026-05-06 13:52:15 -04:00
Brian R. Bondy 5dab0eaa24 Remove BS-012 (redundant with gn check and CS-001) (#36147)
Remove BS-012 (already covered by gn check and CS-001)
2026-05-05 08:20:28 -04:00
Sangwoo KoandCursor f7462bebf9 Add best practice: TabStripModelObserver teardown (no manual RemoveObserver) (#36128)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-05 03:57:33 +09:00
NetzenbotandClaude Sonnet 4.6 f3465bb4fd Update best practices from upstream Chromium docs (#36084)
* Update best practices from upstream Chromium docs

Add three new rules sourced from upstream Chromium documentation:

- CS-070: Pointer/reference symbol positioning (T* not T *)
- CS-071: No Yoda conditions (foo == 0, not 0 == foo)
- TI-041: Feature flag combination testing with bitmask parameterization

Source URLs checked: Chromium C++ style guide, Chromium C++ testing
best practices, smart pointer guidelines, container guidelines,
componentization cookbook.

* Remove best practices covered by linting and formatting tools

CS-070 (pointer/reference positioning) is enforced by clang-format.
CS-071 (no Yoda conditions) is caught by clang-tidy.
Neither belongs in a human-facing best practices doc.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-05-01 18:43:20 -04:00
Aleksei Khoroshilov aebc47b822 Adjust python-related build system best practices. (#35943) 2026-04-27 14:30:52 -04:00
Brian R. Bondy a313ad3b2d Add best practice: No browser-process-only APIs in common/ directories (#35866) 2026-04-27 14:30:07 -04:00
Brian R. Bondy 8ea5a96ef4 Remove "Prefer const for Local Variables" best practice (#35882) 2026-04-24 16:51:35 -04:00
cdesouza-chromium 469b21a709 Add best practice: raw_ref<T> vs raw_ptr<T> for non-owning fields (CSM-036) (#35731) 2026-04-21 21:10:37 +01:00
Brian R. Bondy 4dd860c0ae Remove CSM-002 best practice (#35734) 2026-04-21 16:08:30 -04:00
Pete Miller c5cde404d4 Docs updates - introduce Running Tests, introduce Web UI Frontend, small fixes (#35231)
* Docs updates

- New test suites doc (how to run tests)
- New WebUI Frontend doc (basic introduction to Brave's different stack)
- Patches points to best practices
- bug fix in claude code skills doc
- Adjust docs/README.md to prioritize the index
- Preflight skill addition of missing test suites
2026-04-20 22:35:18 -07:00
Shivan bb00e0f82d Remove redundant docs section (#35640)
Accidental miss from https://github.com/brave/brave-core/pull/35637
2026-04-18 07:08:52 -04:00
Shivan f45d6502b9 Add crypto.md to docs/ (#35637) 2026-04-17 12:38:09 -07:00
Jackson 8a0d7c89bc Add detail to the premium account token docs (#35503) 2026-04-14 15:21:15 -04:00
Brian R. Bondy 73d4857336 Add premium account documentation (#35498)
Add premium account information
2026-04-14 14:39:15 -04:00
Anirudha Bose a667af3258 [Rewards] Make gate3 URL environment-aware via CLI switches (#34801)
* [Rewards] Make gate3 URL environment-aware via CLI switches

* Address review: network audit list, public_deps, CHECK

- Add gate3 prod and dev endpoints to network audit allowed list
- Move //base to public_deps in :constants (BS-024)
- Replace DCHECK with CHECK in GetGate3URL (CS-025)

* Fix broken tests

* Remove gate3 endpoints from network audit list

* Add gate3 endpoints to TLS pin list

* Replace auto with explicit type

* Refactor GetGate3URL tests into table-driven loop

* Move kEnvGate3Switch to header and use named constants in tests

* Add explicit default for gate3_url in RewardsEngineOptions

* Fix MaybeWarnSwitchValue comment to describe both log paths

* Remove gate3 entries from brave_network_audit_allowed_lists.h

* Simplify GetGate3URL to delegate to GetServicesDomain

* Use std::optional<std::string> for gate3_url instead of empty sentinel

* Rename brave_domains/constants.h/cc to urls.h/cc

* Switch to GURL in GetGate3URL

* Clean up review nits from gate3 env switch

* Add comment in brave_domains/urls.h
2026-04-14 23:05:38 +05:30
Anthony Tseng fa14702bf3 Split ARCH-062 into separate CUJ test and change detector rules (#35182)
ARCH-062 combined two distinct concerns under one heading, causing
the bot to demand CUJ InteractiveBrowserTest for non-UI code like
tab helpers and services. Split into:

- ARCH-062: CUJ tests required only for features with UI changes
- ARCH-062b: Avoid change detector tests (general testing guidance)

Clarify that non-UI components should use unit tests or browser tests
appropriate to the code rather than CUJ tests.
2026-04-03 18:55:26 +02:00
Kyle Den Hartog 0ae4cc76a5 Add --update-crate flag to update a single vendored tool crate (#34929)
* Add --update-crate flag to update a single vendored tool crate

Adds a --update-crate=<name>@<version> option to tools/crates/update.py
that updates one crate in-place without running cargo vendor. It downloads
the tarball directly from crates.io, replaces the vendor directory, patches
Cargo.lock, and regenerates .cargo-checksum.json. This avoids collateral
version bumps from a full re-vendor and is useful for targeted security
advisory fixes.

Exposes the flag via `npm run update_brave_tools_crates -- --update-crate=`.
2026-04-03 10:40:38 +13:00
Brian R. Bondy bb8e455038 Clarify best practice applicability and reduce upstream hallucinations (#35219)
* Clarify best practice applicability and reduce upstream hallucinations

- ARCH-020: Clarify rule applies to bypassing access control, not
  normal inheritance patterns (calling protected methods from subclasses)
- ARCH-062: Clarify CUJ test requirement applies to UI features, not
  backend services or infrastructure
- Review rules: Add explicit instruction to verify upstream code claims
  by reading actual files rather than relying on training data

* Update ARCH-020 friend class example to modern #define pattern

Replace outdated BRAVE_CLASS_NAME_H guidance with the current
chromium_src #define approach for adding friend declarations.
2026-04-02 13:36:07 -04:00
Anthony Tseng a23d6fd1ee Update ARCH-064 to clarify when Unowned User Data pattern is needed (#35175)
Self-contained tab features that don't need external retrieval can use
simple unique_ptr ownership in BraveTabFeatures. The Unowned User Data
pattern should only be used when external code needs to look up the
feature via a static From() method.
2026-04-02 13:09:36 -04:00
Brian R. Bondy 53985f7beb Update CSA-053: distinguish workarounds from permanent design decisions (#34996)
Clarify that CSA-053 only applies to temporary workarounds, not
permanent design decisions. Comments explaining why an alternative
API was not used due to a known limitation do not need TODO tracking
issues when the current code is the intended long-term solution.
2026-03-25 16:48:16 -04:00
Brian R. Bondy bdd31d10f5 Fix stale wiki link in patching docs (#35000)
The wiki content was moved into the docs folder, so the external
link to brave-browser/wiki/Patching-Chromium#making-methods-virtual
now just redirects. Use a local anchor instead.
2026-03-25 15:14:04 -04:00
Brian R. Bondy 92aae1ccc6 Update network endpoint best practices (#34906)
Clarify that network auditor entries are only needed for
endpoints that do not require user opt-in. Add new best
practice (BS-056) requiring all new Brave endpoints be
added to the HSTS pin list.
2026-03-24 08:44:56 -04:00
Brian R. Bondy 0b14f04c96 Remove ARCH-052 mojom default values best practice (#34912)
Mojom code generation already value-initializes all struct fields
via the default constructor, making explicit defaults redundant.
2026-03-24 08:22:20 -04:00
Sangwoo Ko ce0f439a19 [Tree Tabs] Support tab groups in tree tab strip (#34826)
* Support tab groups in tree tab strip

Integrate tab groups with the tree tab strip so that groups are represented
as a single tree node wrapping the group (not one tree node per tab). Tabs
inside a group remain direct children of the group collection.

Collection and delegate:
- BraveTreeTabStripCollectionDelegate: When adding a tab with new_group_id,
  add to collection without wrapping in a tree node; the group wraps it.
  MoveTabsRecursive: handle empty tab_indices (no-op when moving within same
  group), and route move-out-of-group and move-into-group to new helpers.
- MoveTabsIntoGroup: unwrap tabs from tree nodes (or detach from other
  groups), add to target group; when group is detached (new group), wrap
  group in a TreeTabNode and attach at the correct tree position.
- MoveTabsOutOfGroup: move tabs from TabGroupTabCollection back into the
  tree by wrapping each in a tree node at the destination index.
- BraveTabStripCollection: add PopDetachedGroupCollectionForDelegate and
  GetTreeTabNodeIdForGroup; chromium_src TabStripCollection gains virtual
  GetTreeTabNodeIdForGroup. BraveTabStripCollectionDelegate implements
  GetTreeTabNodeIdForGroup.

TreeTabNodeTabCollection:
- BuildTreeTabs: wrap entire groups in one tree node (processed_groups set);
  grouped tabs stay as direct children of the group.
- New constructor that wraps a TabGroupTabCollection (for creating a group
  in tree mode). Single-tab constructor allows null for GetEmptyTreeTabNode
  when a tab was moved into a group and the view still holds the old node id.

Model, controller, and UI:
- BraveTabStripModel::GetTreeTabNodeIdForGroup returns the tree node id for
  a group (or nullptr if tree tabs off). Wired through controller and
  BraveTabStripCollection.
- BraveBrowserTabStripController::GetTreeTabNode returns GetEmptyTreeTabNode()
  when the node is null (e.g. tab just moved into group, before
  TabGroupedStateChanged/AddTabToGroup updates the view).
- OnTreeTabChanged: handle tab index kNoTab and detached state during group
  creation; avoid double-clearing when AddTabToGroup will clear the node id.
- BraveTabStrip::AddTabToGroup override sets the tab's tree_tab_node from
  GetTreeTabNodeIdForGroup when adding to a group in tree mode.
2026-03-24 11:18:48 +01:00
Mihai PLESA ae8356fda8 readme migrate from b-b (#34734) 2026-03-23 09:27:39 -07:00
Brian R. Bondy 54d0a15d3a Add best practice: keep PRs focused on a single purpose (#34891) 2026-03-23 11:11:47 -04:00
Anthony Tseng c11e31c388 Add best practice: don't rely on implicit const char* to string_view for non-null-terminated data (#34866) 2026-03-20 13:37:45 -07:00
Brian R. BondyandClaude Opus 4.6 1f1b6b01cb Update TUF-004: don't use sanitizer-specific filters when upstream flakes broadly (#34874)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-20 14:20:59 -04:00
Netzenbot 5bb907f22d Add best practices doc for handling upstream docs (#34864)
Add upstream test failures best practices doc

Consolidates upstream-flake filter guidance from testing-isolation.md
(TI-031, TI-032, TI-041, TI-042, TI-043) and patches.md (PATCH-011)
into a dedicated testing-upstream-failures.md. Expands the flake-check
section with full script usage and the LUCI verdict table.
2026-03-20 12:22:23 -04:00
Netzenbot 249704cfca Rename BEST-PRACTICES.md to best_practices.md (#34861)
Update all internal references in skill docs.
2026-03-20 11:23:36 -04:00
Anthony Tseng 5947ff35a8 Revert "Add best practice: use base::as_string_view() for compile-time string length" (#34853)
Revert "Add best practice: use base::as_string_view() for compile-time string…"

This reverts commit 20abc50120.
2026-03-20 11:05:43 +00:00
Anthony Tseng 20abc50120 Add best practice: use base::as_string_view() for compile-time string length (#34838)
Add best practice: use base::as_string_view() for compile-time string length (#34830)
2026-03-19 11:09:40 -07:00
Sangwoo Ko b7a3eeb712 [Tree Tabs] Add split tab support for tree tabs (#34659)
* Add split tab support for tree tabs

In order to support split tabs in tree tabs, mainly we need to reimplment
two methods - CreateSplit and Unsplit.

For CreateSplit, we need to wrap the split tabs in a tree node, and insert it
at the position.
For Unsplit, we need to extract the tabs back to the tree nodes.

- TabStripCollection: virtual CreateSplit, Unsplit, AddCollectionMapping,
  RemoveCollectionMapping; AddTabCollectionAtPosition for delegate.

- BraveTabStripCollection(delegate): override CreateSplit/Unsplit and
  AddCollectionMapping/RemoveCollectionMapping; PassKey overloads for
  AddTabCollectionAtPosition and collection mapping.

- BraveTreeTabStripCollectionDelegate: implement CreateSplit (wrap split in
  tree node, insert at position), Unsplit (extract tabs back to tree nodes),
  AddCollectionMapping/RemoveCollectionMapping for TREE_NODE holding split/group;
  MoveTabsRecursive same-position handling for split/group creation.

- Tab strip API: handle TREE_NODE in tab_converters (unpinned container).

- Docs: tree tabs + split tabs flow and MoveTabsRecursive behavior.
2026-03-17 16:02:52 +09:00
Brian R. Bondy e88f2476b2 Add best practice: use public to restrict header visibility (#34743) 2026-03-15 13:55:46 -04:00
Brian R. Bondy 628bd598c7 Update best practices for feature flags and buildflag confusion (#34722)
* Update best practice: feature flags for significant or experimental features

* Update best practice: clarify buildflag vs feature flag confusion
2026-03-13 18:26:40 -04:00
Brian R. Bondy 8b74765985 Add best practice: PRs should include reasonable test coverage (#34696)
* Add best practice: PRs should include reasonable test coverage

* Add best practice: Use chromium_src include pattern to test upstream overrides
2026-03-12 23:11:13 -04:00
AlexeyBarabash e8302c177f Android settings search indexes (#34576)
Added support for search indexes for Brave preferences fragments
2026-03-12 23:20:56 +02:00
Brian R. Bondy 391da523ab Add Claude skills documentation (#34603) 2026-03-10 10:53:54 -04:00
Aleksei Khoroshilov ce76e01a49 Support contained tabs session restore and sync. (#33313)
* Support contained tabs session restore and sync.

* Review fixes.

* Use struct as a return value instead of optional with out args.

* Add a unit test for view-source: scheme.

* Move TabRestore helper to components.

* Add containers-specific SerializedNavigationBuilder* tests.

* Guard PageState.top.url_string use.

* Add plaster files for few patches.

* Replace browser_tabrestore.cc #define patch with plaster rewrite.

* Replace content_serialized_navigation_builder.cc change with rewrite.

* Fix gn check.

* Add prefix_length check.

* Improve rewrite rules.

* Guard PageState changes with buildflag.

* Rename StoragePartitionKeyToUrlPrefix.

* Add buildflag check into SerializedNavigationEntry.

* Fix build issues with containers buildflag disabled.

* Fix iOS build.
2026-03-10 19:20:50 +07:00
Brian R. Bondy 66d25b65b5 Import best-practice docs from brave-experiments/brave-core-tools (#34568) 2026-03-09 14:15:22 -04:00
Brian Johnson a9fa852335 Add link to plaster best practices in plaster.md (#34517) 2026-03-06 13:43:03 +00:00