Commit 28aa43e6 authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Report Drive as disabled to Files app when mounting it has failed.

While Drive is mounting, a fake Google Drive entry is shown in Files
app. If mounting fails, begin returning false for the is drive enabled
"pref" to Files app and dispatch an event notifying it about the change
in prefs.

Bug: 889732
Change-Id: Ia79c19a36904bb73f7a3a8ed86ab52dd685689dc
Reviewed-on: https://chromium-review.googlesource.com/c/1312442
Commit-Queue: Sam McNally <sammc@chromium.org>
Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604557}
parent f015caa1
......@@ -760,6 +760,7 @@ void DriveIntegrationService::SetEnabled(bool enabled) {
enabled_ = false;
drivefs_total_failures_count_ = 0;
drivefs_consecutive_failures_count_ = 0;
mount_failed_ = false;
}
}
......@@ -989,13 +990,19 @@ void DriveIntegrationService::MaybeRemountFileSystem(
++drivefs_consecutive_failures_count_;
++drivefs_total_failures_count_;
if (drivefs_total_failures_count_ > 10) {
mount_failed_ = true;
logger_->Log(logging::LOG_ERROR,
"DriveFs is too crashy. Leaving it alone.");
for (auto& observer : observers_)
observer.OnFileSystemMountFailed();
return;
}
if (drivefs_consecutive_failures_count_ > 3) {
mount_failed_ = true;
logger_->Log(logging::LOG_ERROR,
"DriveFs keeps failing at start. Giving up.");
for (auto& observer : observers_)
observer.OnFileSystemMountFailed();
return;
}
remount_delay = base::TimeDelta::FromSeconds(
......
......@@ -79,6 +79,10 @@ class DriveIntegrationServiceObserver {
virtual void OnFileSystemBeingUnmounted() {
}
// Triggered when mounting the filesystem has failed in a fashion that will
// not be automatically retried.
virtual void OnFileSystemMountFailed() {}
protected:
virtual ~DriveIntegrationServiceObserver() {}
};
......@@ -125,6 +129,8 @@ class DriveIntegrationService : public KeyedService,
bool IsMounted() const;
bool mount_failed() const { return mount_failed_; }
// Returns the path of the mount point for drive. It is only valid to call if
// |IsMounted()|.
base::FilePath GetMountPointPath() const;
......@@ -245,6 +251,7 @@ class DriveIntegrationService : public KeyedService,
Profile* profile_;
State state_;
bool enabled_;
bool mount_failed_ = false;
// Custom mount point name that can be injected for testing in constructor.
std::string mount_point_name_;
......
......@@ -497,6 +497,7 @@ void EventRouter::Shutdown() {
DriveIntegrationService* const integration_service =
DriveIntegrationServiceFactory::FindForProfile(profile_);
if (integration_service) {
integration_service->RemoveObserver(this);
if (integration_service->GetDriveFsHost()) {
integration_service->GetDriveFsHost()->RemoveObserver(
drivefs_event_router_.get());
......@@ -549,6 +550,7 @@ void EventRouter::ObserveEvents() {
DriveIntegrationService* const integration_service =
DriveIntegrationServiceFactory::FindForProfile(profile_);
if (integration_service) {
integration_service->AddObserver(this);
if (integration_service->GetDriveFsHost()) {
integration_service->GetDriveFsHost()->AddObserver(
drivefs_event_router_.get());
......@@ -1084,6 +1086,10 @@ void EventRouter::SetDispatchDirectoryChangeEventImplForTesting(
dispatch_directory_change_event_impl_ = callback;
}
void EventRouter::OnFileSystemMountFailed() {
OnFileManagerPrefsChanged();
}
base::WeakPtr<EventRouter> EventRouter::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......
......@@ -58,7 +58,8 @@ class EventRouter : public KeyedService,
public drive::FileSystemObserver,
public drive::DriveServiceObserver,
public VolumeManagerObserver,
public arc::ArcIntentHelperObserver {
public arc::ArcIntentHelperObserver,
public drive::DriveIntegrationServiceObserver {
public:
typedef base::Callback<void(const base::FilePath& virtual_path,
const drive::FileChange* list,
......@@ -148,6 +149,9 @@ class EventRouter : public KeyedService,
void SetDispatchDirectoryChangeEventImplForTesting(
const DispatchDirectoryChangeEventImplCallback& callback);
// DriveIntegrationServiceObserver override.
void OnFileSystemMountFailed() override;
// Returns a weak pointer for the event router.
base::WeakPtr<EventRouter> GetWeakPtr();
......
......@@ -23,6 +23,7 @@
#include "chrome/browser/chromeos/crostini/crostini_package_installer_service.h"
#include "chrome/browser/chromeos/crostini/crostini_share_path.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/chromeos/drive/drive_integration_service.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_util.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
......@@ -205,8 +206,12 @@ FileManagerPrivateGetPreferencesFunction::Run() {
api::file_manager_private::Preferences result;
Profile* profile = Profile::FromBrowserContext(browser_context());
const PrefService* const service = profile->GetPrefs();
auto* drive_integration_service =
drive::DriveIntegrationServiceFactory::FindForProfile(profile);
result.drive_enabled = drive::util::IsDriveEnabledForProfile(profile);
result.drive_enabled = drive::util::IsDriveEnabledForProfile(profile) &&
drive_integration_service &&
!drive_integration_service->mount_failed();
result.cellular_disabled =
service->GetBoolean(drive::prefs::kDisableDriveOverCellular);
result.hosted_files_disabled =
......
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