Commit faf8f229 authored by yoshiki@chromium.org's avatar yoshiki@chromium.org

Drive: Mount/Unmount GoogleDrive on Files App when the file system is mounted/unmounted.

This cl is necessary to refresh the list on file manager on unmounting and mounting the drive file system.

This patch does the following:
- Move the code to raise the mount/unmount events of file manager from file_browser_private_api.cc to file_browser_event_router.cc
- Add handlers' interfaces to notify mount/unmount events in gdata_file_system_interface.h.
- Call the mount/unmount events to FilesApp when handler is called.
- Call the handlers when the file system is mounted/unmounted

BUG=135197
TEST=out/Debug/unit_tests:GData* and out/Debug/browser_tests:GData* passes.

Review URL: https://chromiumcodereview.appspot.com/10834115

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149913 0039d316-1c4b-4281-b951-d872f2087c98
parent 8e65fd31
...@@ -226,6 +226,48 @@ void FileBrowserEventRouter::RemoveFileWatch( ...@@ -226,6 +226,48 @@ void FileBrowserEventRouter::RemoveFileWatch(
} }
} }
void FileBrowserEventRouter::MountDrive(
const base::Closure& callback) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
gdata::GDataSystemService* system_service =
gdata::GDataSystemServiceFactory::GetForProfile(profile_);
if (system_service) {
system_service->docs_service()->Authenticate(
base::Bind(&FileBrowserEventRouter::OnAuthenticated,
this,
callback));
}
}
void FileBrowserEventRouter::OnAuthenticated(
const base::Closure& callback,
gdata::GDataErrorCode error,
const std::string& token) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
chromeos::MountError error_code;
// For the file manager to work offline, GDATA_NO_CONNECTION is allowed.
if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION)
error_code = chromeos::MOUNT_ERROR_NONE;
else
error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED;
// Pass back the gdata mount point path as source path.
const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
DiskMountManager::MountPointInfo mount_info(
gdata_path,
gdata_path,
chromeos::MOUNT_TYPE_GDATA,
chromeos::disks::MOUNT_CONDITION_NONE);
// Raise mount event.
MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info);
if (!callback.is_null())
callback.Run();
}
void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) { void FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread(bool start) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
...@@ -416,6 +458,26 @@ void FileBrowserEventRouter::OnDocumentFeedFetched( ...@@ -416,6 +458,26 @@ void FileBrowserEventRouter::OnDocumentFeedFetched(
NULL, GURL()); NULL, GURL());
} }
void FileBrowserEventRouter::OnFileSystemMounted() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
MountDrive(base::Bind(&base::DoNothing)); // Callback does nothing.
}
void FileBrowserEventRouter::OnFileSystemBeingUnmounted() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Raise a MountCompleted event to notify the File Manager.
const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
DiskMountManager::MountPointInfo mount_info(
gdata_path,
gdata_path,
chromeos::MOUNT_TYPE_GDATA,
chromeos::disks::MOUNT_CONDITION_NONE);
MountCompleted(DiskMountManager::UNMOUNTING, chromeos::MOUNT_ERROR_NONE,
mount_info);
}
void FileBrowserEventRouter::OnAuthenticationFailed() { void FileBrowserEventRouter::OnAuthenticationFailed() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
......
...@@ -52,6 +52,10 @@ class FileBrowserEventRouter ...@@ -52,6 +52,10 @@ class FileBrowserEventRouter
void RemoveFileWatch(const FilePath& file_path, void RemoveFileWatch(const FilePath& file_path,
const std::string& extension_id); const std::string& extension_id);
// Mounts Drive on File browser. |callback| will be called after raising a
// mount request event to file manager on JS-side.
void MountDrive(const base::Closure& callback);
// CrosDisksClient::Observer overrides. // CrosDisksClient::Observer overrides.
virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event, virtual void DiskChanged(chromeos::disks::DiskMountManagerEventType event,
const chromeos::disks::DiskMountManager::Disk* disk) const chromeos::disks::DiskMountManager::Disk* disk)
...@@ -82,6 +86,8 @@ class FileBrowserEventRouter ...@@ -82,6 +86,8 @@ class FileBrowserEventRouter
// gdata::GDataFileSystemInterface::Observer overrides. // gdata::GDataFileSystemInterface::Observer overrides.
virtual void OnDirectoryChanged(const FilePath& directory_path) OVERRIDE; virtual void OnDirectoryChanged(const FilePath& directory_path) OVERRIDE;
virtual void OnDocumentFeedFetched(int num_accumulated_entries) OVERRIDE; virtual void OnDocumentFeedFetched(int num_accumulated_entries) OVERRIDE;
virtual void OnFileSystemMounted() OVERRIDE;
virtual void OnFileSystemBeingUnmounted() OVERRIDE;
private: private:
friend class FileBrowserEventRouterFactory; friend class FileBrowserEventRouterFactory;
...@@ -186,6 +192,11 @@ class FileBrowserEventRouter ...@@ -186,6 +192,11 @@ class FileBrowserEventRouter
// zero. // zero.
void HandleRemoteUpdateRequestOnUIThread(bool start); void HandleRemoteUpdateRequestOnUIThread(bool start);
// Used to implement MountDrive(). Called after the authentication.
void OnAuthenticated(const base::Closure& callback,
gdata::GDataErrorCode error,
const std::string& tokeni);
scoped_refptr<FileWatcherDelegate> delegate_; scoped_refptr<FileWatcherDelegate> delegate_;
WatcherMap file_watchers_; WatcherMap file_watchers_;
scoped_ptr<FileBrowserNotifications> notifications_; scoped_ptr<FileBrowserNotifications> notifications_;
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_vector.h" #include "base/memory/scoped_vector.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/memory/weak_ptr.h"
#include "base/string_split.h" #include "base/string_split.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/time.h" #include "base/time.h"
...@@ -1089,13 +1088,11 @@ bool AddMountFunction::RunImpl() { ...@@ -1089,13 +1088,11 @@ bool AddMountFunction::RunImpl() {
break; break;
} }
case chromeos::MOUNT_TYPE_GDATA: { case chromeos::MOUNT_TYPE_GDATA: {
gdata::GDataSystemService* system_service = const bool success = true;
gdata::GDataSystemServiceFactory::GetForProfile(profile_); FileBrowserEventRouterFactory::GetForProfile(profile_)->
if (system_service) { MountDrive(base::Bind(&AddMountFunction::SendResponse,
system_service->docs_service()->Authenticate( this,
base::Bind(&AddMountFunction::OnGDataAuthentication, success));
this));
}
break; break;
} }
default: { default: {
...@@ -1114,33 +1111,6 @@ bool AddMountFunction::RunImpl() { ...@@ -1114,33 +1111,6 @@ bool AddMountFunction::RunImpl() {
return true; return true;
} }
void AddMountFunction::RaiseGDataMountEvent(gdata::GDataErrorCode error) {
chromeos::MountError error_code = chromeos::MOUNT_ERROR_NONE;
// For the file manager to work offline, GDATA_NO_CONNECTION is allowed.
if (error == gdata::HTTP_SUCCESS || error == gdata::GDATA_NO_CONNECTION) {
error_code = chromeos::MOUNT_ERROR_NONE;
} else {
error_code = chromeos::MOUNT_ERROR_NOT_AUTHENTICATED;
}
// Pass back the gdata mount point path as source path.
const std::string& gdata_path = gdata::util::GetGDataMountPointPathAsString();
SetResult(Value::CreateStringValue(gdata_path));
DiskMountManager::MountPointInfo mount_info(
gdata_path,
gdata_path,
chromeos::MOUNT_TYPE_GDATA,
chromeos::disks::MOUNT_CONDITION_NONE);
// Raise mount event
FileBrowserEventRouterFactory::GetForProfile(profile_)->
MountCompleted(DiskMountManager::MOUNTING, error_code, mount_info);
}
void AddMountFunction::OnGDataAuthentication(gdata::GDataErrorCode error,
const std::string& token) {
RaiseGDataMountEvent(error);
SendResponse(true);
}
void AddMountFunction::GetLocalPathsResponseOnUIThread( void AddMountFunction::GetLocalPathsResponseOnUIThread(
const std::string& mount_type_str, const std::string& mount_type_str,
const SelectedFileInfoList& files) { const SelectedFileInfoList& files) {
......
...@@ -276,11 +276,6 @@ class AddMountFunction : public FileBrowserFunction { ...@@ -276,11 +276,6 @@ class AddMountFunction : public FileBrowserFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
private: private:
// Sends gdata mount event to renderers.
void RaiseGDataMountEvent(gdata::GDataErrorCode error);
// A callback method to handle the result of GData authentication request.
void OnGDataAuthentication(gdata::GDataErrorCode error,
const std::string& token);
// A callback method to handle the result of // A callback method to handle the result of
// GetLocalPathsOnFileThreadAndRunCallbackOnUIThread. // GetLocalPathsOnFileThreadAndRunCallbackOnUIThread.
void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str, void GetLocalPathsResponseOnUIThread(const std::string& mount_type_str,
......
...@@ -886,9 +886,16 @@ void GDataFileSystem::StartUpdates() { ...@@ -886,9 +886,16 @@ void GDataFileSystem::StartUpdates() {
} }
void GDataFileSystem::StopUpdates() { void GDataFileSystem::StopUpdates() {
// If unmount request comes from filesystem side, this method may be called
// twice. First is just after unmounting on filesystem, second is after
// unmounting on filemanager on JS. In other words, if this is called from
// GDataSystemService::RemoveDriveMountPoint(), this will be called again from
// FileBrowserEventRouter::HandleRemoteUpdateRequestOnUIThread().
// We choose to stopping updates asynchronous without waiting for filemanager,
// rather than waiting for completion of unmounting on filemanager.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(update_timer_.IsRunning()); if (update_timer_.IsRunning())
update_timer_.Stop(); update_timer_.Stop();
} }
void GDataFileSystem::GetEntryInfoByResourceId( void GDataFileSystem::GetEntryInfoByResourceId(
...@@ -3478,6 +3485,24 @@ void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id, ...@@ -3478,6 +3485,24 @@ void GDataFileSystem::RemoveStaleEntryOnUpload(const std::string& resource_id,
} }
} }
void GDataFileSystem::NotifyFileSystemMounted() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DVLOG(1) << "File System is mounted";
// Notify the observers that the file system is mounted.
FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
OnFileSystemMounted());
}
void GDataFileSystem::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(GDataFileSystemInterface::Observer, observers_,
OnFileSystemBeingUnmounted());
}
void GDataFileSystem::RunAndNotifyInitialLoadFinished( void GDataFileSystem::RunAndNotifyInitialLoadFinished(
const FindEntryCallback& callback, const FindEntryCallback& callback,
GDataFileError error, GDataFileError error,
......
...@@ -213,6 +213,8 @@ class GDataFileSystem : public GDataFileSystemInterface, ...@@ -213,6 +213,8 @@ class GDataFileSystem : public GDataFileSystemInterface,
GDataFileSystemInterface::Observer* observer) OVERRIDE; GDataFileSystemInterface::Observer* observer) OVERRIDE;
virtual void StartUpdates() OVERRIDE; virtual void StartUpdates() OVERRIDE;
virtual void StopUpdates() OVERRIDE; virtual void StopUpdates() OVERRIDE;
virtual void NotifyFileSystemMounted() OVERRIDE;
virtual void NotifyFileSystemToBeUnmounted() OVERRIDE;
virtual void CheckForUpdates() OVERRIDE; virtual void CheckForUpdates() OVERRIDE;
virtual void GetEntryInfoByResourceId( virtual void GetEntryInfoByResourceId(
const std::string& resource_id, const std::string& resource_id,
......
...@@ -107,6 +107,11 @@ class GDataFileSystemInterface { ...@@ -107,6 +107,11 @@ class GDataFileSystemInterface {
// Triggered when the feed from the server is loaded. // Triggered when the feed from the server is loaded.
virtual void OnFeedFromServerLoaded() {} 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: protected:
virtual ~Observer() {} virtual ~Observer() {}
}; };
...@@ -123,6 +128,12 @@ class GDataFileSystemInterface { ...@@ -123,6 +128,12 @@ class GDataFileSystemInterface {
virtual void StartUpdates() = 0; virtual void StartUpdates() = 0;
virtual void StopUpdates() = 0; virtual void StopUpdates() = 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. // Checks for updates on the server.
virtual void CheckForUpdates() = 0; virtual void CheckForUpdates() = 0;
......
...@@ -118,9 +118,15 @@ void GDataSystemService::AddDriveMountPoint() { ...@@ -118,9 +118,15 @@ void GDataSystemService::AddDriveMountPoint() {
mount_point, mount_point,
new GDataFileSystemProxy(file_system_.get())); new GDataFileSystemProxy(file_system_.get()));
} }
file_system_->Initialize();
file_system_->NotifyFileSystemMounted();
} }
void GDataSystemService::RemoveDriveMountPoint() { void GDataSystemService::RemoveDriveMountPoint() {
file_system_->NotifyFileSystemToBeUnmounted();
file_system_->StopUpdates();
const FilePath mount_point = gdata::util::GetGDataMountPointPath(); const FilePath mount_point = gdata::util::GetGDataMountPointPath();
fileapi::ExternalFileSystemMountPointProvider* provider = fileapi::ExternalFileSystemMountPointProvider* provider =
BrowserContext::GetFileSystemContext(profile_)->external_provider(); BrowserContext::GetFileSystemContext(profile_)->external_provider();
......
...@@ -24,6 +24,8 @@ class MockGDataFileSystem : public GDataFileSystemInterface { ...@@ -24,6 +24,8 @@ class MockGDataFileSystem : public GDataFileSystemInterface {
MOCK_METHOD1(RemoveObserver, void(Observer* observer)); MOCK_METHOD1(RemoveObserver, void(Observer* observer));
MOCK_METHOD0(StartUpdates, void()); MOCK_METHOD0(StartUpdates, void());
MOCK_METHOD0(StopUpdates, void()); MOCK_METHOD0(StopUpdates, void());
MOCK_METHOD0(NotifyFileSystemMounted, void());
MOCK_METHOD0(NotifyFileSystemToBeUnmounted, void());
MOCK_METHOD0(CheckForUpdates, void()); MOCK_METHOD0(CheckForUpdates, void());
MOCK_METHOD2(GetEntryInfoByResourceId, MOCK_METHOD2(GetEntryInfoByResourceId,
void(const std::string& resource_id, void(const std::string& resource_id,
......
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