Skip to content

Commit

Permalink
traffic_counters: Remove all auto reset enabled code
Browse files Browse the repository at this point in the history
This code was originally added to support the toggle functionality for traffic counters. Since the toggle functionality is no longer supported,  remove it from the UX and model. See bug for additional details.

BUG=b:324745923
TEST=existing unit tests

Change-Id: Ica2e50b93db3814ccfd5eae5a3cb043f8a1f8aa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5284327
Reviewed-by: Steven Bennetts <[email protected]>
Reviewed-by: Ashley Prasad <[email protected]>
Reviewed-by: Alex Gough <[email protected]>
Reviewed-by: Artem Sumaneev <[email protected]>
Commit-Queue: Kartik Hegde <[email protected]>
Reviewed-by: Kyle Horimoto <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1268015}
  • Loading branch information
krh26 authored and Chromium LUCI CQ committed Mar 4, 2024
1 parent 0bac784 commit 29bf040
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 407 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface Network {
counters: TrafficCounter[];
lastResetTime: Time|null;
friendlyDate: string|null;
autoReset: boolean;
userSpecifiedResetDay: number;
}

Expand All @@ -40,7 +39,6 @@ function createNetwork(
counters: TrafficCounter[],
lastResetTime: Time|null,
friendlyDate: string|null,
autoReset: boolean,
userSpecifiedResetDay: number): Network {
return {
guid: guid,
Expand All @@ -49,7 +47,6 @@ function createNetwork(
counters: counters,
lastResetTime: lastResetTime,
friendlyDate: friendlyDate,
autoReset: autoReset,
userSpecifiedResetDay: userSpecifiedResetDay,
};
}
Expand Down Expand Up @@ -84,14 +81,11 @@ export class TrafficCountersAdapter {
await this.requestLastResetTimeForNetwork(networkState.guid);
const friendlyDate =
await this.requestFriendlyDateForNetwork(networkState.guid);
const autoReset =
await this.requestEnableAutoResetBooleanForNetwork(networkState.guid);
const userSpecifiedResetDay =
await this.requestUserSpecifiedResetDayForNetwork(networkState.guid);
networks.push(createNetwork(
networkState.guid, networkState.name, networkState.type,
trafficCounters, lastResetTime, friendlyDate, autoReset,
userSpecifiedResetDay));
trafficCounters, lastResetTime, friendlyDate, userSpecifiedResetDay));
}
return networks;
}
Expand Down Expand Up @@ -142,19 +136,6 @@ export class TrafficCountersAdapter {
null;
}

/**
* Requests enable traffic counters auto reset boolean for the given network.
*/
async requestEnableAutoResetBooleanForNetwork(
guid: string): Promise<boolean> {
const managedPropertiesPromise =
await this.networkConfig_.getManagedProperties(guid);
if (!managedPropertiesPromise || !managedPropertiesPromise.result) {
return false;
}
return managedPropertiesPromise.result.trafficCounterProperties.autoReset;
}

/**
* Requests user specified reset day for the given network.
*/
Expand All @@ -171,11 +152,8 @@ export class TrafficCountersAdapter {
/**
* Sets values for auto reset.
*/
async setTrafficCountersAutoResetForNetwork(
guid: string,
autoReset: boolean,
resetDay: UInt32Value|null): Promise<void> {
await this.networkConfig_.setTrafficCountersAutoReset(
guid, autoReset, resetDay);
async setTrafficCountersResetDayForNetwork(
guid: string, resetDay: UInt32Value|null): Promise<void> {
await this.networkConfig_.setTrafficCountersResetDay(guid, resetDay);
}
}
3 changes: 0 additions & 3 deletions chrome/browser/ash/net/traffic_counters_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,6 @@ class TrafficCountersHandlerTest : public ::testing::Test {
base::Value(shill::kStateOnline));
helper_->profile_test()->AddService(
NetworkProfileHandler::GetSharedProfilePath(), wifi_path_);
NetworkHandler::Get()
->network_metadata_store()
->SetEnableTrafficCountersAutoReset(wifi_guid_, false);
task_environment_.RunUntilIdle();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,10 @@ void FakeCrosNetworkConfigBase::ResetTrafficCounters(const std::string& guid) {
NOTREACHED();
}

void FakeCrosNetworkConfigBase::SetTrafficCountersAutoReset(
void FakeCrosNetworkConfigBase::SetTrafficCountersResetDay(
const std::string& guid,
bool auto_reset,
chromeos::network_config::mojom::UInt32ValuePtr day,
SetTrafficCountersAutoResetCallback callback) {
SetTrafficCountersResetDayCallback callback) {
NOTREACHED();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ class FakeCrosNetworkConfigBase
void RequestTrafficCounters(const std::string& guid,
RequestTrafficCountersCallback callback) override;
void ResetTrafficCounters(const std::string& guid) override;
void SetTrafficCountersAutoReset(
void SetTrafficCountersResetDay(
const std::string& guid,
bool auto_reset,
chromeos::network_config::mojom::UInt32ValuePtr day,
SetTrafficCountersAutoResetCallback callback) override;
SetTrafficCountersResetDayCallback callback) override;
void CreateCustomApn(const std::string& network_guid,
chromeos::network_config::mojom::ApnPropertiesPtr apn,
CreateCustomApnCallback callback) override;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,14 @@
</div>
<div id="data-usage-wrapper">
<div class="start settings-box-text" aria-hidden="true">
<div id="autoDataUsageResetLabel">
[[i18n('TrafficCountersDataUsageEnableAutoResetLabel')]]
</div>
<div class="secondary" id="autoDataUsageResetSubLabel">
[[i18n('TrafficCountersDataUsageEnableAutoResetSublabel')]]
<div id="daySelectionLabel">
[[i18n('TrafficCountersDataUsageAutoResetDayOfMonthLabel')]]
</div>
</div>
<div class="separator"></div>
<cr-toggle id="autoDataUsageResetToggle" checked="[[autoReset_]]"
aria-labelledby="autoDataUsageResetLabel"
aria-describedby="autoDataUsageResetSubLabel"
on-change="onAutoDataUsageResetToggle_">
</cr-toggle>
<cr-input id="daySelectionInput" type="number" value="{{resetDay_}}"
max="31" min="1" on-change="onResetDaySelected_">
</cr-input>
</div>
<template is="dom-if" if="[[autoReset_]]" restamp>
<div id="data-usage-wrapper">
<div class="start settings-box-text" aria-hidden="true">
<div id="daySelectionLabel">
[[i18n('TrafficCountersDataUsageAutoResetDayOfMonthLabel')]]
</div>
</div>
<div class="separator"></div>
<cr-input id="daySelectionInput" type="number" value="{{resetDay_}}"
max="31" min="1" on-change="onResetDaySelected_">
</cr-input>
</div>
</template>
</div>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,15 @@ export class SettingsTrafficCountersElement extends
type: String,
value: '',
},
/** Tracks whether auto reset is enabled. */
autoReset_: {
type: Boolean,
value: false,
},
/** Tracks the user specified day of reset. Default is 1. */
resetDay_: {
type: Number,
value: 1,
value: DEFAULT_RESET_DAY,
},
};
}

guid: string;
private autoReset_: boolean;
private date_: string;
private resetDay_: number;
private trafficCountersAdapter_: TrafficCountersAdapter;
Expand All @@ -130,7 +124,7 @@ export class SettingsTrafficCountersElement extends
this.populateTrafficCountersAvailable_();
this.populateDate_();
this.populateDataUsageValue_();
this.populateAutoResetValues_();
this.populateUserSpecifiedResetDay_();
}

/**
Expand Down Expand Up @@ -217,66 +211,27 @@ export class SettingsTrafficCountersElement extends
}

/**
* Populates the auto reset enable and day values.
*/
private populateAutoResetValues_(): void {
this.populateEnableAutoResetBoolean_();
this.populateUserSpecifiedResetDay_();
}

/**
* Determines whether auto reset is enabled.
*/
private async populateEnableAutoResetBoolean_(): Promise<void> {
const result = await this.populateEnableAutoResetBooleanHelper_();
this.autoReset_ = result;
}

