Commit 95dc7bfd authored by mtomasz's avatar mtomasz Committed by Commit bot

[fsp] Generalize fileBrowserPrivate.getEntryProperties().

This patch makes the method providing additional metadata for entries available
for provided file systems too.

NOTRY=True
TEST=Tested manually. Files app works as before.
BUG=408017

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

Cr-Commit-Position: refs/heads/master@{#292851}
parent af2ddaa0
......@@ -35,7 +35,7 @@ using file_manager::util::EntryDefinitionList;
using file_manager::util::EntryDefinitionListCallback;
using file_manager::util::FileDefinition;
using file_manager::util::FileDefinitionList;
using extensions::api::file_browser_private::DriveEntryProperties;
using extensions::api::file_browser_private::EntryProperties;
namespace extensions {
namespace {
......@@ -54,9 +54,9 @@ const char kDriveConnectionReasonNoService[] = "no_service";
// Copies properties from |entry_proto| to |properties|. |shared_with_me| is
// given from the running profile.
void FillDriveEntryPropertiesValue(const drive::ResourceEntry& entry_proto,
void FillEntryPropertiesValue(const drive::ResourceEntry& entry_proto,
bool shared_with_me,
DriveEntryProperties* properties) {
EntryProperties* properties) {
properties->shared_with_me.reset(new bool(shared_with_me));
properties->shared.reset(new bool(entry_proto.shared()));
......@@ -145,55 +145,52 @@ void ConvertSearchResultInfoListToEntryDefinitionList(
callback);
}
class SingleDriveEntryPropertiesGetter {
class SingleEntryPropertiesGetterForDrive {
public:
typedef base::Callback<void(drive::FileError error)> ResultCallback;
typedef base::Callback<void(scoped_ptr<EntryProperties> properties,
base::File::Error error)> ResultCallback;
// Creates an instance and starts the process.
static void Start(const base::FilePath local_path,
linked_ptr<DriveEntryProperties> properties,
Profile* const profile,
const ResultCallback& callback) {
SingleDriveEntryPropertiesGetter* instance =
new SingleDriveEntryPropertiesGetter(
local_path, properties, profile, callback);
SingleEntryPropertiesGetterForDrive* instance =
new SingleEntryPropertiesGetterForDrive(local_path, profile, callback);
instance->StartProcess();
// The instance will be destroyed by itself.
}
virtual ~SingleDriveEntryPropertiesGetter() {}
virtual ~SingleEntryPropertiesGetterForDrive() {}
private:
// Given parameters.
const ResultCallback callback_;
const base::FilePath local_path_;
const linked_ptr<DriveEntryProperties> properties_;
Profile* const running_profile_;
// Values used in the process.
scoped_ptr<EntryProperties> properties_;
Profile* file_owner_profile_;
base::FilePath file_path_;
scoped_ptr<drive::ResourceEntry> owner_resource_entry_;
base::WeakPtrFactory<SingleDriveEntryPropertiesGetter> weak_ptr_factory_;
base::WeakPtrFactory<SingleEntryPropertiesGetterForDrive> weak_ptr_factory_;
SingleDriveEntryPropertiesGetter(const base::FilePath local_path,
linked_ptr<DriveEntryProperties> properties,
SingleEntryPropertiesGetterForDrive(const base::FilePath local_path,
Profile* const profile,
const ResultCallback& callback)
: callback_(callback),
local_path_(local_path),
properties_(properties),
running_profile_(profile),
properties_(new EntryProperties),
file_owner_profile_(NULL),
weak_ptr_factory_(this) {
DCHECK(!callback_.is_null());
DCHECK(profile);
}
base::WeakPtr<SingleDriveEntryPropertiesGetter> GetWeakPtr() {
base::WeakPtr<SingleEntryPropertiesGetterForDrive> GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
......@@ -206,7 +203,7 @@ class SingleDriveEntryPropertiesGetter {
if (!file_owner_profile_ ||
!g_browser_process->profile_manager()->IsValidProfile(
file_owner_profile_)) {
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
return;
}
......@@ -215,13 +212,13 @@ class SingleDriveEntryPropertiesGetter {
drive::util::GetFileSystemByProfile(file_owner_profile_);
if (!file_system) {
// |file_system| is NULL if Drive is disabled or not mounted.
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
return;
}
file_system->GetResourceEntry(
file_path_,
base::Bind(&SingleDriveEntryPropertiesGetter::OnGetFileInfo,
base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetFileInfo,
GetWeakPtr()));
}
......@@ -230,7 +227,7 @@ class SingleDriveEntryPropertiesGetter {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != drive::FILE_ERROR_OK) {
CompleteGetFileProperties(error);
CompleteGetEntryProperties(error);
return;
}
......@@ -247,12 +244,12 @@ class SingleDriveEntryPropertiesGetter {
drive::FileSystemInterface* const file_system =
drive::util::GetFileSystemByProfile(running_profile_);
if (!file_system) {
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
return;
}
file_system->GetPathFromResourceId(
owner_resource_entry_->resource_id(),
base::Bind(&SingleDriveEntryPropertiesGetter::OnGetRunningPath,
base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetRunningPath,
GetWeakPtr()));
}
......@@ -276,7 +273,7 @@ class SingleDriveEntryPropertiesGetter {
file_system->GetResourceEntry(
file_path,
base::Bind(&SingleDriveEntryPropertiesGetter::OnGetShareInfo,
base::Bind(&SingleEntryPropertiesGetterForDrive::OnGetShareInfo,
GetWeakPtr()));
}
......@@ -285,7 +282,7 @@ class SingleDriveEntryPropertiesGetter {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
if (error != drive::FILE_ERROR_OK) {
CompleteGetFileProperties(error);
CompleteGetEntryProperties(error);
return;
}
......@@ -296,7 +293,7 @@ class SingleDriveEntryPropertiesGetter {
void StartParseFileInfo(bool shared_with_me) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
FillDriveEntryPropertiesValue(
FillEntryPropertiesValue(
*owner_resource_entry_, shared_with_me, properties_.get());
drive::FileSystemInterface* const file_system =
......@@ -305,14 +302,14 @@ class SingleDriveEntryPropertiesGetter {
drive::util::GetDriveAppRegistryByProfile(file_owner_profile_);
if (!file_system || !app_registry) {
// |file_system| or |app_registry| is NULL if Drive is disabled.
CompleteGetFileProperties(drive::FILE_ERROR_FAILED);
CompleteGetEntryProperties(drive::FILE_ERROR_FAILED);
return;
}
// The properties meaningful for directories are already filled in
// FillDriveEntryPropertiesValue().
// FillEntryPropertiesValue().
if (!owner_resource_entry_->has_file_specific_info()) {
CompleteGetFileProperties(drive::FILE_ERROR_OK);
CompleteGetEntryProperties(drive::FILE_ERROR_OK);
return;
}
......@@ -345,64 +342,85 @@ class SingleDriveEntryPropertiesGetter {
}
}
CompleteGetFileProperties(drive::FILE_ERROR_OK);
CompleteGetEntryProperties(drive::FILE_ERROR_OK);
}
void CompleteGetFileProperties(drive::FileError error) {
void CompleteGetEntryProperties(drive::FileError error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(!callback_.is_null());
callback_.Run(error);
callback_.Run(properties_.Pass(), drive::FileErrorToBaseFileError(error));
delete this;
}
}; // class SingleDriveEntryPropertiesGetter
}; // class SingleEntryPropertiesGetterForDrive
} // namespace
FileBrowserPrivateGetDriveEntryPropertiesFunction::
FileBrowserPrivateGetDriveEntryPropertiesFunction()
: processed_count_(0) {}
FileBrowserPrivateGetEntryPropertiesFunction::
FileBrowserPrivateGetEntryPropertiesFunction()
: processed_count_(0) {
}
FileBrowserPrivateGetDriveEntryPropertiesFunction::
~FileBrowserPrivateGetDriveEntryPropertiesFunction() {}
FileBrowserPrivateGetEntryPropertiesFunction::
~FileBrowserPrivateGetEntryPropertiesFunction() {
}
bool FileBrowserPrivateGetDriveEntryPropertiesFunction::RunAsync() {
bool FileBrowserPrivateGetEntryPropertiesFunction::RunAsync() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
using api::file_browser_private::GetDriveEntryProperties::Params;
using api::file_browser_private::GetEntryProperties::Params;
const scoped_ptr<Params> params(Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params);
properties_list_.resize(params->file_urls.size());
scoped_refptr<storage::FileSystemContext> file_system_context =
file_manager::util::GetFileSystemContextForRenderViewHost(
GetProfile(), render_view_host());
properties_list_.resize(params->file_urls.size());
for (size_t i = 0; i < params->file_urls.size(); i++) {
const GURL url = GURL(params->file_urls[i]);
const base::FilePath local_path = file_manager::util::GetLocalPathFromURL(
render_view_host(), GetProfile(), url);
properties_list_[i] = make_linked_ptr(new DriveEntryProperties);
SingleDriveEntryPropertiesGetter::Start(
local_path,
properties_list_[i],
const storage::FileSystemURL file_system_url =
file_system_context->CrackURL(url);
switch (file_system_url.type()) {
case storage::kFileSystemTypeDrive:
SingleEntryPropertiesGetterForDrive::Start(
file_system_url.path(),
GetProfile(),
base::Bind(&FileBrowserPrivateGetDriveEntryPropertiesFunction::
CompleteGetFileProperties,
this));
base::Bind(&FileBrowserPrivateGetEntryPropertiesFunction::
CompleteGetEntryProperties,
this,
i));
break;
case storage::kFileSystemTypeProvided:
// TODO(mtomasz): Add support for provided file systems.
NOTIMPLEMENTED();
break;
default:
LOG(ERROR) << "Not supported file system type.";
CompleteGetEntryProperties(i,
make_scoped_ptr(new EntryProperties),
base::File::FILE_ERROR_INVALID_OPERATION);
}
}
return true;
}
void FileBrowserPrivateGetDriveEntryPropertiesFunction::
CompleteGetFileProperties(drive::FileError error) {
void FileBrowserPrivateGetEntryPropertiesFunction::CompleteGetEntryProperties(
size_t index,
scoped_ptr<EntryProperties> properties,
base::File::Error error) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
DCHECK(0 <= processed_count_ && processed_count_ < properties_list_.size());
properties_list_[index] = make_linked_ptr(properties.release());
processed_count_++;
if (processed_count_ < properties_list_.size())
return;
results_ = extensions::api::file_browser_private::GetDriveEntryProperties::
results_ = extensions::api::file_browser_private::GetEntryProperties::
Results::Create(properties_list_);
SendResponse(true);
}
......
......@@ -7,6 +7,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_MANAGER_PRIVATE_API_DRIVE_H_
#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/chromeos/drive/file_errors.h"
#include "chrome/browser/chromeos/drive/file_system_interface.h"
#include "chrome/browser/chromeos/extensions/file_manager/private_api_base.h"
......@@ -26,32 +28,35 @@ namespace extensions {
namespace api {
namespace file_browser_private {
struct DriveEntryProperties;
struct EntryProperties;
} // namespace file_browser_private
} // namespace api
// Retrieves property information for an entry and returns it as a dictionary.
// On error, returns a dictionary with the key "error" set to the error number
// (drive::FileError).
class FileBrowserPrivateGetDriveEntryPropertiesFunction
// (base::File::Error).
class FileBrowserPrivateGetEntryPropertiesFunction
: public LoggedAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getDriveEntryProperties",
FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES)
DECLARE_EXTENSION_FUNCTION("fileBrowserPrivate.getEntryProperties",
FILEBROWSERPRIVATE_GETENTRYPROPERTIES)
FileBrowserPrivateGetDriveEntryPropertiesFunction();
FileBrowserPrivateGetEntryPropertiesFunction();
protected:
virtual ~FileBrowserPrivateGetDriveEntryPropertiesFunction();
virtual ~FileBrowserPrivateGetEntryPropertiesFunction();
// AsyncExtensionFunction overrides.
virtual bool RunAsync() OVERRIDE;
private:
void CompleteGetFileProperties(drive::FileError error);
void CompleteGetEntryProperties(
size_t index,
scoped_ptr<api::file_browser_private::EntryProperties> properties,
base::File::Error error);
size_t processed_count_;
std::vector<linked_ptr<api::file_browser_private::DriveEntryProperties> >
std::vector<linked_ptr<api::file_browser_private::EntryProperties> >
properties_list_;
};
......
......@@ -173,8 +173,8 @@ dictionary FileTask {
boolean isDefault;
};
// Drive file properties.
dictionary DriveEntryProperties {
// Additional entry properties.
dictionary EntryProperties {
// Size of this file.
double? fileSize;
......@@ -477,12 +477,13 @@ callback AddFileWatchCallback = void(optional boolean success);
callback RemoveFileWatchCallback = void(optional boolean success);
// |fileSystem| A DOMFileSystem instance for local file system access. null if
// |the caller has no appropriate permissions.
// the caller has no appropriate permissions.
callback RequestFileSystemCallback = void(optional object fileSystem);
// |fileProperties| A dictionary containing properties of the requested entries.
callback GetDriveEntryPropertiesCallback =
void(DriveEntryProperties[] entryProperties);
// |entryProperties| A dictionary containing properties of the requested
// entries.
callback GetEntryPropertiesCallback =
void(EntryProperties[] entryProperties);
// |localFilePaths| An array of the local file paths for the requested files,
// one entry for each file in fileUrls.
......@@ -628,12 +629,12 @@ interface Functions {
boolean shouldReturnLocalPath,
SimpleCallback callback);
// Requests Drive file properties for files.
// Requests additional properties for files.
// |fileUrls| list of URLs of files
// |callback|
static void getDriveEntryProperties(
static void getEntryProperties(
DOMString[] fileUrls,
GetDriveEntryPropertiesCallback callback);
GetEntryPropertiesCallback callback);
// Pins/unpins a Drive file in the cache.
// |fileUrl| URL of a file to pin/unpin.
......
......@@ -135,7 +135,7 @@ enum HistogramValue {
DELETED_FILEBROWSERPRIVATE_CLEARDRIVECACHE,
SERIAL_GETCONTROLSIGNALS,
DEVELOPERPRIVATE_ENABLE,
FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES,
FILEBROWSERPRIVATE_GETENTRYPROPERTIES,
USB_FINDDEVICES,
BOOKMARKMANAGERPRIVATE_DROP,
DELETED_FILEBROWSERPRIVATE_GETFILETRANSFERS,
......
......@@ -40356,7 +40356,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="74" label="DELETED_FILEBROWSERPRIVATE_CLEARDRIVECACHE"/>
<int value="75" label="SERIAL_GETCONTROLSIGNALS"/>
<int value="76" label="DEVELOPERPRIVATE_ENABLE"/>
<int value="77" label="FILEBROWSERPRIVATE_GETDRIVEFILEPROPERTIES"/>
<int value="77" label="FILEBROWSERPRIVATE_GETENTRYPROPERTIES"/>
<int value="78" label="USB_FINDDEVICES"/>
<int value="79" label="BOOKMARKMANAGERPRIVATE_DROP"/>
<int value="80" label="DELETED_FILEBROWSERPRIVATE_GETFILETRANSFERS"/>
......@@ -263,7 +263,7 @@ FileTransferController.prototype = {
var processFileEntries = function(entries) {
return new Promise(function(callback) {
var urls = util.entriesToURLs(entries);
chrome.fileBrowserPrivate.getDriveEntryProperties(urls, callback);
chrome.fileBrowserPrivate.getEntryProperties(urls, callback);
}).
then(function(metadatas) {
return entries.filter(function(entry, i) {
......
......@@ -838,9 +838,9 @@ DriveProvider.prototype.callApi_ = function() {
this.callbacks_ = [];
var self = this;
// TODO(mtomasz): Make getDriveEntryProperties accept Entry instead of URL.
// TODO(mtomasz): Make getEntryProperties accept Entry instead of URL.
var entryURLs = util.entriesToURLs(entries);
chrome.fileBrowserPrivate.getDriveEntryProperties(
chrome.fileBrowserPrivate.getEntryProperties(
entryURLs,
function(propertiesList) {
console.assert(propertiesList.length === callbacks.length);
......
......@@ -105,7 +105,7 @@ MediaManager.prototype.getMime = function() {
return Promise.resolve(this.cachedDriveProp_.thumbnailUrl);
return new Promise(function(fulfill, reject) {
chrome.fileBrowserPrivate.getDriveEntryProperties(
chrome.fileBrowserPrivate.getEntryProperties(
[this.entry_.toURL()], fulfill);
}.bind(this)).then(function(props) {
if (!props || !props[0] || !props[0].contentMimeType) {
......@@ -128,7 +128,7 @@ MediaManager.prototype.getThumbnail = function() {
return Promise.resolve(this.cachedDriveProp_.thumbnailUrl);
return new Promise(function(fulfill, reject) {
chrome.fileBrowserPrivate.getDriveEntryProperties(
chrome.fileBrowserPrivate.getEntryProperties(
[this.entry_.toURL()], fulfill);
}.bind(this)).then(function(props) {
if (!props || !props[0] || !props[0].thumbnailUrl) {
......
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