Commit b4db86a6 authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Introduce State to DriveIntegrationService.

This is small refactoring of DriveIntegrationService by introducing State.
This is preparation of mount/enabled state migration of
DriveIntegrationSerivice. By the migration, DriveIntegrationService can be
obtained even before initialization. This CL supports the change.
Also, by this CL, FileSystem can be deleted even before Initialize() is called.

BUG=284972
TEST=Ran unit_tests
R=kinaba@chromium.org

Review URL: https://codereview.chromium.org/23548025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222231 0039d316-1c4b-4281-b951-d872f2087c98
parent 39080c97
...@@ -139,7 +139,7 @@ DriveIntegrationService::DriveIntegrationService( ...@@ -139,7 +139,7 @@ DriveIntegrationService::DriveIntegrationService(
const base::FilePath& test_cache_root, const base::FilePath& test_cache_root,
FileSystemInterface* test_file_system) FileSystemInterface* test_file_system)
: profile_(profile), : profile_(profile),
is_initialized_(false), state_(NOT_INITIALIZED),
cache_root_directory_(!test_cache_root.empty() ? cache_root_directory_(!test_cache_root.empty() ?
test_cache_root : util::GetCacheRootPath(profile)), test_cache_root : util::GetCacheRootPath(profile)),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
...@@ -209,6 +209,9 @@ DriveIntegrationService::~DriveIntegrationService() { ...@@ -209,6 +209,9 @@ DriveIntegrationService::~DriveIntegrationService() {
void DriveIntegrationService::Initialize() { void DriveIntegrationService::Initialize() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK_EQ(NOT_INITIALIZED, state_);
state_ = INITIALIZING;
drive_service_->Initialize(); drive_service_->Initialize();
file_system_->Initialize(); file_system_->Initialize();
...@@ -227,6 +230,8 @@ void DriveIntegrationService::Initialize() { ...@@ -227,6 +230,8 @@ void DriveIntegrationService::Initialize() {
void DriveIntegrationService::Shutdown() { void DriveIntegrationService::Shutdown() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
weak_ptr_factory_.InvalidateWeakPtrs();
DriveNotificationManager* drive_notification_manager = DriveNotificationManager* drive_notification_manager =
DriveNotificationManagerFactory::GetForBrowserContext(profile_); DriveNotificationManagerFactory::GetForBrowserContext(profile_);
if (drive_notification_manager) if (drive_notification_manager)
...@@ -272,7 +277,8 @@ bool DriveIntegrationService::IsDriveEnabled() { ...@@ -272,7 +277,8 @@ bool DriveIntegrationService::IsDriveEnabled() {
if (!util::IsDriveEnabledForProfile(profile_)) if (!util::IsDriveEnabledForProfile(profile_))
return false; return false;
return is_initialized_; // For backword compatibility, REMOUNTING also means enabled.
return state_ == INITIALIZED || state_ == REMOUNTING;
} }
void DriveIntegrationService::ClearCacheAndRemountFileSystem( void DriveIntegrationService::ClearCacheAndRemountFileSystem(
...@@ -280,6 +286,13 @@ void DriveIntegrationService::ClearCacheAndRemountFileSystem( ...@@ -280,6 +286,13 @@ void DriveIntegrationService::ClearCacheAndRemountFileSystem(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
if (state_ != INITIALIZED) {
callback.Run(false);
return;
}
state_ = REMOUNTING;
RemoveDriveMountPoint(); RemoveDriveMountPoint();
// Reloading the file system will clear the resource metadata. // Reloading the file system will clear the resource metadata.
file_system_->Reload(); file_system_->Reload();
...@@ -324,9 +337,12 @@ void DriveIntegrationService::AddDriveMountPoint() { ...@@ -324,9 +337,12 @@ void DriveIntegrationService::AddDriveMountPoint() {
drive_mount_point); drive_mount_point);
if (success) { if (success) {
state_ = INITIALIZED;
util::Log(logging::LOG_INFO, "Drive mount point is added"); util::Log(logging::LOG_INFO, "Drive mount point is added");
FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_, FOR_EACH_OBSERVER(DriveIntegrationServiceObserver, observers_,
OnFileSystemMounted()); OnFileSystemMounted());
} else {
state_ = NOT_INITIALIZED;
} }
} }
...@@ -362,9 +378,12 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized( ...@@ -362,9 +378,12 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized(
pref_service->SetFilePath(prefs::kDownloadDefaultDirectory, pref_service->SetFilePath(prefs::kDownloadDefaultDirectory,
DownloadPrefs::GetDefaultDownloadDirectory()); DownloadPrefs::GetDefaultDownloadDirectory());
} }
// Back to NOT_INITIALIZED state. Then, re-running Initialize() should
// work if the error is recovarable manually (such as out of disk space).
state_ = NOT_INITIALIZED;
return; return;
} }
is_initialized_ = true;
content::DownloadManager* download_manager = content::DownloadManager* download_manager =
g_browser_process->download_status_updater() ? g_browser_process->download_status_updater() ?
...@@ -388,6 +407,7 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized( ...@@ -388,6 +407,7 @@ void DriveIntegrationService::InitializeAfterMetadataInitialized(
} }
AddDriveMountPoint(); AddDriveMountPoint();
state_ = INITIALIZED;
} }
//===================== DriveIntegrationServiceFactory ======================= //===================== DriveIntegrationServiceFactory =======================
......
...@@ -110,6 +110,13 @@ class DriveIntegrationService ...@@ -110,6 +110,13 @@ class DriveIntegrationService
const base::Callback<void(bool)>& callback); const base::Callback<void(bool)>& callback);
private: private:
enum State {
NOT_INITIALIZED,
INITIALIZING,
INITIALIZED,
REMOUNTING,
};
// Returns true if Drive is enabled. // Returns true if Drive is enabled.
// Must be called on UI thread. // Must be called on UI thread.
bool IsDriveEnabled(); bool IsDriveEnabled();
...@@ -131,7 +138,7 @@ class DriveIntegrationService ...@@ -131,7 +138,7 @@ class DriveIntegrationService
friend class DriveIntegrationServiceFactory; friend class DriveIntegrationServiceFactory;
Profile* profile_; Profile* profile_;
bool is_initialized_; State state_;
base::FilePath cache_root_directory_; base::FilePath cache_root_directory_;
scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
......
...@@ -401,7 +401,8 @@ FileSystem::~FileSystem() { ...@@ -401,7 +401,8 @@ FileSystem::~FileSystem() {
// shutdown. // shutdown.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
change_list_loader_->RemoveObserver(this); if (change_list_loader_)
change_list_loader_->RemoveObserver(this);
} }
void FileSystem::AddObserver(FileSystemObserver* observer) { void FileSystem::AddObserver(FileSystemObserver* observer) {
......
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