Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled Performance features by default #17290

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ source_set("browser_tests") {
"//components/network_time",
"//components/omnibox/browser",
"//components/optimization_guide/core",
"//components/performance_manager",
"//components/permissions",
"//components/privacy_sandbox",
"//components/reading_list/features:flags",
Expand Down
3 changes: 3 additions & 0 deletions app/brave_main_delegate_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "components/omnibox/common/omnibox_features.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/performance_manager/public/features.h"
#include "components/permissions/features.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/reading_list/features/reading_list_switches.h"
Expand Down Expand Up @@ -216,6 +217,8 @@ IN_PROC_BROWSER_TEST_F(BraveMainDelegateBrowserTest, EnabledFeatures) {
&features::kWinrtGeolocationImplementation,
#endif
#if !BUILDFLAG(IS_ANDROID)
&performance_manager::features::kBatterySaverModeAvailable,
&performance_manager::features::kHighEfficiencyModeAvailable,
&safe_browsing::kDownloadBubble,
&safe_browsing::kDownloadBubbleV2,
&sharing_hub::kDesktopScreenshots,
Expand Down
9 changes: 9 additions & 0 deletions browser/resources/settings/brave_icons.html
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@
<path
d="M7 3a1 1 0 0 0-1 1v4H5c-1.65 0-3 1.35-3 3v4a2 2 0 0 0 2 2h2v2a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2v-2h2a2 2 0 0 0 2-2v-4c0-1.65-1.35-3-3-3h-1V4a1 1 0 0 0-2 0v4H8V4a1 1 0 0 0-1-1zm2.879 0a.563.563 0 0 0-.399.96l1.7 1.7a1.16 1.16 0 0 0 1.64 0l1.701-1.7a.564.564 0 0 0-.4-.96H9.879zM19 10c.6 0 1 .4 1 1s-.4 1-1 1-1-.4-1-1 .4-1 1-1zM8.5 14h7a.5.5 0 0 1 .5.5v4a.5.5 0 0 1-.5.5h-7a.5.5 0 0 1-.5-.5v-4a.5.5 0 0 1 .5-.5z" />
</g>
<g id="performance" viewBox="0 0 24 24">
<lineargradient id="selectedGradient" gradientTransform="rotate(314.2)">
<stop offset="8.49%" stop-color="var(--selected-gradient-color1, currentColor)"></stop>
<stop offset="43.72%" stop-color="var(--selected-gradient-color2, currentColor)"></stop>
<stop offset="99.51%" stop-color="var(--selected-gradient-color3, currentColor)"></stop>
</lineargradient>
<path fill-rule="evenodd" clip-rule="evenodd"
d="M20.5811 3.92439C20.5834 3.83443 20.5047 3.73931 20.3886 3.73911C11.8322 3.72448 7.68312 5.81571 5.85082 8.51885C4.0036 11.244 4.28826 14.9057 5.39465 18.5812C5.40733 18.6233 5.45393 18.6761 5.51842 18.6945C9.1441 19.7267 11.8285 19.6785 13.8225 19.0123C15.8023 18.3508 17.1901 17.0505 18.1786 15.3969C20.1927 12.0276 20.4951 7.29244 20.5811 3.92439ZM20.3913 2.13912C21.3798 2.14081 22.2065 2.95098 22.1806 3.96525C22.0955 7.29527 21.8096 12.4412 19.5519 16.2178C18.4046 18.1371 16.7357 19.7259 14.3295 20.5298C11.9648 21.32 8.97586 21.3228 5.2105 20.27L3.79381 21.6867C3.46116 22.0194 2.92183 22.0194 2.58918 21.6867C2.25653 21.3541 2.25653 20.8148 2.58918 20.4821L3.90505 19.1662C3.88941 19.1257 3.87521 19.0844 3.86256 19.0424C2.72584 15.2661 2.25185 10.9767 4.52641 7.62112C6.8159 4.24347 11.669 2.1242 20.3913 2.13912ZM13.8703 7.80786C14.1341 7.45346 14.0607 6.95227 13.7063 6.68844C13.3519 6.4246 12.8507 6.49802 12.5869 6.85242L9.17338 11.4376C8.99274 11.6803 8.96441 12.004 9.10018 12.2744C9.23594 12.5447 9.51257 12.7153 9.81508 12.7153H12.4709L11.17 16.0594C10.9357 16.434 11.0494 16.9276 11.424 17.1619C11.7986 17.3962 12.2922 17.2825 12.5265 16.9079L15.384 12.3396C15.5383 12.093 15.5465 11.7821 15.4056 11.5276C15.2646 11.2732 14.9967 11.1153 14.7058 11.1153H11.9674L13.8703 7.80786Z" />
</g>
<g id="close-circle" viewBox="0 0 32 32">
<lineargradient id="selectedGradient" gradientTransform="rotate(314.2)">
<stop offset="8.49%" stop-color="var(--selected-gradient-color1, currentColor)"></stop>
Expand Down
35 changes: 16 additions & 19 deletions browser/resources/settings/brave_overrides/basic_page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2020 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/.
// You can obtain one at https://mozilla.org/MPL/2.0/.

// @ts-nocheck TODO(petemill): Define types and remove ts-nocheck

Expand Down Expand Up @@ -75,20 +75,6 @@ function createNestedSectionElement(sectionName, nestedUnder, titleName, childNa
`
}


/**
* Creates a settings-toggle-button element and returns it.
* @param {string} pref - preference path to handle by toggle
* @param {string} label - label for the element
* @returns {Element}
*/
function createToggleButtonElement (pref, label) {
return html`
<settings-toggle-button class="cr-row" pref="{{${pref}}}" label="${loadTimeData.getString(label)}">
</settings-toggle-button>
`
}

RegisterStyleOverride(
'settings-basic-page',
html`
Expand Down Expand Up @@ -275,6 +261,21 @@ RegisterPolymerTemplateModifications({
prefs: '{{prefs}}'
}
))

// Remove all hidden performance options from basic page.
// We moved performance elements in system settings.
const performanceTemplate = actualTemplate.content.querySelector(
'template[if="[[showPerformancePage_(pageVisibility.performance)]]"]')
if (performanceTemplate) {
performanceTemplate.remove()
}

const batteryTemplate = actualTemplate.content.querySelector(
'template[if="[[showBatteryPage_(pageVisibility.performance)]]"]')
if (batteryTemplate) {
batteryTemplate.remove()
}

// Get Started at top
let last = basicPageEl.insertAdjacentElement('afterbegin',
sectionGetStarted)
Expand Down Expand Up @@ -329,10 +330,6 @@ RegisterPolymerTemplateModifications({
// Move help tips after downloads
const sectionDownloads = getSectionElement(advancedSubSectionsTemplate.content, 'downloads')
sectionDownloads.insertAdjacentElement('afterend', sectionHelpTips)
// Add an element to Chromium's system section
const buttonElement = createToggleButtonElement("prefs.brave.enable_closing_last_tab", "braveHelpTipsClosingLastTab")
const sectionSystem = getSectionElement(advancedSubSectionsTemplate.content, 'system')
sectionSystem.appendChild(buttonElement)
}
}
})
3 changes: 2 additions & 1 deletion browser/resources/settings/brave_overrides/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ OverrideIronIcons('settings', 'brave_settings', {
assignment: 'autofill',
language: 'language',
build: 'system',
restore: 'reset-settings'
restore: 'reset-settings',
performance: 'performance'
})
OverrideIronIcons('cr', 'brave_settings', {
security: 'privacy-security',
Expand Down
1 change: 1 addition & 0 deletions browser/resources/settings/brave_overrides/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ import './site_details.js'
import './site_settings_page.js'
import './sync_account_control.js'
import './sync_controls.js'
import './system_page.js'
7 changes: 7 additions & 0 deletions browser/resources/settings/brave_overrides/settings_menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ RegisterPolymerTemplateModifications({
} else {
menuEl.insertAdjacentElement('afterbegin', titleEl)
}

// Hide performance menu. We moved it under system menu instead.
const performanceEl = getMenuElement(templateContent, '/performance')
if (performanceEl) {
performanceEl.remove()
}

// Add 'Get Started' item
const peopleEl = getMenuElement(templateContent, '/people')
const getStartedEl = createMenuElement(
Expand Down
24 changes: 24 additions & 0 deletions browser/resources/settings/brave_overrides/system_page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2023 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/.

import {html, RegisterPolymerTemplateModifications} from 'chrome://resources/brave/polymer_overriding.js'
import {loadTimeData} from '../i18n_setup.js'
import '../brave_system_page/brave_performance_page.js'

RegisterPolymerTemplateModifications({
'settings-system-page': (templateContent) => {
templateContent.appendChild(
html`
<settings-toggle-button
class="cr-row"
pref="{{prefs.brave.enable_closing_last_tab}}"
label="${loadTimeData.getString("braveHelpTipsClosingLastTab")}">
</settings-toggle-button>

<settings-brave-performance-page prefs="{{prefs}}">
</settings-brave-performance-page>
`)
}
})
4 changes: 4 additions & 0 deletions browser/resources/settings/brave_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export default function addBraveRoutes(r: Partial<SettingsRoutes>) {
} else if (!isGuest) {
console.error('[Brave Settings Overrides] Could not move autofill route to advanced route', r)
}
// Deleted performance menu and system menu includes it instead.
if (r.PERFORMANCE) {
delete r.PERFORMANCE
bsclifton marked this conversation as resolved.
Show resolved Hide resolved
}
// Safety check route is moved to advanced.
if (r.SAFETY_CHECK && r.ADVANCED) {
r.SAFETY_CHECK.parent = r.ADVANCED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<style include="settings-shared cr-shared-style iron-flex">
.title {
font-size: 14px;
font-weight: 600;
height: 68px;
}
</style>

<template is="dom-if" if="[[showPerformancePage_()]]">
<div class="cr-row title">$i18n{performancePageTitle}</div>
<settings-performance-page prefs="{{prefs}}">
</settings-performance-page>
</template>

<template is="dom-if" if="[[showBatteryPage_()]]">
<div hidden="[[!showBatterySettings_]]">
<div class="cr-row title">$i18n{batteryPageTitle}</div>
<settings-battery-page prefs="{{prefs}}">
</settings-battery-page>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2023 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/.

import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'
import {WebUiListenerMixin, WebUiListenerMixinInterface} from 'chrome://resources/cr_elements/web_ui_listener_mixin.js'
import {BaseMixin} from '../base_mixin.js'
import {PerformanceBrowserProxy, PerformanceBrowserProxyImpl} from '../performance_page/performance_browser_proxy.js'
import {getTemplate} from './brave_performance_page.html.js'
import {pageVisibility} from '../page_visibility.js'
import {loadTimeData} from '../i18n_setup.js'
import '../performance_page/battery_page.js'
import '../performance_page/performance_page.js'

/**
* 'settings-brave-performance-page' is the settings page containing
* brave's performance features.
*/

const SettingsBravePerformancePageElementBase =
WebUiListenerMixin(BaseMixin(PolymerElement)) as {
new(): PolymerElement & WebUiListenerMixinInterface
}

export class SettingsBravePerformancePageElement
extends SettingsBravePerformancePageElementBase {
static get is() {
return 'settings-brave-performance-page'
}

static get template() {
return getTemplate()
}

static get properties() {
return {
/**
* Used to hide battery settings section if the device has no battery
*/
showBatterySettings_: {
type: Boolean,
value: false,
},
}
}

private showBatterySettings_: boolean;
private performanceBrowserProxy_: PerformanceBrowserProxy =
PerformanceBrowserProxyImpl.getInstance();

override connectedCallback() {
super.connectedCallback()

if (loadTimeData.getBoolean('batterySaverModeAvailable')) {
this.addWebUiListener(
'device-has-battery-changed',
this.onDeviceHasBatteryChanged_.bind(this))
this.performanceBrowserProxy_.getDeviceHasBattery().then(
this.onDeviceHasBatteryChanged_.bind(this))
}
}

private showPerformancePage_(): boolean {
return pageVisibility?.performance !== false &&
loadTimeData.getBoolean('highEfficiencyModeAvailable')
}

private showBatteryPage_(): boolean {
return pageVisibility?.performance !== false &&
loadTimeData.getBoolean('batterySaverModeAvailable')
}

private onDeviceHasBatteryChanged_(deviceHasBattery: boolean) {
this.showBatterySettings_ = deviceHasBattery
}
}

declare global {
interface HTMLElementTagNameMap {
'settings-brave-performance-page': SettingsBravePerformancePageElement
}
}

customElements.define(
SettingsBravePerformancePageElement.is, SettingsBravePerformancePageElement)
2 changes: 2 additions & 0 deletions browser/resources/settings/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ brave_settings_web_component_files = [
"brave_sync_page/brave_sync_page.ts",
"brave_sync_page/brave_sync_setup.ts",
"brave_sync_page/brave_sync_subpage.ts",
"brave_system_page/brave_performance_page.ts",
"brave_tor_page/brave_tor_bridges_dialog.ts",
"brave_tor_page/brave_tor_snowflake_install_failed_dialog.ts",
"brave_tor_page/brave_tor_subpage.ts",
Expand Down Expand Up @@ -85,6 +86,7 @@ brave_settings_non_web_component_files = [
"brave_overrides/settings_section.ts",
"brave_overrides/settings_ui.ts",
"brave_overrides/site_details.ts",
"brave_overrides/system_page.ts",
"brave_overrides/add_site_dialog.ts",
"brave_overrides/site_settings_page.ts",
"brave_overrides/sync_account_control.ts",
Expand Down
6 changes: 4 additions & 2 deletions chromium_src/chrome/common/url_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const char kAutomaticSettingsResetLearnMoreURL[] =
const char kAdvancedProtectionDownloadLearnMoreURL[] =
"https://support.brave.com/";

const char kBatterySaverModeLearnMoreUrl[] = "https://support.brave.com/";
const char kBatterySaverModeLearnMoreUrl[] =
"https://support.brave.com/hc/en-us/articles/13380606172557";

const char kBluetoothAdapterOffHelpURL[] =
"https://support.brave.com/";
Expand Down Expand Up @@ -139,7 +140,8 @@ const char kLearnMoreReportingURL[] =
"https://support.brave.com/hc/en-us/articles/"
"360017905872-How-do-I-enable-or-disable-automatic-crash-reporting-";

const char kHighEfficiencyModeLearnMoreUrl[] = "https://support.brave.com/";
const char kHighEfficiencyModeLearnMoreUrl[] =
"https://support.brave.com/hc/en-us/articles/13383683902733";

const char kManagedUiLearnMoreUrl[] = "https://support.brave.com/";

Expand Down
17 changes: 15 additions & 2 deletions chromium_src/chrome/common/webui_url_constants.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Copyright 2021 The Brave Authors. All rights reserved.
/* Copyright (c) 2021 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 http://mozilla.org/MPL/2.0/. */
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "brave/components/constants/webui_url_constants.h"
#include "chrome/common/webui_url_constants.h"
Expand All @@ -10,5 +10,18 @@
kChromeUIAttributionInternalsHost, kAdblockHost, kAdblockInternalsHost, \
kIPFSWebUIHost, kRewardsPageHost, kRewardsInternalsHost, kWelcomeHost, \
kWalletPageHost, kTorInternalsHost
#define kChromeUIPerformanceSettingsURL kChromeUIPerformanceSettingsURL_UnUsed
#define kPerformanceSubPage kPerformanceSubPage_UnUsed

#include "src/chrome/common/webui_url_constants.cc"

#undef kPerformanceSubPage
#undef kChromeUIPerformanceSettingsURL
#undef kChromeUIAttributionInternalsHost

namespace chrome {

const char kChromeUIPerformanceSettingsURL[] = "chrome://settings/system";
const char kPerformanceSubPage[] = "system";

} // namespace chrome
20 changes: 20 additions & 0 deletions chromium_src/components/performance_manager/features.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2023 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/. */

#include "src/components/performance_manager/features.cc"

#include "base/feature_override.h"
#include "build/build_config.h"

namespace performance_manager::features {

#if !BUILDFLAG(IS_ANDROID)
OVERRIDE_FEATURE_DEFAULT_STATES({{
{kBatterySaverModeAvailable, base::FEATURE_ENABLED_BY_DEFAULT},
{kHighEfficiencyModeAvailable, base::FEATURE_ENABLED_BY_DEFAULT},
}});
#endif

} // namespace performance_manager::features
13 changes: 13 additions & 0 deletions test/filters/unit_tests.filter
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@
# groups
-All/TabGroupViewsTest.UnderlineBoundsWhenTabsAreNotVisible/1

# These tests are disabled because of turning the performance features on.
# Re-enable when performance features are enabled by default from upstream.
# performance_manager::features::kBatterySaverModeAvailable,
# performance_manager::features::kHighEfficiencyModeAvailable
-AppMenuModelTest.DisabledPerformanceItem
-CLSUkmPageLoadMetricsObserverTest.BeforeInputOrScroll*
-HighEfficiencyModeTest.*
-OfflinePreviewsUKMPageLoadMetricsObserverTest.OfflinePreviewReported
-PageDiscardingHelperTest.*
-UkmPageLoadMetricsObserverWithMockTimeTest.LargestContentfulPaintRecordOnHidden
-UrgentPageDiscardingPolicyTest.DiscardOnCriticalPressure
-UrgentPageDiscardingPolicyTest.NoDiscardOnModeratePressure

# Tests below this point have not been diagnosed or had issues created yet.
-AboutFlagsHistogramTest.*
-AboutFlagsTest.*
Expand Down
Loading