Commit 4bb5c3f2 authored by Austin Tankiang's avatar Austin Tankiang Committed by Chromium LUCI CQ

Create PreferenceWatcher even if Drive is disabled by pref

Before PreferenceWatcher was not created when Drive was disabled by the
kDisableDrive pref, which would cause Drive to not start when the pref
was changed.

Bug: 1110238
Change-Id: Ic96c757ed77a8cb957dc6959f7ea40efb5460b9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2328544
Commit-Queue: Austin Tankiang <austinct@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832218}
parent dd397219
...@@ -575,7 +575,7 @@ DriveIntegrationService::DriveIntegrationService( ...@@ -575,7 +575,7 @@ DriveIntegrationService::DriveIntegrationService(
{base::MayBlock(), base::TaskPriority::USER_BLOCKING, {base::MayBlock(), base::TaskPriority::USER_BLOCKING,
base::WithBaseSyncPrimitives()}); base::WithBaseSyncPrimitives()});
if (util::IsDriveEnabledForProfile(profile)) { if (util::IsDriveAvailableForProfile(profile)) {
preference_watcher_ = preference_watcher_ =
std::make_unique<PreferenceWatcher>(profile->GetPrefs()); std::make_unique<PreferenceWatcher>(profile->GetPrefs());
preference_watcher_->set_integration_service(this); preference_watcher_->set_integration_service(this);
......
...@@ -39,8 +39,8 @@ class DriveIntegrationServiceBrowserTest : public InProcessBrowserTest { ...@@ -39,8 +39,8 @@ class DriveIntegrationServiceBrowserTest : public InProcessBrowserTest {
return &fake_drivefs_helpers_[profile]->fake_drivefs(); return &fake_drivefs_helpers_[profile]->fake_drivefs();
} }
private: protected:
drive::DriveIntegrationService* CreateDriveIntegrationService( virtual drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) { Profile* profile) {
base::ScopedAllowBlockingForTesting allow_blocking; base::ScopedAllowBlockingForTesting allow_blocking;
base::FilePath mount_path = profile->GetPath().Append("drivefs"); base::FilePath mount_path = profile->GetPath().Append("drivefs");
...@@ -52,6 +52,7 @@ class DriveIntegrationServiceBrowserTest : public InProcessBrowserTest { ...@@ -52,6 +52,7 @@ class DriveIntegrationServiceBrowserTest : public InProcessBrowserTest {
return integration_service; return integration_service;
} }
private:
drive::DriveIntegrationServiceFactory::FactoryCallback drive::DriveIntegrationServiceFactory::FactoryCallback
create_drive_integration_service_; create_drive_integration_service_;
std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest>
...@@ -215,4 +216,28 @@ IN_PROC_BROWSER_TEST_F(DriveIntegrationServiceBrowserTest, ...@@ -215,4 +216,28 @@ IN_PROC_BROWSER_TEST_F(DriveIntegrationServiceBrowserTest,
run_loop.Run(); run_loop.Run();
} }
} }
class DriveIntegrationServiceWithPrefDisabledBrowserTest
: public DriveIntegrationServiceBrowserTest {
drive::DriveIntegrationService* CreateDriveIntegrationService(
Profile* profile) override {
profile->GetPrefs()->SetBoolean(prefs::kDisableDrive, true);
return DriveIntegrationServiceBrowserTest::CreateDriveIntegrationService(
profile);
}
};
IN_PROC_BROWSER_TEST_F(DriveIntegrationServiceWithPrefDisabledBrowserTest,
RenableAndDisableDrive) {
auto* profile = browser()->profile();
auto* drive_service = DriveIntegrationServiceFactory::FindForProfile(profile);
EXPECT_FALSE(drive_service->is_enabled());
profile->GetPrefs()->SetBoolean(prefs::kDisableDrive, false);
EXPECT_TRUE(drive_service->is_enabled());
profile->GetPrefs()->SetBoolean(prefs::kDisableDrive, true);
EXPECT_FALSE(drive_service->is_enabled());
}
} // namespace drive } // namespace drive
...@@ -72,7 +72,7 @@ base::FilePath GetCacheRootPath(Profile* profile) { ...@@ -72,7 +72,7 @@ base::FilePath GetCacheRootPath(Profile* profile) {
return cache_root_path.Append(kFileCacheVersionDir); return cache_root_path.Append(kFileCacheVersionDir);
} }
bool IsDriveEnabledForProfile(Profile* profile) { bool IsDriveAvailableForProfile(Profile* profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Disable Drive for non-Gaia accounts. // Disable Drive for non-Gaia accounts.
...@@ -90,11 +90,6 @@ bool IsDriveEnabledForProfile(Profile* profile) { ...@@ -90,11 +90,6 @@ bool IsDriveEnabledForProfile(Profile* profile) {
if (!user || !user->HasGaiaAccount()) if (!user || !user->HasGaiaAccount())
return false; return false;
// Disable Drive if preference is set. This can happen with commandline flag
// --disable-drive or enterprise policy, or with user settings.
if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive))
return false;
// Disable drive if sync is disabled by command line flag. Outside tests, this // Disable drive if sync is disabled by command line flag. Outside tests, this
// only occurs in cases already handled by the gaia account check above. // only occurs in cases already handled by the gaia account check above.
if (!switches::IsSyncAllowedByFlag()) if (!switches::IsSyncAllowedByFlag())
...@@ -103,6 +98,15 @@ bool IsDriveEnabledForProfile(Profile* profile) { ...@@ -103,6 +98,15 @@ bool IsDriveEnabledForProfile(Profile* profile) {
return true; return true;
} }
bool IsDriveEnabledForProfile(Profile* profile) {
// Disable Drive if preference is set. This can happen with commandline flag
// --disable-drive or enterprise policy, or with user settings.
if (profile->GetPrefs()->GetBoolean(prefs::kDisableDrive))
return false;
return IsDriveAvailableForProfile(profile);
}
ConnectionStatusType GetDriveConnectionStatus(Profile* profile) { ConnectionStatusType GetDriveConnectionStatus(Profile* profile) {
auto* drive_integration_service = GetIntegrationServiceByProfile(profile); auto* drive_integration_service = GetIntegrationServiceByProfile(profile);
if (!drive_integration_service) if (!drive_integration_service)
......
...@@ -31,7 +31,10 @@ bool IsUnderDriveMountPoint(const base::FilePath& path); ...@@ -31,7 +31,10 @@ bool IsUnderDriveMountPoint(const base::FilePath& path);
// profile. // profile.
base::FilePath GetCacheRootPath(Profile* profile); base::FilePath GetCacheRootPath(Profile* profile);
// Returns true if Drive is enabled for the given Profile. // Returns true if Drive is available for the given Profile.
bool IsDriveAvailableForProfile(Profile* profile);
// Returns true if Drive is currently enabled for the given Profile.
bool IsDriveEnabledForProfile(Profile* profile); bool IsDriveEnabledForProfile(Profile* profile);
// Enum type for describing the current connection status to Drive. // Enum type for describing the current connection status to Drive.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment