Skip to content

Commit

Permalink
[FilesTiering] Add skeleton class for DriveFsPinManager
Browse files Browse the repository at this point in the history
This adds skeleton code for the DriveFsPinManager which will manage and
maintain the "bulk pinning" functionality. This also adds a new pref
that maintains the enablement of this feature, toggling it currently
does nothing, but later will serve as the mechanism to start and stop
the bulk pinning action.

Bug: b:259454320
Change-Id: I790775a01218493a3184cc0f3066540b4649631d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4036471
Reviewed-by: Hiroki Nakagawa <nhiroki@chromium.org>
Auto-Submit: Ben Reich <benreich@chromium.org>
Reviewed-by: Bo Majewski <majewski@chromium.org>
Reviewed-by: James Cook <jamescook@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1075127}
  • Loading branch information
ben-reich authored and Chromium LUCI CQ committed Nov 23, 2022
1 parent b7dff48 commit af3cf2d
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 8 deletions.
1 change: 1 addition & 0 deletions ash/constants/ash_features.h
Expand Up @@ -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();
Expand Down
31 changes: 31 additions & 0 deletions chrome/browser/ash/drive/drive_integration_service.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -667,6 +684,11 @@ DriveIntegrationService::DriveIntegrationService(
}

SetEnabled(drive::util::IsDriveEnabledForProfile(profile));

if (ash::features::IsDriveFsBulkPinningEnabled()) {
pin_manager_ = std::make_unique<drivefs::pinning::DriveFsPinManager>(
profile->GetPrefs()->GetBoolean(prefs::kDriveFsBulkPinningEnabled));
}
}

DriveIntegrationService::~DriveIntegrationService() {
Expand Down Expand Up @@ -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*
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ash/drive/drive_integration_service.h
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -389,6 +393,7 @@ class DriveIntegrationService : public KeyedService,

std::unique_ptr<DriveFsHolder> drivefs_holder_;
std::unique_ptr<PreferenceWatcher> preference_watcher_;
std::unique_ptr<drivefs::pinning::DriveFsPinManager> pin_manager_;
int drivefs_total_failures_count_ = 0;
int drivefs_consecutive_failures_count_ = 0;
bool remount_when_online_ = false;
Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/ash/preferences.cc
Expand Up @@ -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, "");
Expand Down
2 changes: 2 additions & 0 deletions chromeos/ash/components/drivefs/BUILD.gn
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions 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
36 changes: 36 additions & 0 deletions 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_
10 changes: 6 additions & 4 deletions components/drive/drive_pref_names.cc
Expand Up @@ -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.
Expand Down Expand Up @@ -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
7 changes: 3 additions & 4 deletions components/drive/drive_pref_names.h
Expand Up @@ -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[];
Expand All @@ -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_

0 comments on commit af3cf2d

Please sign in to comment.