diff --git a/ash/constants/ash_features.h b/ash/constants/ash_features.h index f494cd2f82a9f..964f90d80ff6c 100644 --- a/ash/constants/ash_features.h +++ b/ash/constants/ash_features.h @@ -666,6 +666,7 @@ COMPONENT_EXPORT(ASH_CONSTANTS) bool IsDisplayAlignmentAssistanceEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsDragUnpinnedAppToPinEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsDragWindowToNewDeskEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsDriveFsMirroringEnabled(); +COMPONENT_EXPORT(ASH_CONSTANTS) bool IsDriveFsBulkPinningEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsInlineSyncStatusEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsEapGtcWifiAuthenticationEnabled(); COMPONENT_EXPORT(ASH_CONSTANTS) bool IsEcheSWAEnabled(); diff --git a/chrome/browser/ash/drive/drive_integration_service.cc b/chrome/browser/ash/drive/drive_integration_service.cc index 88b2666e1ceb9..b6f8803604337 100644 --- a/chrome/browser/ash/drive/drive_integration_service.cc +++ b/chrome/browser/ash/drive/drive_integration_service.cc @@ -42,6 +42,7 @@ #include "chrome/browser/signin/identity_manager_factory.h" #include "chrome/common/pref_names.h" #include "chromeos/ash/components/drivefs/drivefs_bootstrap.h" +#include "chromeos/ash/components/drivefs/drivefs_pin_manager.h" #include "chromeos/ash/components/network/network_handler.h" #include "chromeos/ash/components/network/network_state.h" #include "chromeos/ash/components/network/network_state_handler.h" @@ -373,6 +374,12 @@ class DriveIntegrationService::PreferenceWatcher base::BindRepeating(&PreferenceWatcher::ToggleLocalMirroring, weak_ptr_factory_.GetWeakPtr())); } + if (ash::features::IsDriveFsBulkPinningEnabled()) { + pref_change_registrar_.Add( + prefs::kDriveFsBulkPinningEnabled, + base::BindRepeating(&PreferenceWatcher::UpdateBulkPinningState, + weak_ptr_factory_.GetWeakPtr())); + } } PreferenceWatcher(const PreferenceWatcher&) = delete; @@ -437,6 +444,16 @@ class DriveIntegrationService::PreferenceWatcher } } + void UpdateBulkPinningState() { + DCHECK(integration_service_); + if (!ash::features::IsDriveFsBulkPinningEnabled()) { + return; + } + + integration_service_->SetBulkPinningEnabled( + pref_service_->GetBoolean(prefs::kDriveFsBulkPinningEnabled)); + } + void AddNetworkPortalDetectorObserver() { if (!ash::NetworkHandler::IsInitialized()) return; // Test environment. @@ -667,6 +684,11 @@ DriveIntegrationService::DriveIntegrationService( } SetEnabled(drive::util::IsDriveEnabledForProfile(profile)); + + if (ash::features::IsDriveFsBulkPinningEnabled()) { + pin_manager_ = std::make_unique( + profile->GetPrefs()->GetBoolean(prefs::kDriveFsBulkPinningEnabled)); + } } DriveIntegrationService::~DriveIntegrationService() { @@ -1418,6 +1440,15 @@ void DriveIntegrationService::ForceReSyncFile(const base::FilePath& local_path, std::move(callback)); } +void DriveIntegrationService::SetBulkPinningEnabled(bool enabled) { + if (!ash::features::IsDriveFsBulkPinningEnabled() || !IsMounted() || + !GetDriveFsInterface() || pin_manager_) { + return; + } + + pin_manager_->SetBulkPinningEnabled(enabled); +} + //===================== DriveIntegrationServiceFactory ======================= DriveIntegrationServiceFactory::FactoryCallback* diff --git a/chrome/browser/ash/drive/drive_integration_service.h b/chrome/browser/ash/drive/drive_integration_service.h index c16f6ba05db95..cba633008bc68 100644 --- a/chrome/browser/ash/drive/drive_integration_service.h +++ b/chrome/browser/ash/drive/drive_integration_service.h @@ -19,6 +19,7 @@ #include "base/time/time.h" #include "chrome/browser/profiles/profile_keyed_service_factory.h" #include "chromeos/ash/components/drivefs/drivefs_host.h" +#include "chromeos/ash/components/drivefs/drivefs_pin_manager.h" #include "chromeos/ash/components/drivefs/sync_status_tracker.h" #include "components/drive/drive_notification_observer.h" #include "components/drive/file_errors.h" @@ -274,6 +275,9 @@ class DriveIntegrationService : public KeyedService, void ForceReSyncFile(const base::FilePath& local_path, base::OnceClosure callback); + // Enable / disable the bulk pinning functionality. + void SetBulkPinningEnabled(bool enabled); + private: enum State { NOT_INITIALIZED, @@ -389,6 +393,7 @@ class DriveIntegrationService : public KeyedService, std::unique_ptr drivefs_holder_; std::unique_ptr preference_watcher_; + std::unique_ptr pin_manager_; int drivefs_total_failures_count_ = 0; int drivefs_consecutive_failures_count_ = 0; bool remount_when_online_ = false; diff --git a/chrome/browser/ash/preferences.cc b/chrome/browser/ash/preferences.cc index ca26ac425c48c..c215588b36d07 100644 --- a/chrome/browser/ash/preferences.cc +++ b/chrome/browser/ash/preferences.cc @@ -269,6 +269,11 @@ void Preferences::RegisterProfilePrefs( registry->RegisterBooleanPref(drive::prefs::kDriveFsEnableMirrorSync, false); registry->RegisterStringPref(drive::prefs::kDriveFsMirrorSyncMachineRootId, ""); + // Do not sync kDriveFsBulkPinningEnabled as this maintains files that are + // locally pinned to this device and should not sync the state across multiple + // devices. + registry->RegisterBooleanPref(drive::prefs::kDriveFsBulkPinningEnabled, + false); // We don't sync ::prefs::kLanguageCurrentInputMethod and PreviousInputMethod // because they're just used to track the logout state of the device. registry->RegisterStringPref(::prefs::kLanguageCurrentInputMethod, ""); diff --git a/chromeos/ash/components/drivefs/BUILD.gn b/chromeos/ash/components/drivefs/BUILD.gn index bb12524ba70b2..80df8b15e5716 100644 --- a/chromeos/ash/components/drivefs/BUILD.gn +++ b/chromeos/ash/components/drivefs/BUILD.gn @@ -18,6 +18,8 @@ component("drivefs") { "drivefs_host_observer.h", "drivefs_http_client.cc", "drivefs_http_client.h", + "drivefs_pin_manager.cc", + "drivefs_pin_manager.h", "drivefs_search.cc", "drivefs_search.h", "drivefs_session.cc", diff --git a/chromeos/ash/components/drivefs/drivefs_pin_manager.cc b/chromeos/ash/components/drivefs/drivefs_pin_manager.cc new file mode 100644 index 0000000000000..286392e39a3b1 --- /dev/null +++ b/chromeos/ash/components/drivefs/drivefs_pin_manager.cc @@ -0,0 +1,11 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chromeos/ash/components/drivefs/drivefs_pin_manager.h" + +namespace drivefs::pinning { + +DriveFsPinManager::DriveFsPinManager(bool enabled) : enabled_(enabled) {} + +} // namespace drivefs::pinning \ No newline at end of file diff --git a/chromeos/ash/components/drivefs/drivefs_pin_manager.h b/chromeos/ash/components/drivefs/drivefs_pin_manager.h new file mode 100644 index 0000000000000..0096c0aecde72 --- /dev/null +++ b/chromeos/ash/components/drivefs/drivefs_pin_manager.h @@ -0,0 +1,36 @@ +// Copyright 2022 The Chromium Authors +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_PIN_MANAGER_H_ +#define CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_PIN_MANAGER_H_ + +#include "base/component_export.h" + +namespace drivefs::pinning { + +// Manages bulk pinning of items via DriveFS. This class handles the following: +// - Manage batching of pin actions to avoid sending too many events at once. +// - Ensure disk space is not being exceeded whilst pinning files. +// - Maintain pinning of files that are newly created. +// - Rebuild the progress of bulk pinned items (if turned off mid way through a +// bulk pinning event). +class COMPONENT_EXPORT(CHROMEOS_ASH_COMPONENTS_DRIVEFS) DriveFsPinManager { + public: + explicit DriveFsPinManager(bool enabled); + + DriveFsPinManager(const DriveFsPinManager&) = delete; + DriveFsPinManager& operator=(const DriveFsPinManager&) = delete; + + ~DriveFsPinManager() = default; + + // Enable or disable the bulk pinning. + void SetBulkPinningEnabled(bool enabled) { enabled_ = enabled; } + + private: + bool enabled_ = false; +}; + +} // namespace drivefs::pinning + +#endif // CHROMEOS_ASH_COMPONENTS_DRIVEFS_DRIVEFS_PIN_MANAGER_H_ \ No newline at end of file diff --git a/components/drive/drive_pref_names.cc b/components/drive/drive_pref_names.cc index 8e9554e225f68..b193228e4f97b 100644 --- a/components/drive/drive_pref_names.cc +++ b/components/drive/drive_pref_names.cc @@ -4,8 +4,7 @@ #include "components/drive/drive_pref_names.h" -namespace drive { -namespace prefs { +namespace drive::prefs { // A boolean pref to disable Google Drive integration. // The pref prefix should remain as "gdata" for backward compatibility. @@ -37,5 +36,8 @@ const char kDriveFsEnableMirrorSync[] = "drivefs.enable_mirror_sync"; const char kDriveFsMirrorSyncMachineRootId[] = "drivefs.mirror_sync_machine_root_id"; -} // namespace prefs -} // namespace drive +// A boolean pref that maintains whether the feature is enabled or disabled by +// the user. +const char kDriveFsBulkPinningEnabled[] = "drivefs.bulk_pinning_enabled"; + +} // namespace drive::prefs diff --git a/components/drive/drive_pref_names.h b/components/drive/drive_pref_names.h index 9ded9ae264e53..6a37b41124219 100644 --- a/components/drive/drive_pref_names.h +++ b/components/drive/drive_pref_names.h @@ -7,8 +7,7 @@ #ifndef COMPONENTS_DRIVE_DRIVE_PREF_NAMES_H_ #define COMPONENTS_DRIVE_DRIVE_PREF_NAMES_H_ -namespace drive { -namespace prefs { +namespace drive::prefs { extern const char kDisableDrive[]; extern const char kDisableDriveOverCellular[]; @@ -18,8 +17,8 @@ extern const char kDriveFsPinnedMigrated[]; extern const char kDriveFsWasLaunchedAtLeastOnce[]; extern const char kDriveFsEnableMirrorSync[]; extern const char kDriveFsMirrorSyncMachineRootId[]; +extern const char kDriveFsBulkPinningEnabled[]; -} // namespace prefs -} // namespace drive +} // namespace drive::prefs #endif // COMPONENTS_DRIVE_DRIVE_PREF_NAMES_H_