Commit 17d0ba46 authored by satorux@chromium.org's avatar satorux@chromium.org

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
parent adbe1348
......@@ -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,
......
......@@ -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,
......
......@@ -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;
......
......@@ -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() {}
};
......
......@@ -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_);
......
......@@ -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_;
......
......@@ -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));
}
......
......@@ -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,
......
......@@ -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,
......
......@@ -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.
......
......@@ -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);
}
......
......@@ -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;
......
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