0

[skyvault] Add lacros CloudFileSystemPathCache

- Added CloudFileSystemPathCache on Lacros that observes
both GoogleDrive and OneDrive mount points updates and
caches them for further uses on Lacros.
- Moved all the code for DriveFsCache to CloudFileSystemPathCache
since it's better to encapsulate it all there.

Bug: b/325897784
Change-Id: Idbddeb0cbef618cac75d270c023ca90d5266eba7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5331991
Reviewed-by: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: Erik Chen <erikchen@chromium.org>
Reviewed-by: Peter Marshall <petermarshall@chromium.org>
Commit-Queue: Aya Elsayed <ayaelattar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1267765}
This commit is contained in:
Aya ElAttar
2024-03-04 11:35:39 +00:00
committed by Chromium LUCI CQ
parent d740d3a15d
commit 2ee3189fd8
16 changed files with 163 additions and 87 deletions

@ -5554,6 +5554,8 @@ static_library("browser") {
"lacros/chrome_browser_main_extra_parts_lacros.h",
"lacros/clipboard_history_lacros.cc",
"lacros/clipboard_history_lacros.h",
"lacros/cloud_file_system_path_cache.cc",
"lacros/cloud_file_system_path_cache.h",
"lacros/debug_interface_lacros.cc",
"lacros/debug_interface_lacros.h",
"lacros/desk_profiles_lacros.cc",
@ -5566,8 +5568,6 @@ static_library("browser") {
"lacros/device_settings_lacros.h",
"lacros/download_controller_client_lacros.cc",
"lacros/download_controller_client_lacros.h",
"lacros/drivefs_cache.cc",
"lacros/drivefs_cache.h",
"lacros/drivefs_native_message_host_bridge_lacros.cc",
"lacros/drivefs_native_message_host_bridge_lacros.h",
"lacros/drivefs_native_message_host_lacros.cc",

@ -13,6 +13,7 @@
#include "chrome/browser/ash/file_manager/path_util.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ash/cloud_upload/cloud_upload_util.h"
#include "chrome/browser/web_applications/preinstalled_web_app_config_utils.h"
#include "chromeos/ash/components/dbus/cros_disks/cros_disks_client.h"
#include "chromeos/ash/components/install_attributes/install_attributes.h"
@ -101,6 +102,9 @@ mojom::DefaultPathsPtr EnvironmentProvider::GetDefaultPaths() {
integration_service->IsMounted()) {
default_paths->drivefs = integration_service->GetMountPointPath();
}
if (ash::cloud_upload::IsODFSMounted(profile)) {
default_paths->onedrive = ash::cloud_upload::GetODFSFuseboxMount(profile);
}
default_paths->android_files =
base::FilePath(file_manager::util::GetAndroidFilesPath());
default_paths->linux_files =
@ -116,6 +120,7 @@ mojom::DefaultPathsPtr EnvironmentProvider::GetDefaultPaths() {
default_paths->documents = home.Append("Documents");
default_paths->downloads = home.Append("Downloads");
default_paths->drivefs = home.Append("Drive");
default_paths->onedrive = home.Append("fsp");
default_paths->android_files = home.Append("Android");
default_paths->linux_files = home.Append("Crostini");
default_paths->ash_resources = home.Append("Ash");

@ -47,9 +47,9 @@ class DlpFilesControllerLacrosTest
documents_dir_ = my_files_dir_.Append(FILE_PATH_LITERAL("Documents"));
downloads_dir_ = my_files_dir_.Append(FILE_PATH_LITERAL("Downloads"));
chrome::SetLacrosDefaultPaths(
documents_dir_, downloads_dir_, drivefs_, removable_media_dir_,
android_files_dir_, linux_files_dir_, ash_resources_dir_,
share_cache_dir_, preinstalled_web_app_config_dir_,
documents_dir_, downloads_dir_, drivefs_, /*onedrive=*/base::FilePath(),
removable_media_dir_, android_files_dir_, linux_files_dir_,
ash_resources_dir_, share_cache_dir_, preinstalled_web_app_config_dir_,
preinstalled_web_app_extra_config_dir_);
}

@ -563,9 +563,10 @@ TEST(DownloadPrefsTest, DownloadDirSanitization) {
base::FilePath preinstalled_web_app_config_dir;
base::FilePath preinstalled_web_app_extra_config_dir;
chrome::SetLacrosDefaultPaths(
documents_path, default_dir, drivefs_dir, removable_media_dir,
android_files_dir, linux_files_dir, ash_resources_dir, share_cache_dir,
preinstalled_web_app_config_dir, preinstalled_web_app_extra_config_dir);
documents_path, default_dir, drivefs_dir, /*onedrive=*/base::FilePath(),
removable_media_dir, android_files_dir, linux_files_dir,
ash_resources_dir, share_cache_dir, preinstalled_web_app_config_dir,
preinstalled_web_app_extra_config_dir);
#endif
// Test a valid subdirectory of downloads.

@ -25,11 +25,11 @@
#include "chrome/browser/lacros/automation_manager_lacros.h"
#include "chrome/browser/lacros/browser_service_lacros.h"
#include "chrome/browser/lacros/clipboard_history_lacros.h"
#include "chrome/browser/lacros/cloud_file_system_path_cache.h"
#include "chrome/browser/lacros/debug_interface_lacros.h"
#include "chrome/browser/lacros/desk_profiles_lacros.h"
#include "chrome/browser/lacros/desk_template_client_lacros.h"
#include "chrome/browser/lacros/download_controller_client_lacros.h"
#include "chrome/browser/lacros/drivefs_cache.h"
#include "chrome/browser/lacros/drivefs_native_message_host_bridge_lacros.h"
#include "chrome/browser/lacros/embedded_a11y_manager_lacros.h"
#include "chrome/browser/lacros/field_trial_observer.h"
@ -264,10 +264,11 @@ void ChromeBrowserMainExtraPartsLacros::PostBrowserStart() {
std::make_unique<arc::ArcIconCacheDelegateProvider>(
arc_icon_cache_.get());
// Start Lacros' drive mount point path caching, since it is available in Ash.
drivefs_cache_ = std::make_unique<DriveFsCache>();
// Start Lacros' cloud file systems mount points paths caching, since they are
// available in Ash.
cloud_file_system_cache_ = std::make_unique<CloudFileSystemPathCache>();
// After construction finishes, start caching.
drivefs_cache_->Start();
cloud_file_system_cache_->Start();
field_trial_observer_ = std::make_unique<FieldTrialObserver>();
field_trial_observer_->Start();

@ -18,7 +18,7 @@ class BrowserServiceLacros;
class ChromeKioskLaunchControllerLacros;
class DeskTemplateClientLacros;
class DeviceLocalAccountExtensionInstallerLacros;
class DriveFsCache;
class CloudFileSystemPathCache;
class DownloadControllerClientLacros;
class ForceInstalledTrackerLacros;
class FullscreenControllerClientLacros;
@ -113,8 +113,8 @@ class ChromeBrowserMainExtraPartsLacros : public ChromeBrowserMainExtraParts {
// Handles task manager crosapi from ash for sending lacros tasks to ash.
std::unique_ptr<crosapi::TaskManagerLacros> task_manager_provider_;
// Receiver and cache of drive mount point path updates.
std::unique_ptr<DriveFsCache> drivefs_cache_;
// Receiver and cache of cloud file systems mount points paths updates.
std::unique_ptr<CloudFileSystemPathCache> cloud_file_system_cache_;
// Handles requests from DriveFS to connect to an extension in lacros.
std::unique_ptr<drive::DriveFsNativeMessageHostBridge>

@ -0,0 +1,46 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/lacros/cloud_file_system_path_cache.h"
#include "chrome/common/chrome_paths_lacros.h"
#include "chromeos/lacros/lacros_service.h"
CloudFileSystemPathCache::CloudFileSystemPathCache() = default;
CloudFileSystemPathCache::~CloudFileSystemPathCache() = default;
void CloudFileSystemPathCache::Start() {
auto* lacros_service = chromeos::LacrosService::Get();
if (lacros_service->IsAvailable<crosapi::mojom::DriveIntegrationService>()) {
// Check if Ash is too old to support the `DriveIntegrationServiceObserver`.
int driveServiceVersion =
lacros_service
->GetInterfaceVersion<crosapi::mojom::DriveIntegrationService>();
int minRequiredVersion = static_cast<int>(
crosapi::mojom::DriveIntegrationService::MethodMinVersions::
kAddDriveIntegrationServiceObserverMinVersion);
if (driveServiceVersion >= minRequiredVersion) {
lacros_service->GetRemote<crosapi::mojom::DriveIntegrationService>()
->AddDriveIntegrationServiceObserver(
drivefs_receiver_.BindNewPipeAndPassRemote());
}
}
if (lacros_service
->IsAvailable<crosapi::mojom::OneDriveIntegrationService>()) {
lacros_service->GetRemote<crosapi::mojom::OneDriveIntegrationService>()
->AddOneDriveMountObserver(
onedrive_receiver_.BindNewPipeAndPassRemote());
}
}
void CloudFileSystemPathCache::OnMountPointPathChanged(
const base::FilePath& drivefs) {
chrome::SetDriveFsMountPointPath(drivefs);
}
void CloudFileSystemPathCache::OnOneDriveMountPointPathChanged(
const base::FilePath& onedrive) {
chrome::SetOneDriveMountPointPath(onedrive);
}

@ -0,0 +1,47 @@
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_LACROS_CLOUD_FILE_SYSTEM_PATH_CACHE_H_
#define CHROME_BROWSER_LACROS_CLOUD_FILE_SYSTEM_PATH_CACHE_H_
#include "chromeos/crosapi/mojom/drive_integration_service.mojom.h"
#include "chromeos/crosapi/mojom/one_drive_integration_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
// This instance connects to ash-chrome, listens to Google Drive and Microsoft
// OneDrive mount points paths changes (including changes in drive
// availability), and caches the info for later synchronous reads using
// `GetDefaultPaths()`.
class CloudFileSystemPathCache
: public crosapi::mojom::DriveIntegrationServiceObserver,
public crosapi::mojom::OneDriveMountObserver {
public:
CloudFileSystemPathCache();
CloudFileSystemPathCache(const CloudFileSystemPathCache&) = delete;
CloudFileSystemPathCache& operator=(const CloudFileSystemPathCache&) = delete;
~CloudFileSystemPathCache() override;
// Start observing drive availability changes in ash-chrome.
// This is a post-construction step to decouple from LacrosService.
void Start();
private:
// crosapi::mojom::DriveIntegrationServiceObserver:
void OnMountPointPathChanged(const base::FilePath& drivefs) override;
// crosapi::mojom::OneDriveMountObserver:
void OnOneDriveMountPointPathChanged(const base::FilePath& drivefs) override;
// Receives mojo messages from ash-chrome (under Streaming mode) for Google
// Drive mount changes.
mojo::Receiver<crosapi::mojom::DriveIntegrationServiceObserver>
drivefs_receiver_{this};
// Receives mojo messages from ash-chrome (under Streaming mode) for OneDrive
// mount changes.
mojo::Receiver<crosapi::mojom::OneDriveMountObserver> onedrive_receiver_{
this};
};
#endif // CHROME_BROWSER_LACROS_CLOUD_FILE_SYSTEM_PATH_CACHE_H_

@ -1,35 +0,0 @@
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/lacros/drivefs_cache.h"
#include "chrome/common/chrome_paths_lacros.h"
#include "chromeos/lacros/lacros_service.h"
DriveFsCache::DriveFsCache() = default;
DriveFsCache::~DriveFsCache() = default;
void DriveFsCache::Start() {
auto* lacros_service = chromeos::LacrosService::Get();
if (!lacros_service->IsAvailable<crosapi::mojom::DriveIntegrationService>())
return;
// Check if Ash is too old to support the `DriveIntegrationServiceObserver`.
int driveServiceVersion =
lacros_service
->GetInterfaceVersion<crosapi::mojom::DriveIntegrationService>();
int minRequiredVersion = static_cast<int>(
crosapi::mojom::DriveIntegrationService::MethodMinVersions::
kAddDriveIntegrationServiceObserverMinVersion);
if (driveServiceVersion < minRequiredVersion)
return;
lacros_service->GetRemote<crosapi::mojom::DriveIntegrationService>()
->AddDriveIntegrationServiceObserver(
receiver_.BindNewPipeAndPassRemote());
}
void DriveFsCache::OnMountPointPathChanged(const base::FilePath& drivefs) {
chrome::SetDriveFsMountPointPath(drivefs);
}

@ -1,34 +0,0 @@
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_LACROS_DRIVEFS_CACHE_H_
#define CHROME_BROWSER_LACROS_DRIVEFS_CACHE_H_
#include "chromeos/crosapi/mojom/drive_integration_service.mojom.h"
#include "mojo/public/cpp/bindings/receiver.h"
// This instance connects to ash-chrome, listens to drive mount point path
// changes (including changes in drive availability), and caches the info for
// later synchronous reads using `GetDefaultPaths()`.
class DriveFsCache : public crosapi::mojom::DriveIntegrationServiceObserver {
public:
DriveFsCache();
DriveFsCache(const DriveFsCache&) = delete;
DriveFsCache& operator=(const DriveFsCache&) = delete;
~DriveFsCache() override;
// Start observing drive availability changes in ash-chrome.
// This is a post-construction step to decouple from LacrosService.
void Start();
private:
// crosapi::mojom::DriveIntegrationServiceObserver:
void OnMountPointPathChanged(const base::FilePath& drivefs) override;
// Receives mojo messages from ash-chromem (under Streaming mode).
mojo::Receiver<crosapi::mojom::DriveIntegrationServiceObserver> receiver_{
this};
};
#endif // CHROME_BROWSER_LACROS_DRIVEFS_CACHE_H_

@ -22,6 +22,8 @@ struct DefaultPaths {
base::FilePath downloads_dir;
// |drivefs| is empty if Drive is not enabled in Ash.
base::FilePath drivefs;
// |onedrive| is empty if Microsoft OneDrive is not mounted in Ash.
base::FilePath onedrive;
base::FilePath removable_media_dir;
base::FilePath android_files_dir;
base::FilePath linux_files_dir;
@ -41,6 +43,7 @@ void SetLacrosDefaultPaths(
const base::FilePath& documents_dir,
const base::FilePath& downloads_dir,
const base::FilePath& drivefs,
const base::FilePath& onedrive,
const base::FilePath& removable_media_dir,
const base::FilePath& android_files_dir,
const base::FilePath& linux_files_dir,
@ -57,6 +60,7 @@ void SetLacrosDefaultPaths(
GetDefaultPaths().downloads_dir = downloads_dir;
GetDefaultPaths().drivefs = drivefs;
GetDefaultPaths().onedrive = onedrive;
GetDefaultPaths().removable_media_dir = removable_media_dir;
GetDefaultPaths().android_files_dir = android_files_dir;
GetDefaultPaths().linux_files_dir = linux_files_dir;
@ -79,6 +83,10 @@ void SetLacrosDefaultPathsFromInitParams(
base::FilePath drivefs_dir;
if (default_paths->drivefs.has_value())
drivefs_dir = default_paths->drivefs.value();
base::FilePath onedrive_dir;
if (default_paths->onedrive.has_value()) {
onedrive_dir = default_paths->onedrive.value();
}
base::FilePath removable_media_dir;
if (default_paths->removable_media.has_value())
removable_media_dir = default_paths->removable_media.value();
@ -107,7 +115,7 @@ void SetLacrosDefaultPathsFromInitParams(
chrome::SetLacrosDefaultPaths(
default_paths->documents, default_paths->downloads, drivefs_dir,
removable_media_dir, android_files_dir, linux_files_dir,
onedrive_dir, removable_media_dir, android_files_dir, linux_files_dir,
ash_resources_dir, share_cache_dir, preinstalled_web_app_config_dir,
preinstalled_web_app_extra_config_dir);
}
@ -117,6 +125,20 @@ void SetDriveFsMountPointPath(const base::FilePath& drivefs) {
GetDefaultPaths().drivefs = drivefs;
}
void SetOneDriveMountPointPath(const base::FilePath& onedrive) {
GetDefaultPaths().onedrive = onedrive;
}
bool GetOneDriveMountPointPath(base::FilePath* result) {
// NOTE: Lacros overrides the path with a value from ash early in startup. See
// crosapi::mojom::LacrosInitParams.
if (GetDefaultPaths().onedrive.empty()) {
return false;
}
*result = GetDefaultPaths().onedrive;
return true;
}
bool GetDefaultUserDataDirectory(base::FilePath* result) {
if (base::SysInfo::IsRunningOnChromeOS()) {
*result = base::FilePath(crosapi::kLacrosUserDataPath);

@ -21,6 +21,7 @@ void SetLacrosDefaultPaths(
const base::FilePath& documents_dir,
const base::FilePath& downloads_dir,
const base::FilePath& drivefs,
const base::FilePath& onedrive,
const base::FilePath& removable_media_dir,
const base::FilePath& android_files_dir,
const base::FilePath& linux_files_dir,
@ -44,6 +45,16 @@ void SetDriveFsMountPointPath(const base::FilePath& drivefs);
// Returns false if Drive is not enabled in Ash.
bool GetDriveFsMountPointPath(base::FilePath* result);
// The OneDrive mount point path is sent by ash-chrome, `onedrive` may be
// empty in case OneDrive is not mounted in Ash. `SetOneDriveMountPointPath()`
// is triggered when OneDrive mount point in Ash changes.
void SetOneDriveMountPointPath(const base::FilePath& onedrive);
// Sets `result` to the the OneDrive mount point path, which is passed in by Ash
// and continually updated as it changes in Ash.
// Returns false if OneDrive is not mounted in Ash.
bool GetOneDriveMountPointPath(base::FilePath* result);
// These paths are sent by ash-chrome at Lacros startup. These return false if
// the value was not sent (eg. due to API version skew).
bool GetRemovableMediaPath(base::FilePath* result);

@ -120,6 +120,7 @@ void ChromeTestSuite::Initialize() {
/*documents_dir=*/temp_path,
/*downloads_dir=*/temp_path,
/*drivefs=*/base::FilePath(),
/*onedrive=*/base::FilePath(),
/*removable_media_dir=*/base::FilePath(),
/*android_files_dir=*/base::FilePath(),
/*linux_files_dir=*/base::FilePath(),

@ -41,6 +41,7 @@ void ChromeOSTestSuite::Initialize() {
/*documents_dir=*/temp_path,
/*downloads_dir=*/temp_path,
/*drivefs=*/base::FilePath(),
/*onedrive=*/base::FilePath(),
/*removable_media_dir=*/base::FilePath(),
/*android_files_dir=*/base::FilePath(),
/*linux_files_dir=*/base::FilePath(),

@ -912,8 +912,8 @@ enum MetricsReportingManaged {
// future compatibility, to avoid assumptions about where on disk the directory
// is located.
//
// Next version: 35
// Next id: 11
// Next version: 36
// Next id: 12
[Stable]
struct DefaultPaths {
// The default (non-configurable) directory for documents. For example,
@ -928,6 +928,10 @@ struct DefaultPaths {
// example, /media/fuse/drivefs-<hash>.
[MinVersion=23] mojo_base.mojom.FilePath? drivefs@2;
// The path of the mount point for OneDrive in ChromeOS. For example,
// /media/fuse/fusebox/fsp.<hash>.
[MinVersion=35] mojo_base.mojom.FilePath? onedrive@11;
// The (non-configurable) path of the software user NSS database. For
// example, /home/chronos/u-<hash>/.pki/nssdb.
[MinVersion=30] mojo_base.mojom.FilePath? user_nss_database@3;

@ -92,6 +92,7 @@
#include "chromeos/crosapi/mojom/networking_attributes.mojom.h"
#include "chromeos/crosapi/mojom/networking_private.mojom.h"
#include "chromeos/crosapi/mojom/nonclosable_app_toast_service.mojom.h"
#include "chromeos/crosapi/mojom/one_drive_integration_service.mojom.h"
#include "chromeos/crosapi/mojom/one_drive_notification_service.mojom.h"
#include "chromeos/crosapi/mojom/parent_access.mojom.h"
#include "chromeos/crosapi/mojom/policy_service.mojom.h"
@ -518,6 +519,11 @@ LacrosService::LacrosService()
&crosapi::mojom::Crosapi::BindOneDriveNotificationService,
Crosapi::MethodMinVersions::kBindOneDriveNotificationServiceMinVersion>();
ConstructRemote<
crosapi::mojom::OneDriveIntegrationService,
&crosapi::mojom::Crosapi::BindOneDriveIntegrationService,
Crosapi::MethodMinVersions::kBindOneDriveIntegrationServiceMinVersion>();
ConstructRemote<crosapi::mojom::Prefs, &crosapi::mojom::Crosapi::BindPrefs,
Crosapi::MethodMinVersions::kBindPrefsMinVersion>();
ConstructRemote<