summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 14:25:32 +0000
committerkinaba@chromium.org <kinaba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-20 14:25:32 +0000
commitdd4a26fc4de5baaa9888d87a3e9c96ceb5227985 (patch)
treebc7cb8177c9eddc7bad70252896ac9cb9a6ac671
parent8366350f1a997675ce4ec69e81446292dbc154c9 (diff)
downloadchromium_src-dd4a26fc4de5baaa9888d87a3e9c96ceb5227985.zip
chromium_src-dd4a26fc4de5baaa9888d87a3e9c96ceb5227985.tar.gz
chromium_src-dd4a26fc4de5baaa9888d87a3e9c96ceb5227985.tar.bz2
Implement cross profile Drive file sharing private API.
BUG=348476 Review URL: https://codereview.chromium.org/195763019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258274 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/drive/dummy_file_system.h4
-rw-r--r--chrome/browser/chromeos/drive/fake_file_system.cc7
-rw-r--r--chrome/browser/chromeos/drive/fake_file_system.h4
-rw-r--r--chrome/browser/chromeos/drive/file_system.cc51
-rw-r--r--chrome/browser/chromeos/drive/file_system.h11
-rw-r--r--chrome/browser/chromeos/drive/file_system_interface.h7
-rw-r--r--chrome/browser/chromeos/drive/job_list.cc3
-rw-r--r--chrome/browser/chromeos/drive/job_list.h1
-rw-r--r--chrome/browser/chromeos/drive/job_scheduler.cc23
-rw-r--r--chrome/browser/chromeos/drive/job_scheduler.h6
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc55
-rw-r--r--chrome/browser/chromeos/extensions/file_manager/private_api_drive.h4
12 files changed, 174 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/drive/dummy_file_system.h b/chrome/browser/chromeos/drive/dummy_file_system.h
index 3f65ecd..493b59c 100644
--- a/chrome/browser/chromeos/drive/dummy_file_system.h
+++ b/chrome/browser/chromeos/drive/dummy_file_system.h
@@ -91,6 +91,10 @@ class DummyFileSystem : public FileSystemInterface {
const FileOperationCallback& callback) OVERRIDE {}
virtual void GetCacheEntry(const base::FilePath& drive_file_path,
const GetCacheEntryCallback& callback) OVERRIDE {}
+ virtual void AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) OVERRIDE {}
virtual void Reset(const FileOperationCallback& callback) OVERRIDE {}
};
diff --git a/chrome/browser/chromeos/drive/fake_file_system.cc b/chrome/browser/chromeos/drive/fake_file_system.cc
index 99f4def..97dca44 100644
--- a/chrome/browser/chromeos/drive/fake_file_system.cc
+++ b/chrome/browser/chromeos/drive/fake_file_system.cc
@@ -221,6 +221,13 @@ void FakeFileSystem::GetCacheEntry(
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
}
+void FakeFileSystem::AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
void FakeFileSystem::Reset(const FileOperationCallback& callback) {
}
diff --git a/chrome/browser/chromeos/drive/fake_file_system.h b/chrome/browser/chromeos/drive/fake_file_system.h
index c152c80..e93a021 100644
--- a/chrome/browser/chromeos/drive/fake_file_system.h
+++ b/chrome/browser/chromeos/drive/fake_file_system.h
@@ -122,6 +122,10 @@ class FakeFileSystem : public FileSystemInterface {
virtual void GetCacheEntry(
const base::FilePath& drive_file_path,
const GetCacheEntryCallback& callback) OVERRIDE;
+ virtual void AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) OVERRIDE;
virtual void Reset(const FileOperationCallback& callback) OVERRIDE;
private:
diff --git a/chrome/browser/chromeos/drive/file_system.cc b/chrome/browser/chromeos/drive/file_system.cc
index 69f9a09..724b185 100644
--- a/chrome/browser/chromeos/drive/file_system.cc
+++ b/chrome/browser/chromeos/drive/file_system.cc
@@ -229,6 +229,13 @@ void FilterHostedDocuments(const ReadDirectoryCallback& callback,
callback.Run(error, entries.Pass(), has_more);
}
+// Adapter for using FileOperationCallback as google_apis::EntryActionCallback.
+void RunFileOperationCallbackAsEntryActionCallback(
+ const FileOperationCallback& callback,
+ google_apis::GDataErrorCode error) {
+ callback.Run(GDataToFileError(error));
+}
+
} // namespace
struct FileSystem::CreateDirectoryParams {
@@ -926,6 +933,50 @@ void FileSystem::GetCacheEntry(
base::Owned(cache_entry)));
}
+void FileSystem::AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ // Resolve the resource id.
+ ResourceEntry* const entry = new ResourceEntry;
+ base::PostTaskAndReplyWithResult(
+ blocking_task_runner_.get(),
+ FROM_HERE,
+ base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
+ base::Unretained(resource_metadata_),
+ drive_file_path,
+ entry),
+ base::Bind(&FileSystem::AddPermissionAfterGetResourceEntry,
+ weak_ptr_factory_.GetWeakPtr(),
+ email,
+ role,
+ callback,
+ base::Owned(entry)));
+}
+
+void FileSystem::AddPermissionAfterGetResourceEntry(
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback,
+ ResourceEntry* entry,
+ FileError error) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ if (error != FILE_ERROR_OK) {
+ callback.Run(error);
+ return;
+ }
+
+ scheduler_->AddPermission(
+ entry->resource_id(),
+ email,
+ role,
+ base::Bind(&RunFileOperationCallbackAsEntryActionCallback, callback));
+}
+
void FileSystem::OpenFile(const base::FilePath& file_path,
OpenMode open_mode,
const std::string& mime_type,
diff --git a/chrome/browser/chromeos/drive/file_system.h b/chrome/browser/chromeos/drive/file_system.h
index e5bb77c..28539fb 100644
--- a/chrome/browser/chromeos/drive/file_system.h
+++ b/chrome/browser/chromeos/drive/file_system.h
@@ -155,6 +155,10 @@ class FileSystem : public FileSystemInterface,
virtual void GetCacheEntry(
const base::FilePath& drive_file_path,
const GetCacheEntryCallback& callback) OVERRIDE;
+ virtual void AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) OVERRIDE;
virtual void Reset(const FileOperationCallback& callback) OVERRIDE;
// file_system::OperationObserver overrides.
@@ -227,6 +231,13 @@ class FileSystem : public FileSystemInterface,
void OnGetResourceEntryForGetShareUrl(const GetShareUrlCallback& callback,
google_apis::GDataErrorCode status,
const GURL& share_url);
+ // Part of AddPermission.
+ void AddPermissionAfterGetResourceEntry(
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback,
+ ResourceEntry* entry,
+ FileError error);
// Part of OnDriveSyncError().
virtual void OnDriveSyncErrorAfterGetFilePath(
diff --git a/chrome/browser/chromeos/drive/file_system_interface.h b/chrome/browser/chromeos/drive/file_system_interface.h
index 6de182a..6633c8c 100644
--- a/chrome/browser/chromeos/drive/file_system_interface.h
+++ b/chrome/browser/chromeos/drive/file_system_interface.h
@@ -423,6 +423,13 @@ class FileSystemInterface {
virtual void GetCacheEntry(const base::FilePath& drive_file_path,
const GetCacheEntryCallback& callback) = 0;
+ // Adds permission as |role| to |email| for the entry at |drive_file_path|.
+ // |callback| must not be null.
+ virtual void AddPermission(const base::FilePath& drive_file_path,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const FileOperationCallback& callback) = 0;
+
// Resets local data.
virtual void Reset(const FileOperationCallback& callback) = 0;
};
diff --git a/chrome/browser/chromeos/drive/job_list.cc b/chrome/browser/chromeos/drive/job_list.cc
index 57451a5..8b940c5 100644
--- a/chrome/browser/chromeos/drive/job_list.cc
+++ b/chrome/browser/chromeos/drive/job_list.cc
@@ -58,6 +58,8 @@ std::string JobTypeToString(JobType type) {
return "TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI";
case TYPE_GET_REMAINING_RESOURCE_LIST:
return "TYPE_GET_REMAINING_RESOURCE_LIST";
+ case TYPE_ADD_PERMISSION:
+ return "TYPE_ADD_PERMISSION";
}
NOTREACHED();
return "(unknown job type)";
@@ -133,6 +135,7 @@ bool IsActiveFileTransferJobInfo(const JobInfo& job_info) {
case TYPE_CREATE_FILE:
case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI:
case TYPE_GET_REMAINING_RESOURCE_LIST:
+ case TYPE_ADD_PERMISSION:
return false;
case TYPE_DOWNLOAD_FILE:
case TYPE_UPLOAD_NEW_FILE:
diff --git a/chrome/browser/chromeos/drive/job_list.h b/chrome/browser/chromeos/drive/job_list.h
index 4df5501..0d15449 100644
--- a/chrome/browser/chromeos/drive/job_list.h
+++ b/chrome/browser/chromeos/drive/job_list.h
@@ -38,6 +38,7 @@ enum JobType {
TYPE_CREATE_FILE,
TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI,
TYPE_GET_REMAINING_RESOURCE_LIST,
+ TYPE_ADD_PERMISSION,
};
// Returns the string representation of |type|.
diff --git a/chrome/browser/chromeos/drive/job_scheduler.cc b/chrome/browser/chromeos/drive/job_scheduler.cc
index 2dbaf846..ee8479a 100644
--- a/chrome/browser/chromeos/drive/job_scheduler.cc
+++ b/chrome/browser/chromeos/drive/job_scheduler.cc
@@ -734,6 +734,28 @@ void JobScheduler::GetRemainingResourceList(
StartJob(new_job);
}
+void JobScheduler::AddPermission(
+ const std::string& resource_id,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const google_apis::EntryActionCallback& callback) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ DCHECK(!callback.is_null());
+
+ JobEntry* new_job = CreateNewJob(TYPE_ADD_PERMISSION);
+ new_job->task = base::Bind(&DriveServiceInterface::AddPermission,
+ base::Unretained(drive_service_),
+ resource_id,
+ email,
+ role,
+ base::Bind(&JobScheduler::OnEntryActionJobDone,
+ weak_ptr_factory_.GetWeakPtr(),
+ new_job->job_info.job_id,
+ callback));
+ new_job->abort_callback = callback;
+ StartJob(new_job);
+}
+
JobScheduler::JobEntry* JobScheduler::CreateNewJob(JobType type) {
JobEntry* job = new JobEntry(type);
job->job_info.job_id = job_map_.Add(job); // Takes the ownership of |job|.
@@ -1101,6 +1123,7 @@ JobScheduler::QueueType JobScheduler::GetJobQueueType(JobType type) {
case TYPE_CREATE_FILE:
case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY_BY_WAPI:
case TYPE_GET_REMAINING_RESOURCE_LIST:
+ case TYPE_ADD_PERMISSION:
return METADATA_QUEUE;
case TYPE_DOWNLOAD_FILE:
diff --git a/chrome/browser/chromeos/drive/job_scheduler.h b/chrome/browser/chromeos/drive/job_scheduler.h
index b7aed81..416e66d 100644
--- a/chrome/browser/chromeos/drive/job_scheduler.h
+++ b/chrome/browser/chromeos/drive/job_scheduler.h
@@ -219,6 +219,12 @@ class JobScheduler
const GURL& next_link,
const google_apis::GetResourceListCallback& callback);
+ // Adds AddPermission operation to the queue. |callback| must not be null.
+ void AddPermission(const std::string& resource_id,
+ const std::string& email,
+ google_apis::drive::PermissionRole role,
+ const google_apis::EntryActionCallback& callback);
+
private:
friend class JobSchedulerTest;
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc
index b2bde8f..0f683d1 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "chrome/browser/chromeos/file_manager/url_util.h"
#include "chrome/browser/chromeos/fileapi/file_system_backend.h"
+#include "chrome/browser/chromeos/login/user_manager.h"
#include "chrome/browser/drive/drive_app_registry.h"
#include "chrome/browser/drive/event_logger.h"
#include "chrome/browser/profiles/profile.h"
@@ -694,8 +695,58 @@ void FileBrowserPrivateGetShareUrlFunction::OnGetShareUrl(
}
bool FileBrowserPrivateRequestDriveShareFunction::RunImpl() {
- NOTIMPLEMENTED();
- return false;
+ using extensions::api::file_browser_private::RequestDriveShare::Params;
+ const scoped_ptr<Params> params(Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ const base::FilePath path = file_manager::util::GetLocalPathFromURL(
+ render_view_host(), GetProfile(), GURL(params->url));
+ const base::FilePath drive_path = drive::util::ExtractDrivePath(path);
+ Profile* const owner_profile = drive::util::ExtractProfileFromPath(path);
+
+ if (!owner_profile)
+ return false;
+
+ drive::FileSystemInterface* const owner_file_system =
+ drive::util::GetFileSystemByProfile(owner_profile);
+ if (!owner_file_system)
+ return false;
+
+ const chromeos::User* const user =
+ chromeos::UserManager::Get()->GetUserByProfile(GetProfile());
+ if (!user || !user->is_logged_in())
+ return false;
+
+ google_apis::drive::PermissionRole role =
+ google_apis::drive::PERMISSION_ROLE_READER;
+ switch (params->share_type) {
+ case api::file_browser_private::DRIVE_SHARE_TYPE_NONE:
+ NOTREACHED();
+ return false;
+ case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_EDIT:
+ role = google_apis::drive::PERMISSION_ROLE_WRITER;
+ break;
+ case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_COMMENT:
+ role = google_apis::drive::PERMISSION_ROLE_COMMENTER;
+ break;
+ case api::file_browser_private::DRIVE_SHARE_TYPE_CAN_VIEW:
+ role = google_apis::drive::PERMISSION_ROLE_READER;
+ break;
+ }
+
+ // Share |drive_path| in |owner_file_system| to |user->email()|.
+ owner_file_system->AddPermission(
+ drive_path,
+ user->email(),
+ role,
+ base::Bind(&FileBrowserPrivateRequestDriveShareFunction::OnAddPermission,
+ this));
+ return true;
+}
+
+void FileBrowserPrivateRequestDriveShareFunction::OnAddPermission(
+ drive::FileError error) {
+ SendResponse(error == drive::FILE_ERROR_OK);
}
} // namespace extensions
diff --git a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.h b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.h
index dfd5a35..970444e 100644
--- a/chrome/browser/chromeos/extensions/file_manager/private_api_drive.h
+++ b/chrome/browser/chromeos/extensions/file_manager/private_api_drive.h
@@ -241,6 +241,10 @@ class FileBrowserPrivateRequestDriveShareFunction
protected:
virtual ~FileBrowserPrivateRequestDriveShareFunction() {}
virtual bool RunImpl() OVERRIDE;
+
+ private:
+ // Called back after the drive file system operation is finished.
+ void OnAddPermission(drive::FileError error);
};
} // namespace extensions