-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Files] Implement methods to update the store when going online/offline
When the device connection status changes, this status gets updated in the store along with the `isDisabled` state of ODFS, when relevant. Bug: b:293547300 Change-Id: I909012211b922530d09990dd9f9781eea5318931 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4790552 Reviewed-by: Luciano Pacheco <lucmult@chromium.org> Commit-Queue: Jeremie Boulic <jboulic@chromium.org> Cr-Commit-Position: refs/heads/main@{#1188151}
- Loading branch information
Jérémie Boulic
authored and
Chromium LUCI CQ
committed
Aug 25, 2023
1 parent
5cd22ad
commit 13d0563
Showing
9 changed files
with
166 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {util} from '../../common/js/util.js'; | ||
import {State, Volume} from '../../externs/ts/state.js'; | ||
import {addReducer, BaseAction, Reducer, ReducersMap} from '../../lib/base_store.js'; | ||
import {Action, ActionType} from '../actions.js'; | ||
|
||
/** Map of actions to reducers for the device slice. */ | ||
export const deviceReducersMap: ReducersMap<State, Action> = new Map(); | ||
|
||
/** Action to update the device connection state in the store. */ | ||
export interface UpdateDeviceConnectionStateAction extends BaseAction { | ||
type: ActionType.UPDATE_DEVICE_CONNECTION_STATE; | ||
payload: { | ||
connection: chrome.fileManagerPrivate.DeviceConnectionState, | ||
}; | ||
} | ||
|
||
function updateDeviceConnectionStateReducer( | ||
currentState: State, | ||
payload: UpdateDeviceConnectionStateAction['payload']): State { | ||
let device: State['device']|undefined; | ||
let volumes: State['volumes']|undefined; | ||
|
||
// Device connection. | ||
if (payload.connection !== currentState.device.connection) { | ||
device = { | ||
...currentState.device, | ||
connection: payload.connection, | ||
}; | ||
} | ||
|
||
// Find ODFS volume(s) and disable it (or them) if offline. | ||
const disableODFS = payload.connection === | ||
chrome.fileManagerPrivate.DeviceConnectionState.OFFLINE; | ||
for (const volume of Object.values<Volume>(currentState.volumes)) { | ||
if (!util.isOneDriveId(volume.providerId) || | ||
volume.isDisabled === disableODFS) { | ||
continue; | ||
} | ||
if (!volumes) { | ||
volumes = { | ||
...currentState.volumes, | ||
}; | ||
} | ||
volumes[volume.volumeId] = { | ||
...volumes[volume.volumeId], | ||
isDisabled: disableODFS, | ||
}; | ||
} | ||
|
||
if (!device && !volumes) { | ||
return currentState; | ||
} | ||
|
||
const newState = { | ||
...currentState, | ||
}; | ||
|
||
if (device) { | ||
newState.device = device; | ||
} | ||
|
||
if (volumes) { | ||
newState.volumes = volumes; | ||
} | ||
|
||
return newState; | ||
} | ||
|
||
export const updateDeviceConnectionState = addReducer( | ||
ActionType.UPDATE_DEVICE_CONNECTION_STATE, | ||
updateDeviceConnectionStateReducer as Reducer<State, Action>, | ||
deviceReducersMap); |
62 changes: 62 additions & 0 deletions
62
ui/file_manager/file_manager/state/ducks/device_unittest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {assertEquals, assertFalse} from 'chrome://webui-test/chromeos/chai_assert.js'; | ||
|
||
import {MockVolumeManager} from '../../background/js/mock_volume_manager.js'; | ||
import {VolumeManagerCommon} from '../../common/js/volume_manager_types.js'; | ||
import {State} from '../../externs/ts/state.js'; | ||
import {constants} from '../../foreground/js/constants.js'; | ||
import {createFakeVolumeMetadata, setupStore, waitDeepEquals} from '../for_tests.js'; | ||
import {getEmptyState, getStore, Store} from '../store.js'; | ||
|
||
import {updateDeviceConnectionState} from './device.js'; | ||
import {convertVolumeInfoAndMetadataToVolume} from './volumes.js'; | ||
|
||
let store: Store; | ||
|
||
export function setUp() { | ||
store = getStore(); | ||
store.init(getEmptyState()); | ||
} | ||
|
||
export async function testUpdateDeviceConnection(done: () => void) { | ||
const volumeInfo = MockVolumeManager.createMockVolumeInfo( | ||
VolumeManagerCommon.VolumeType.PROVIDED, 'odfs', 'OneDrive', '', | ||
constants.ODFS_EXTENSION_ID, ''); | ||
const ODFSVolume = convertVolumeInfoAndMetadataToVolume( | ||
volumeInfo, createFakeVolumeMetadata(volumeInfo)); | ||
|
||
const initialState = getEmptyState(); | ||
initialState.volumes[ODFSVolume.volumeId] = ODFSVolume; | ||
const store = setupStore(initialState); | ||
|
||
assertEquals( | ||
chrome.fileManagerPrivate.DeviceConnectionState.ONLINE, | ||
store.getState().device.connection); | ||
assertFalse(store.getState().volumes[ODFSVolume.volumeId].isDisabled); | ||
|
||
// Dispatch an action to set |connection| for the device to OFFLINE. | ||
store.dispatch(updateDeviceConnectionState({ | ||
connection: chrome.fileManagerPrivate.DeviceConnectionState.OFFLINE, | ||
})); | ||
|
||
// Expect the volume to be set to disabled. | ||
const want: Partial<State> = { | ||
volumes: { | ||
[ODFSVolume.volumeId]: { | ||
...ODFSVolume, | ||
isDisabled: true, | ||
}, | ||
}, | ||
}; | ||
await waitDeepEquals(store, want, (state) => ({ | ||
volumes: state.volumes, | ||
})); | ||
assertEquals( | ||
chrome.fileManagerPrivate.DeviceConnectionState.OFFLINE, | ||
store.getState().device.connection); | ||
|
||
done(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters