diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 03:59:35 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 03:59:35 +0000 |
commit | 17d0ba461daac2c49a3b3ebc299f94dc87c91393 (patch) | |
tree | 79b5073ecff56192b881b688e1114102c194bbcd | |
parent | adbe1348fc14fc502ca0dc7de3002d37398a07b9 (diff) | |
download | chromium_src-17d0ba461daac2c49a3b3ebc299f94dc87c91393.zip chromium_src-17d0ba461daac2c49a3b3ebc299f94dc87c91393.tar.gz chromium_src-17d0ba461daac2c49a3b3ebc299f94dc87c91393.tar.bz2 |
drive: Introduce DriveSystemServiceObserver
Move DriveFileSystem::NotifyFileSystemMounted() and
NotifyFileSystemToBeUnmounted() to DriveSystemServiceObserver
in favor of less things to have in DriveFileSystem
BUG=231788
TEST=none
Review URL: https://codereview.chromium.org/13866050
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194529 0039d316-1c4b-4281-b951-d872f2087c98
12 files changed, 54 insertions, 59 deletions
diff --git a/chrome/browser/chromeos/drive/drive_file_system.cc b/chrome/browser/chromeos/drive/drive_file_system.cc index b1f7ab5..6a60225 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.cc +++ b/chrome/browser/chromeos/drive/drive_file_system.cc @@ -1298,24 +1298,6 @@ void DriveFileSystem::OnInitialFeedLoaded() { OnInitialLoadFinished()); } -void DriveFileSystem::NotifyFileSystemMounted() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - DVLOG(1) << "File System is mounted"; - // Notify the observers that the file system is mounted. - FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, - OnFileSystemMounted()); -} - -void DriveFileSystem::NotifyFileSystemToBeUnmounted() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - DVLOG(1) << "File System is to be unmounted"; - // Notify the observers that the file system is being unmounted. - FOR_EACH_OBSERVER(DriveFileSystemObserver, observers_, - OnFileSystemBeingUnmounted()); -} - void DriveFileSystem::AddUploadedFile( scoped_ptr<google_apis::ResourceEntry> entry, const base::FilePath& file_content_path, diff --git a/chrome/browser/chromeos/drive/drive_file_system.h b/chrome/browser/chromeos/drive/drive_file_system.h index 4d8a316..4154336 100644 --- a/chrome/browser/chromeos/drive/drive_file_system.h +++ b/chrome/browser/chromeos/drive/drive_file_system.h @@ -66,8 +66,6 @@ class DriveFileSystem : public DriveFileSystemInterface, virtual void Initialize() OVERRIDE; virtual void AddObserver(DriveFileSystemObserver* observer) OVERRIDE; virtual void RemoveObserver(DriveFileSystemObserver* observer) OVERRIDE; - virtual void NotifyFileSystemMounted() OVERRIDE; - virtual void NotifyFileSystemToBeUnmounted() OVERRIDE; virtual void CheckForUpdates() OVERRIDE; virtual void GetEntryInfoByResourceId( const std::string& resource_id, diff --git a/chrome/browser/chromeos/drive/drive_file_system_interface.h b/chrome/browser/chromeos/drive/drive_file_system_interface.h index add7df3..7ae18dd 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_interface.h +++ b/chrome/browser/chromeos/drive/drive_file_system_interface.h @@ -155,12 +155,6 @@ class DriveFileSystemInterface { virtual void AddObserver(DriveFileSystemObserver* observer) = 0; virtual void RemoveObserver(DriveFileSystemObserver* observer) = 0; - // Notifies the file system was just mounted. - virtual void NotifyFileSystemMounted() = 0; - - // Notifies the file system is going to be unmounted. - virtual void NotifyFileSystemToBeUnmounted() = 0; - // Checks for updates on the server. virtual void CheckForUpdates() = 0; diff --git a/chrome/browser/chromeos/drive/drive_file_system_observer.h b/chrome/browser/chromeos/drive/drive_file_system_observer.h index b075189..063ca34 100644 --- a/chrome/browser/chromeos/drive/drive_file_system_observer.h +++ b/chrome/browser/chromeos/drive/drive_file_system_observer.h @@ -32,14 +32,6 @@ class DriveFileSystemObserver { virtual void OnFeedFromServerLoaded() { } - // Triggered when the file system is mounted. - virtual void OnFileSystemMounted() { - } - - // Triggered when the file system is being unmounted. - virtual void OnFileSystemBeingUnmounted() { - } - protected: virtual ~DriveFileSystemObserver() {} }; diff --git a/chrome/browser/chromeos/drive/drive_system_service.cc b/chrome/browser/chromeos/drive/drive_system_service.cc index d614465..a5095ff 100644 --- a/chrome/browser/chromeos/drive/drive_system_service.cc +++ b/chrome/browser/chromeos/drive/drive_system_service.cc @@ -191,6 +191,16 @@ void DriveSystemService::Shutdown() { RemoveDriveMountPoint(); } +void DriveSystemService::AddObserver(DriveSystemServiceObserver* observer) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + observers_.AddObserver(observer); +} + +void DriveSystemService::RemoveObserver(DriveSystemServiceObserver* observer) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); + observers_.RemoveObserver(observer); +} + bool DriveSystemService::IsDriveEnabled() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -309,14 +319,16 @@ void DriveSystemService::AddDriveMountPoint() { if (success) { event_logger_->Log("AddDriveMountPoint"); - file_system_->NotifyFileSystemMounted(); + FOR_EACH_OBSERVER(DriveSystemServiceObserver, observers_, + OnFileSystemMounted()); } } void DriveSystemService::RemoveDriveMountPoint() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - file_system_->NotifyFileSystemToBeUnmounted(); + FOR_EACH_OBSERVER(DriveSystemServiceObserver, observers_, + OnFileSystemBeingUnmounted()); fileapi::ExternalMountPoints* mount_points = BrowserContext::GetMountPoints(profile_); diff --git a/chrome/browser/chromeos/drive/drive_system_service.h b/chrome/browser/chromeos/drive/drive_system_service.h index 7e63a12..cb13044 100644 --- a/chrome/browser/chromeos/drive/drive_system_service.h +++ b/chrome/browser/chromeos/drive/drive_system_service.h @@ -11,6 +11,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/singleton.h" #include "base/memory/weak_ptr.h" +#include "base/observer_list.h" #include "base/threading/sequenced_worker_pool.h" #include "chrome/browser/chromeos/drive/drive_file_error.h" #include "chrome/browser/chromeos/drive/drive_file_system_util.h" @@ -40,6 +41,22 @@ class EventLogger; class FileWriteHelper; class StaleCacheFilesRemover; +// Interface for classes that need to observe events from DriveSystemService. +// All events are notified on UI thread. +class DriveSystemServiceObserver { + public: + // Triggered when the file system is mounted. + virtual void OnFileSystemMounted() { + } + + // Triggered when the file system is being unmounted. + virtual void OnFileSystemBeingUnmounted() { + } + + protected: + virtual ~DriveSystemServiceObserver() {} +}; + // DriveSystemService runs the Drive system, including the Drive file system // implementation for the file manager, and some other sub systems. // @@ -65,6 +82,10 @@ class DriveSystemService : public ProfileKeyedService, // ProfileKeyedService override: virtual void Shutdown() OVERRIDE; + // Adds and removes the observer. + void AddObserver(DriveSystemServiceObserver* observer); + void RemoveObserver(DriveSystemServiceObserver* observer); + google_apis::DriveServiceInterface* drive_service() { return drive_service_.get(); } @@ -152,6 +173,8 @@ class DriveSystemService : public ProfileKeyedService, scoped_ptr<StaleCacheFilesRemover> stale_cache_files_remover_; scoped_refptr<DriveFileSystemProxy> file_system_proxy_; + ObserverList<DriveSystemServiceObserver> observers_; + // Note: This should remain the last member so it'll be destroyed and // invalidate its weak pointers before any other members are destroyed. base::WeakPtrFactory<DriveSystemService> weak_ptr_factory_; diff --git a/chrome/browser/chromeos/drive/fake_drive_file_system.cc b/chrome/browser/chromeos/drive/fake_drive_file_system.cc index 211a21e..87f1852 100644 --- a/chrome/browser/chromeos/drive/fake_drive_file_system.cc +++ b/chrome/browser/chromeos/drive/fake_drive_file_system.cc @@ -42,14 +42,6 @@ void FakeDriveFileSystem::RemoveObserver(DriveFileSystemObserver* observer) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } -void FakeDriveFileSystem::NotifyFileSystemMounted() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - -void FakeDriveFileSystem::NotifyFileSystemToBeUnmounted() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); -} - void FakeDriveFileSystem::CheckForUpdates() { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); } diff --git a/chrome/browser/chromeos/drive/fake_drive_file_system.h b/chrome/browser/chromeos/drive/fake_drive_file_system.h index 254d953..1a83782 100644 --- a/chrome/browser/chromeos/drive/fake_drive_file_system.h +++ b/chrome/browser/chromeos/drive/fake_drive_file_system.h @@ -45,8 +45,6 @@ class FakeDriveFileSystem : public DriveFileSystemInterface { virtual void Initialize() OVERRIDE; virtual void AddObserver(DriveFileSystemObserver* observer) OVERRIDE; virtual void RemoveObserver(DriveFileSystemObserver* observer) OVERRIDE; - virtual void NotifyFileSystemMounted() OVERRIDE; - virtual void NotifyFileSystemToBeUnmounted() OVERRIDE; virtual void CheckForUpdates() OVERRIDE; virtual void GetEntryInfoByResourceId( const std::string& resource_id, diff --git a/chrome/browser/chromeos/drive/mock_drive_file_system.h b/chrome/browser/chromeos/drive/mock_drive_file_system.h index 8113399..9b0e81f 100644 --- a/chrome/browser/chromeos/drive/mock_drive_file_system.h +++ b/chrome/browser/chromeos/drive/mock_drive_file_system.h @@ -25,8 +25,6 @@ class MockDriveFileSystem : public DriveFileSystemInterface { MOCK_METHOD1(AddObserver, void(DriveFileSystemObserver* observer)); MOCK_METHOD1(RemoveObserver, void(DriveFileSystemObserver* observer)); - MOCK_METHOD0(NotifyFileSystemMounted, void()); - MOCK_METHOD0(NotifyFileSystemToBeUnmounted, void()); MOCK_METHOD0(CheckForUpdates, void()); MOCK_METHOD2(GetEntryInfoByResourceId, void(const std::string& resource_id, diff --git a/chrome/browser/chromeos/extensions/file_manager/drive_test_util.cc b/chrome/browser/chromeos/extensions/file_manager/drive_test_util.cc index a7a1fc2..265961b 100644 --- a/chrome/browser/chromeos/extensions/file_manager/drive_test_util.cc +++ b/chrome/browser/chromeos/extensions/file_manager/drive_test_util.cc @@ -20,31 +20,31 @@ const char kDriveMountPointName[] = "drive"; // Helper class used to wait for |OnFileSystemMounted| event from a drive file // system. -class DriveMountPointWaiter : public drive::DriveFileSystemObserver { +class DriveMountPointWaiter : public drive::DriveSystemServiceObserver { public: - explicit DriveMountPointWaiter(drive::DriveFileSystemInterface* file_system) - : file_system_(file_system) { - file_system_->AddObserver(this); + explicit DriveMountPointWaiter(drive::DriveSystemService* system_service) + : system_service_(system_service) { + system_service_->AddObserver(this); } virtual ~DriveMountPointWaiter() { - file_system_->RemoveObserver(this); + system_service_->RemoveObserver(this); } - // DriveFileSystemObserver override. + // DriveSystemServiceObserver override. virtual void OnFileSystemMounted() OVERRIDE { // Note that it is OK for |run_loop_.Quit| to be called before // |run_loop_.Run|. In this case |Run| will return immediately. run_loop_.Quit(); } - // Runs loop until the file_system_ gets mounted. + // Runs loop until the file system is mounted. void Wait() { run_loop_.Run(); } private: - drive::DriveFileSystemInterface* file_system_; + drive::DriveSystemService* system_service_; base::RunLoop run_loop_; }; @@ -63,9 +63,9 @@ void WaitUntilDriveMountPointIsAdded(Profile* profile) { drive::DriveSystemService* system_service = drive::DriveSystemServiceFactory::FindForProfileRegardlessOfStates( profile); - DCHECK(system_service && system_service->file_system()); + DCHECK(system_service); - DriveMountPointWaiter mount_point_waiter(system_service->file_system()); + DriveMountPointWaiter mount_point_waiter(system_service); base::FilePath ignored; // GetRegisteredPath succeeds iff the mount point exists. diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.cc b/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.cc index 8a1c14c..4cf9bd1 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.cc +++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.cc @@ -293,6 +293,7 @@ void FileManagerEventRouter::Shutdown() { DriveSystemService* system_service = DriveSystemServiceFactory::FindForProfileRegardlessOfStates(profile_); if (system_service) { + system_service->RemoveObserver(this); system_service->file_system()->RemoveObserver(this); system_service->drive_service()->RemoveObserver(this); } @@ -322,6 +323,7 @@ void FileManagerEventRouter::ObserveFileSystemEvents() { DriveSystemService* system_service = DriveSystemServiceFactory::GetForProfileRegardlessOfStates(profile_); if (system_service) { + system_service->AddObserver(this); system_service->drive_service()->AddObserver(this); system_service->file_system()->AddObserver(this); } diff --git a/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.h b/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.h index 9a5b327..199f58e 100644 --- a/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.h +++ b/chrome/browser/chromeos/extensions/file_manager/file_manager_event_router.h @@ -16,6 +16,7 @@ #include "base/synchronization/lock.h" #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" #include "chrome/browser/chromeos/drive/drive_resource_metadata.h" +#include "chrome/browser/chromeos/drive/drive_system_service.h" #include "chrome/browser/chromeos/net/connectivity_state_helper_observer.h" #include "chrome/browser/chromeos/system_key_event_listener.h" #include "chrome/browser/google_apis/drive_service_interface.h" @@ -37,6 +38,7 @@ class FileManagerEventRouter : public chromeos::disks::DiskMountManager::Observer, public chromeos::ConnectivityStateHelperObserver, public chromeos::SystemKeyEventListener::ModifiersObserver, + public drive::DriveSystemServiceObserver, public drive::DriveFileSystemObserver, public google_apis::DriveServiceObserver { public: @@ -109,9 +111,11 @@ class FileManagerEventRouter const google_apis::OperationProgressStatusList& list) OVERRIDE; virtual void OnRefreshTokenInvalid() OVERRIDE; - // drive::DriveFileSystemInterface::Observer overrides. + // drive::DriveFileSystemObserver overrides. virtual void OnDirectoryChanged( const base::FilePath& directory_path) OVERRIDE; + + // drive::DriveSystemServiceObserver overrides. virtual void OnFileSystemMounted() OVERRIDE; virtual void OnFileSystemBeingUnmounted() OVERRIDE; |