/**
* Gathers auto reset enable information.
*/
private async populateEnableAutoResetBooleanHelper_(): Promise<boolean> {
const network = await this.getNetworkIfAvailable_();
return network ? network.autoReset : false;
}

/**
* Determines the auto reset day.
* Determines the reset day.
*/
private async populateUserSpecifiedResetDay_(): Promise<void> {
const result = await this.populateUserSpecifiedResetDayHelper_();
this.resetDay_ = result;
}

/**
* Gathers the auto reset day information.
* Gathers the reset day information (helper).
*/
private async populateUserSpecifiedResetDayHelper_(): Promise<number> {
const network = await this.getNetworkIfAvailable_();
return network ? network.userSpecifiedResetDay : DEFAULT_RESET_DAY;
}

/**
* Handles the auto reset toggle changes.
*/
private onAutoDataUsageResetToggle_(): void {
this.autoReset_ = !this.autoReset_;
this.resetDay_ = 1;
const day = this.autoReset_ ? {value: this.resetDay_} : null;
this.trafficCountersAdapter_.setTrafficCountersAutoResetForNetwork(
this.guid, this.autoReset_, day);
this.load();
}

/**
* Handles day of reset changes.
*/
private onResetDaySelected_(): void {
if (!this.autoReset_) {
return;
}
this.trafficCountersAdapter_.setTrafficCountersAutoResetForNetwork(
this.guid, this.autoReset_, {value: this.resetDay_});
this.trafficCountersAdapter_.setTrafficCountersResetDayForNetwork(
this.guid, {value: this.resetDay_});
this.load();
}
}
Expand Down
16 changes: 5 additions & 11 deletions chrome/test/data/webui/chromeos/fake_network_config_mojom.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ export class FakeNetworkConfig {
/** @private {!Map<string, !Array<!Object>>} */
this.trafficCountersMap_ = new Map();

/** @private {!Map<string, !Array<!Object>>} */
this.autoResetValuesMap_ = new Map();

/** @private {!number} */
this.apnIdCounter_ = 0;

Expand Down Expand Up @@ -151,7 +148,7 @@ export class FakeNetworkConfig {
'setProperties', 'setCellularSimState', 'selectCellularMobileNetwork',
'startConnect', 'startDisconnect', 'configureNetwork', 'forgetNetwork',
'getAlwaysOnVpn', 'getSupportedVpnTypes', 'requestTrafficCounters',
'resetTrafficCounters', 'setTrafficCountersAutoReset', 'removeCustomApn',
'resetTrafficCounters', 'setTrafficCountersResetDay', 'removeCustomApn',
'createCustomApn', 'createExclusivelyEnabledCustomApn', 'modifyCustomApn']
.forEach((methodName) => {
this.resolverMap_.set(methodName, new PromiseResolver());
Expand Down Expand Up @@ -783,17 +780,15 @@ export class FakeNetworkConfig {

/**
* @param {string} guid
* @param {boolean} autoReset
* @param {?UInt32Value} resetDay
*/
setAutoResetValues_(guid, autoReset, resetDay) {
setResetDay_(guid, resetDay) {
const network = this.networkStates_.find(state => {
return state.guid === guid;
});
assert(!!network, 'Network not found: ' + guid);
const managed = this.managedProperties_.get(guid);
if (managed) {
managed.trafficCounterProperties.autoReset = autoReset;
managed.trafficCounterProperties.userSpecifiedResetDay =
resetDay ? resetDay.value : 1;
}
Expand All @@ -802,13 +797,12 @@ export class FakeNetworkConfig {

/**
* @param {string} guid
* @param {boolean} autoReset
* @param {?UInt32Value} resetDay
*/
setTrafficCountersAutoReset(guid, autoReset, resetDay) {
setTrafficCountersResetDay(guid, resetDay) {
return new Promise(resolve => {
this.methodCalled('setTrafficCountersAutoReset');
this.setAutoResetValues_(guid, autoReset, resetDay);
this.methodCalled('setTrafficCountersResetDay');
this.setResetDay_(guid, resetDay);
resolve(true);
});
}
Expand Down
Loading

0 comments on commit 29bf040

Please sign in to comment.