summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormtomasz <mtomasz@chromium.org>2015-01-18 19:42:55 -0800
committerCommit bot <commit-bot@chromium.org>2015-01-19 03:44:43 +0000
commitbdf88951860ff4ed1df66f632416b19a39aa2469 (patch)
tree0d6674bdb305abb34e00c25fac9388423da3c018
parentfff0165c776981aaa9cc045b2dc9761d46128dab (diff)
downloadchromium_src-bdf88951860ff4ed1df66f632416b19a39aa2469.zip
chromium_src-bdf88951860ff4ed1df66f632416b19a39aa2469.tar.gz
chromium_src-bdf88951860ff4ed1df66f632416b19a39aa2469.tar.bz2
[fsp] Implement the chrome.fileSystemProvider.get() method.
Providing extensions may want to get file system information for the specific file system. This CL adds such feature. TEST=browser_tests: *FileSystemProvider*GetAll* BUG=449014 Review URL: https://codereview.chromium.org/856433003 Cr-Commit-Position: refs/heads/master@{#312058}
-rw-r--r--chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc75
-rw-r--r--chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h9
-rw-r--r--chrome/common/extensions/api/file_system_provider.idl7
-rw-r--r--chrome/test/data/extensions/api_test/file_system_provider/get_all/test.js16
-rw-r--r--extensions/browser/extension_function_histogram_value.h1
-rw-r--r--tools/metrics/histograms/histograms.xml1
6 files changed, 88 insertions, 21 deletions
diff --git a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc
index 8a6f3b8..00909bb 100644
--- a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc
@@ -25,6 +25,7 @@ using chromeos::file_system_provider::ProvidedFileSystemInterface;
using chromeos::file_system_provider::ProvidedFileSystemObserver;
using chromeos::file_system_provider::RequestValue;
using chromeos::file_system_provider::Service;
+using chromeos::file_system_provider::Watchers;
namespace extensions {
namespace {
@@ -68,6 +69,31 @@ scoped_ptr<ProvidedFileSystemObserver::Changes> ParseChanges(
return results;
}
+// Fills the IDL's FileSystemInfo with FSP's ProvidedFileSystemInfo and
+// Watchers.
+void FillFileSystemInfo(const ProvidedFileSystemInfo& file_system_info,
+ const Watchers& watchers,
+ api::file_system_provider::FileSystemInfo* output) {
+ using api::file_system_provider::Watcher;
+
+ output->file_system_id = file_system_info.file_system_id();
+ output->display_name = file_system_info.display_name();
+ output->writable = file_system_info.writable();
+ output->opened_files_limit = file_system_info.opened_files_limit();
+
+ std::vector<linked_ptr<Watcher>> watcher_items;
+ for (const auto& watcher : watchers) {
+ const linked_ptr<Watcher> watcher_item(new Watcher);
+ watcher_item->entry_path = watcher.second.entry_path.value();
+ watcher_item->recursive = watcher.second.recursive;
+ if (!watcher.second.last_tag.empty())
+ watcher_item->last_tag.reset(new std::string(watcher.second.last_tag));
+ watcher_items.push_back(watcher_item);
+ }
+
+ output->watchers = watcher_items;
+}
+
} // namespace
bool FileSystemProviderMountFunction::RunSync() {
@@ -137,7 +163,6 @@ bool FileSystemProviderUnmountFunction::RunSync() {
bool FileSystemProviderGetAllFunction::RunSync() {
using api::file_system_provider::FileSystemInfo;
- using api::file_system_provider::Watcher;
Service* const service = Service::Get(GetProfile());
DCHECK(service);
@@ -148,10 +173,6 @@ bool FileSystemProviderGetAllFunction::RunSync() {
for (const auto& file_system_info : file_systems) {
if (file_system_info.extension_id() == extension_id()) {
const linked_ptr<FileSystemInfo> item(new FileSystemInfo);
- item->file_system_id = file_system_info.file_system_id();
- item->display_name = file_system_info.display_name();
- item->writable = file_system_info.writable();
- item->opened_files_limit = file_system_info.opened_files_limit();
chromeos::file_system_provider::ProvidedFileSystemInterface* const
file_system =
@@ -159,22 +180,8 @@ bool FileSystemProviderGetAllFunction::RunSync() {
file_system_info.file_system_id());
DCHECK(file_system);
- std::vector<linked_ptr<Watcher>> watcher_items;
- chromeos::file_system_provider::Watchers* const watchers =
- file_system->GetWatchers();
- DCHECK(watchers);
-
- for (const auto& watcher : *watchers) {
- const linked_ptr<Watcher> watcher_item(new Watcher);
- watcher_item->entry_path = watcher.second.entry_path.value();
- watcher_item->recursive = watcher.second.recursive;
- if (!watcher.second.last_tag.empty())
- watcher_item->last_tag.reset(
- new std::string(watcher.second.last_tag));
- watcher_items.push_back(watcher_item);
- }
-
- item->watchers = watcher_items;
+ FillFileSystemInfo(file_system_info, *file_system->GetWatchers(),
+ item.get());
items.push_back(item);
}
}
@@ -183,6 +190,32 @@ bool FileSystemProviderGetAllFunction::RunSync() {
return true;
}
+bool FileSystemProviderGetFunction::RunSync() {
+ using api::file_system_provider::Get::Params;
+ scoped_ptr<Params> params(Params::Create(*args_));
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ using api::file_system_provider::FileSystemInfo;
+ Service* const service = Service::Get(GetProfile());
+ DCHECK(service);
+
+ chromeos::file_system_provider::ProvidedFileSystemInterface* const
+ file_system = service->GetProvidedFileSystem(extension_id(),
+ params->file_system_id);
+
+ if (!file_system) {
+ SetError(FileErrorToString(base::File::FILE_ERROR_NOT_FOUND));
+ return false;
+ }
+
+ FileSystemInfo file_system_info;
+ FillFileSystemInfo(file_system->GetFileSystemInfo(),
+ *file_system->GetWatchers(), &file_system_info);
+ SetResultList(
+ api::file_system_provider::Get::Results::Create(file_system_info));
+ return true;
+}
+
bool FileSystemProviderNotifyFunction::RunAsync() {
using api::file_system_provider::Notify::Params;
scoped_ptr<Params> params(Params::Create(*args_));
diff --git a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h
index 22f43b7..592bb6e 100644
--- a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h
@@ -40,6 +40,15 @@ class FileSystemProviderGetAllFunction : public ChromeSyncExtensionFunction {
bool RunSync() override;
};
+class FileSystemProviderGetFunction : public ChromeSyncExtensionFunction {
+ public:
+ DECLARE_EXTENSION_FUNCTION("fileSystemProvider.get", FILESYSTEMPROVIDER_GET)
+
+ protected:
+ ~FileSystemProviderGetFunction() override {}
+ virtual bool RunSync() override;
+};
+
class FileSystemProviderNotifyFunction : public ChromeAsyncExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("fileSystemProvider.notify",
diff --git a/chrome/common/extensions/api/file_system_provider.idl b/chrome/common/extensions/api/file_system_provider.idl
index ca99320..b04ac0a 100644
--- a/chrome/common/extensions/api/file_system_provider.idl
+++ b/chrome/common/extensions/api/file_system_provider.idl
@@ -397,6 +397,9 @@ namespace fileSystemProvider {
// Callback to receive the result of getAll() function.
callback GetAllCallback = void(FileSystemInfo[] fileSystems);
+ // Callback to receive the result of get() function.
+ callback GetCallback = void(FileSystemInfo fileSystem);
+
// Callback to be called by the providing extension in case of a success.
[nocompile] callback ProviderSuccessCallback = void();
@@ -450,6 +453,10 @@ namespace fileSystemProvider {
// Returns all file systems mounted by the extension.
static void getAll(GetAllCallback callback);
+ // Returns information about a file system with the passed <code>
+ // fileSystemId</code>.
+ static void get(DOMString fileSystemId, GetCallback callback);
+
// Notifies about changes in the watched directory at <code>
// observedPath</code> in <code>recursive</code mode. If the file system is
// mounted with <code>supportsNofityTag</code>, then <code>tag</code> must
diff --git a/chrome/test/data/extensions/api_test/file_system_provider/get_all/test.js b/chrome/test/data/extensions/api_test/file_system_provider/get_all/test.js
index ae1036d..d9e84dc 100644
--- a/chrome/test/data/extensions/api_test/file_system_provider/get_all/test.js
+++ b/chrome/test/data/extensions/api_test/file_system_provider/get_all/test.js
@@ -28,6 +28,16 @@ chrome.test.runTests([
chrome.test.assertTrue(fileSystems[0].writable);
chrome.test.assertEq(2, fileSystems[0].openedFilesLimit);
}));
+ chrome.fileSystemProvider.get(
+ test_util.FILE_SYSTEM_ID,
+ chrome.test.callbackPass(function(fileSystem) {
+ chrome.test.assertEq(
+ test_util.FILE_SYSTEM_ID, fileSystem.fileSystemId);
+ chrome.test.assertEq(
+ test_util.FILE_SYSTEM_NAME, fileSystem.displayName);
+ chrome.test.assertTrue(fileSystem.writable);
+ chrome.test.assertEq(2, fileSystem.openedFilesLimit);
+ }));
}));
},
@@ -41,6 +51,9 @@ chrome.test.runTests([
function(fileSystems) {
chrome.test.assertEq(0, fileSystems.length);
}));
+ chrome.fileSystemProvider.get(
+ test_util.FILE_SYSTEM_ID,
+ chrome.test.callbackFail('NOT_FOUND'));
}));
},
@@ -54,6 +67,9 @@ chrome.test.runTests([
function(fileSystems) {
chrome.test.assertEq(0, fileSystems.length);
}));
+ chrome.fileSystemProvider.get(
+ test_util.FILE_SYSTEM_ID,
+ chrome.test.callbackFail('NOT_FOUND'));
}));
}
]);
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index 413cf77..dc9d407 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -1009,6 +1009,7 @@ enum HistogramValue {
PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT,
PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY,
PRINTERPROVIDERINTERNAL_REPORTPRINTERS,
+ FILESYSTEMPROVIDER_GET,
// Last entry: Add new entries above and ensure to update
// tools/metrics/histograms/histograms.xml.
ENUM_BOUNDARY
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index ce3a686..63a508b 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -46783,6 +46783,7 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="948" label="PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT"/>
<int value="949" label="PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY"/>
<int value="950" label="PRINTERPROVIDERINTERNAL_REPORTPRINTERS"/>
+ <int value="951" label="FILESYSTEMPROVIDER_GET"/>
</enum>
<enum name="ExtensionInstallCause" type="int">