Skip to content

Commit

Permalink
compute pressure: Remove Factors from compute pressure
Browse files Browse the repository at this point in the history
Due to fingerprinting concerns, it was decided to not expose
contributing factors. [1]

[1] w3c/compute-pressure#203

Bug: 1428859, 1365627
Change-Id: If90b2c27e04076795a77ff0d255c5a3a05e220ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4381885
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Raphael Kubo Da Costa <raphael.kubo.da.costa@intel.com>
Commit-Queue: Arnaud Mandy <arnaud.mandy@intel.com>
Cr-Commit-Position: refs/heads/main@{#1131804}
  • Loading branch information
arskama authored and chromium-wpt-export-bot committed Apr 18, 2023
1 parent 0db23bf commit 3aa2368
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,3 @@ pressure_test(async (t, mockPressureService) => {
assert_equals(pressureChanges[0][0].state, 'critical');
assert_equals(pressureChanges[1][0].state, 'nominal');
}, 'Changes that fail the "has change in data" test are discarded.');

pressure_test(async (t, mockPressureService) => {
const pressureChanges = await new Promise(async resolve => {
const observer_changes = [];
let n = 0;
const observer = new PressureObserver(changes => {
observer_changes.push(changes);
if (++n === 2)
resolve(observer_changes);
}, {sampleRate: 5.0});
observer.observe('cpu');
const updatesDelivered = mockPressureService.updatesDelivered();
mockPressureService.setPressureUpdate('cpu', 'critical', ['thermal']);
mockPressureService.startPlatformCollector(/*sampleRate*/ 5.0);

// Deliver 2 updates.
await t.step_wait(
() => mockPressureService.updatesDelivered() >= (updatesDelivered + 2),
'Wait for more than one update to be delivered to the observer');
mockPressureService.setPressureUpdate('cpu', 'critical', ['power-supply']);
// Deliver more updates, |resolve()| will be called when the new pressure
// state reaches PressureObserver and its callback is invoked
// for the second time.
});
assert_equals(pressureChanges.length, 2);
assert_equals(pressureChanges[0][0].state, 'critical');
assert_equals(pressureChanges[0][0].factors[0], 'thermal');
assert_equals(pressureChanges[1][0].state, 'critical');
assert_equals(pressureChanges[1][0].factors[0], 'power-supply');
}, 'Factors that fail the "has change in data" test are discarded.');
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ pressure_test(async (t, mockPressureService) => {
const observer = new PressureObserver(resolve);
t.add_cleanup(() => observer.disconnect());
observer.observe('cpu');
mockPressureService.setPressureUpdate('cpu', 'critical', ['thermal']);
mockPressureService.setPressureUpdate('cpu', 'critical');
mockPressureService.startPlatformCollector(/*sampleRate=*/ 5.0);
});
assert_true(changes.length === 1);
assert_equals(changes[0].state, 'critical');
assert_equals(changes[0].source, 'cpu');
assert_equals(typeof changes[0].time, 'number');
assert_equals(changes[0].factors[0], 'thermal');
}, 'Basic factors functionality test');
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ pressure_test(async (t, mockPressureService) => {
const changes = await new Promise(resolve => {
const observer = new PressureObserver(resolve);
observer.observe('cpu');
mockPressureService.setPressureUpdate('cpu', 'critical', ['thermal']);
mockPressureService.setPressureUpdate('cpu', 'critical');
mockPressureService.startPlatformCollector(/*sampleRate=*/ 5.0);
});
assert_true(changes.length === 1);
const json = changes[0].toJSON();
assert_equals(json.state, 'critical');
assert_equals(json.source, 'cpu');
assert_equals(json.factors[0], 'thermal');
assert_equals(typeof json.time, 'number');
}, 'Basic functionality test');
18 changes: 2 additions & 16 deletions resources/chromium/mock-pressure-service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {PressureManager, PressureManagerReceiver, PressureStatus} from '/gen/services/device/public/mojom/pressure_manager.mojom.m.js'
import {PressureFactor, PressureSource, PressureState} from '/gen/services/device/public/mojom/pressure_update.mojom.m.js'
import {PressureSource, PressureState} from '/gen/services/device/public/mojom/pressure_update.mojom.m.js'

class MockPressureService {
constructor() {
Expand All @@ -15,10 +15,6 @@ class MockPressureService {
['nominal', PressureState.kNominal], ['fair', PressureState.kFair],
['serious', PressureState.kSerious], ['critical', PressureState.kCritical]
]);
this.mojomFactorType_ = new Map([
['thermal', PressureFactor.kThermal],
['power-supply', PressureFactor.kPowerSupply]
]);
this.pressureServiceReadingTimerId_ = null;
}

Expand Down Expand Up @@ -109,26 +105,16 @@ class MockPressureService {
return this.updatesDelivered_;
}

setPressureUpdate(source, state, factors) {
setPressureUpdate(source, state) {
if (!this.mojomSourceType_.has(source))
throw new Error(`PressureSource '${source}' is invalid`);

if (!this.mojomStateType_.has(state))
throw new Error(`PressureState '${state}' is invalid`);

let pressureFactors = [];
if (Array.isArray(factors)) {
for (const factor of factors) {
if (!this.mojomFactorType_.has(factor))
throw new Error(`PressureFactor '${factor}' is invalid`);
pressureFactors.push(this.mojomFactorType_.get(factor));
}
}

this.pressureUpdate_ = {
source: this.mojomSourceType_.get(source),
state: this.mojomStateType_.get(state),
factors: pressureFactors,
};
}

Expand Down

0 comments on commit 3aa2368

Please sign in to comment.