drive: Stop calling OpenFileSystem from SearchDriveFunction/SearchDriveMetadataFunction

What FileSystemContext::OpenFileSystem() does is just calling ValidateFileSystemRoot
and CrosMountPointProvider::ValidateFileSystemRoot() does nothing.
Root URI and name of the file system can be acquired with synchronous functions.

BUG=241951
TEST=Can search in Google Drive directory on Files.app

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202040 0039d316-1c4b-4281-b951-d872f2087c98
parent c8fbac34
...@@ -2816,43 +2816,24 @@ bool SearchDriveFunction::RunImpl() { ...@@ -2816,43 +2816,24 @@ bool SearchDriveFunction::RunImpl() {
if (!args_->GetDictionary(0, &search_params)) if (!args_->GetDictionary(0, &search_params))
return false; return false;
if (!search_params->GetString("query", &query_)) std::string query;
if (!search_params->GetString("query", &query))
return false; return false;
if (!search_params->GetString("nextFeed", &next_feed_)) std::string next_feed;
if (!search_params->GetString("nextFeed", &next_feed))
return false; return false;
content::SiteInstance* site_instance = render_view_host()->GetSiteInstance();
BrowserContext::GetStoragePartition(profile(), site_instance)->
GetFileSystemContext()->OpenFileSystem(
source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
base::Bind(&SearchDriveFunction::OnFileSystemOpened, this));
return true;
}
void SearchDriveFunction::OnFileSystemOpened(
base::PlatformFileError result,
const std::string& file_system_name,
const GURL& file_system_url) {
if (result != base::PLATFORM_FILE_OK) {
SendResponse(false);
return;
}
file_system_name_ = file_system_name;
file_system_url_ = file_system_url;
drive::DriveIntegrationService* integration_service = drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_); drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled. // |integration_service| is NULL if Drive is disabled.
if (!integration_service || !integration_service->file_system()) { if (!integration_service || !integration_service->file_system())
SendResponse(false); return false;
return;
}
integration_service->file_system()->Search( integration_service->file_system()->Search(
query_, GURL(next_feed_), query, GURL(next_feed),
base::Bind(&SearchDriveFunction::OnSearch, this)); base::Bind(&SearchDriveFunction::OnSearch, this));
return true;
} }
void SearchDriveFunction::OnSearch( void SearchDriveFunction::OnSearch(
...@@ -2869,10 +2850,16 @@ void SearchDriveFunction::OnSearch( ...@@ -2869,10 +2850,16 @@ void SearchDriveFunction::OnSearch(
base::ListValue* entries = new ListValue(); base::ListValue* entries = new ListValue();
// Convert Drive files to something File API stack can understand. // Convert Drive files to something File API stack can understand.
GURL origin_url = source_url_.GetOrigin();
fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeExternal;
GURL file_system_root_url =
fileapi::GetFileSystemRootURI(origin_url, file_system_type);
std::string file_system_name =
fileapi::GetFileSystemName(origin_url, file_system_type);
for (size_t i = 0; i < results->size(); ++i) { for (size_t i = 0; i < results->size(); ++i) {
DictionaryValue* entry = new DictionaryValue(); DictionaryValue* entry = new DictionaryValue();
entry->SetString("fileSystemName", file_system_name_); entry->SetString("fileSystemName", file_system_name);
entry->SetString("fileSystemRoot", file_system_url_.spec()); entry->SetString("fileSystemRoot", file_system_root_url.spec());
entry->SetString("fileFullPath", "/" + results->at(i).path.value()); entry->SetString("fileFullPath", "/" + results->at(i).path.value());
entry->SetBoolean("fileIsDirectory", entry->SetBoolean("fileIsDirectory",
results->at(i).entry.file_info().is_directory()); results->at(i).entry.file_info().is_directory());
...@@ -2887,8 +2874,7 @@ void SearchDriveFunction::OnSearch( ...@@ -2887,8 +2874,7 @@ void SearchDriveFunction::OnSearch(
SendResponse(true); SendResponse(true);
} }
SearchDriveMetadataFunction::SearchDriveMetadataFunction() SearchDriveMetadataFunction::SearchDriveMetadataFunction() {}
: max_results_(0) {}
SearchDriveMetadataFunction::~SearchDriveMetadataFunction() {} SearchDriveMetadataFunction::~SearchDriveMetadataFunction() {}
...@@ -2897,66 +2883,48 @@ bool SearchDriveMetadataFunction::RunImpl() { ...@@ -2897,66 +2883,48 @@ bool SearchDriveMetadataFunction::RunImpl() {
if (!args_->GetDictionary(0, &search_params)) if (!args_->GetDictionary(0, &search_params))
return false; return false;
if (!search_params->GetString("query", &query_)) std::string query;
if (!search_params->GetString("query", &query))
return false; return false;
if (!search_params->GetString("types", &types_)) std::string types;
if (!search_params->GetString("types", &types))
return false; return false;
if (!search_params->GetInteger("maxResults", &max_results_)) int max_results = 0;
if (!search_params->GetInteger("maxResults", &max_results))
return false; return false;
drive::util::Log("%s[%d] called. (types: '%s', maxResults: '%d')", drive::util::Log("%s[%d] called. (types: '%s', maxResults: '%d')",
name().c_str(), name().c_str(),
request_id(), request_id(),
types_.c_str(), types.c_str(),
max_results_); max_results);
set_log_on_completion(true); set_log_on_completion(true);
content::SiteInstance* site_instance = render_view_host()->GetSiteInstance();
BrowserContext::GetStoragePartition(profile(), site_instance)->
GetFileSystemContext()->OpenFileSystem(
source_url_.GetOrigin(), fileapi::kFileSystemTypeExternal, false,
base::Bind(&SearchDriveMetadataFunction::OnFileSystemOpened, this));
return true;
}
void SearchDriveMetadataFunction::OnFileSystemOpened(
base::PlatformFileError result,
const std::string& file_system_name,
const GURL& file_system_url) {
if (result != base::PLATFORM_FILE_OK) {
SendResponse(false);
return;
}
file_system_name_ = file_system_name;
file_system_url_ = file_system_url;
drive::DriveIntegrationService* integration_service = drive::DriveIntegrationService* integration_service =
drive::DriveIntegrationServiceFactory::GetForProfile(profile_); drive::DriveIntegrationServiceFactory::GetForProfile(profile_);
// |integration_service| is NULL if Drive is disabled. // |integration_service| is NULL if Drive is disabled.
if (!integration_service || !integration_service->file_system()) { if (!integration_service || !integration_service->file_system())
SendResponse(false); return false;
return;
}
int options = drive::SEARCH_METADATA_ALL; int options = drive::SEARCH_METADATA_ALL;
// TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693 // TODO(hirono): Switch to the JSON scheme compiler. http://crbug.com/241693
if (types_ == "EXCLUDE_DIRECTORIES") if (types == "EXCLUDE_DIRECTORIES")
options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES; options = drive::SEARCH_METADATA_EXCLUDE_DIRECTORIES;
else if (types_ == "SHARED_WITH_ME") else if (types == "SHARED_WITH_ME")
options = drive::SEARCH_METADATA_SHARED_WITH_ME; options = drive::SEARCH_METADATA_SHARED_WITH_ME;
else if (types_ == "OFFLINE") else if (types == "OFFLINE")
options = drive::SEARCH_METADATA_OFFLINE; options = drive::SEARCH_METADATA_OFFLINE;
else else
DCHECK_EQ("ALL", types_); DCHECK_EQ("ALL", types);
integration_service->file_system()->SearchMetadata( integration_service->file_system()->SearchMetadata(
query_, query,
options, options,
max_results_, max_results,
base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this)); base::Bind(&SearchDriveMetadataFunction::OnSearchMetadata, this));
return true;
} }
void SearchDriveMetadataFunction::OnSearchMetadata( void SearchDriveMetadataFunction::OnSearchMetadata(
...@@ -2975,13 +2943,19 @@ void SearchDriveMetadataFunction::OnSearchMetadata( ...@@ -2975,13 +2943,19 @@ void SearchDriveMetadataFunction::OnSearchMetadata(
// file_browser_handler_custom_bindings.cc and // file_browser_handler_custom_bindings.cc and
// file_browser_private_custom_bindings.js for how this is magically // file_browser_private_custom_bindings.js for how this is magically
// converted to a FileEntry. // converted to a FileEntry.
GURL origin_url = source_url_.GetOrigin();
fileapi::FileSystemType file_system_type = fileapi::kFileSystemTypeExternal;
GURL file_system_root_url =
fileapi::GetFileSystemRootURI(origin_url, file_system_type);
std::string file_system_name =
fileapi::GetFileSystemName(origin_url, file_system_type);
for (size_t i = 0; i < results->size(); ++i) { for (size_t i = 0; i < results->size(); ++i) {
DictionaryValue* result_dict = new DictionaryValue(); DictionaryValue* result_dict = new DictionaryValue();
// FileEntry fields. // FileEntry fields.
DictionaryValue* entry = new DictionaryValue(); DictionaryValue* entry = new DictionaryValue();
entry->SetString("fileSystemName", file_system_name_); entry->SetString("fileSystemName", file_system_name);
entry->SetString("fileSystemRoot", file_system_url_.spec()); entry->SetString("fileSystemRoot", file_system_root_url.spec());
entry->SetString("fileFullPath", "/" + results->at(i).path.value()); entry->SetString("fileFullPath", "/" + results->at(i).path.value());
entry->SetBoolean("fileIsDirectory", entry->SetBoolean("fileIsDirectory",
results->at(i).entry.file_info().is_directory()); results->at(i).entry.file_info().is_directory());
......
...@@ -656,22 +656,10 @@ class SearchDriveFunction : public AsyncExtensionFunction { ...@@ -656,22 +656,10 @@ class SearchDriveFunction : public AsyncExtensionFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
private: private:
// Callback fo OpenFileSystem called from RunImpl. // Callback for Search().
void OnFileSystemOpened(base::PlatformFileError result,
const std::string& file_system_name,
const GURL& file_system_url);
// Callback for google_apis::SearchAsync called after file system is opened.
void OnSearch(drive::FileError error, void OnSearch(drive::FileError error,
const GURL& next_feed, const GURL& next_feed,
scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths); scoped_ptr<std::vector<drive::SearchResultInfo> > result_paths);
// Query for which the search is being performed.
std::string query_;
std::string next_feed_;
// Information about remote file system we will need to create file entries
// to represent search results.
std::string file_system_name_;
GURL file_system_url_;
}; };
// Similar to SearchDriveFunction but this one is used for searching drive // Similar to SearchDriveFunction but this one is used for searching drive
...@@ -689,30 +677,9 @@ class SearchDriveMetadataFunction : public FileBrowserFunction { ...@@ -689,30 +677,9 @@ class SearchDriveMetadataFunction : public FileBrowserFunction {
virtual bool RunImpl() OVERRIDE; virtual bool RunImpl() OVERRIDE;
private: private:
// Callback fo OpenFileSystem called from RunImpl. // Callback for SearchMetadata();
void OnFileSystemOpened(base::PlatformFileError result, void OnSearchMetadata(drive::FileError error,
const std::string& file_system_name, scoped_ptr<drive::MetadataSearchResultVector> results);
const GURL& file_system_url);
// Callback for LocalSearch().
void OnSearchMetadata(
drive::FileError error,
scoped_ptr<drive::MetadataSearchResultVector> results);
// Query for which the search is being performed.
std::string query_;
// String representing what type of entries are needed. It corresponds to
// SearchMetadataOptions:
// SEARCH_METADATA_OPTION_EXCLUDE_DIRECTORIES => "EXCLUDE_DIRECTORIES"
// SEARCH_METADATA_OPTION_ALL => "ALL"
std::string types_;
// Maximum number of results. The results contains |max_num_results_| entries
// at most.
int max_results_;
// Information about remote file system we will need to create file entries
// to represent search results.
std::string file_system_name_;
GURL file_system_url_;
}; };
class ClearDriveCacheFunction : public AsyncExtensionFunction { class ClearDriveCacheFunction : public AsyncExtensionFunction {
......
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