fileSystemProvider: First cut at implementing fileSystemProvider API

Implement fileSystemProvider.mount() that does not do anything meaningful
yet. The purpose of this patch is to add boilerplate files so adding new
code is easier.

Design doc of the API: http://goo.gl/lLXJYQ

BUG=248427
TEST=none
[email protected], [email protected]
[email protected]
# TBR thestig@ for chrome/renderer/resources/renderer_resources.grd

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233799 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/chrome/browser/chromeos/extensions/file_system_provider/OWNERS b/chrome/browser/chromeos/extensions/file_system_provider/OWNERS
new file mode 100644
index 0000000..159f992
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_system_provider/OWNERS
@@ -0,0 +1 @@
[email protected]
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
new file mode 100644
index 0000000..0d9fc0dd
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.cc
@@ -0,0 +1,63 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h"
+
+#include "chrome/common/extensions/api/file_system_provider.h"
+
+namespace extensions {
+
+namespace {
+
+// Error names from
+// http://www.w3.org/TR/file-system-api/#errors-and-exceptions
+const char kSecurityErrorName[] = "SecurityError";
+
+// Error messages.
+const char kEmptyNameErrorMessage[] = "Empty display name is not allowed";
+
+// Creates a dictionary, which looks like a DOMError. The returned dictionary
+// will be converted to a real DOMError object in
+// file_system_provier_custom_bindings.js.
+base::DictionaryValue* CreateError(const std::string& name,
+                                   const std::string& message) {
+  base::DictionaryValue* error = new base::DictionaryValue();
+  error->SetString("name", name);
+  error->SetString("message", message);
+  return error;
+}
+
+}  // namespace
+
+bool FileSystemProviderMountFunction::RunImpl() {
+  using extensions::api::file_system_provider::Mount::Params;
+  const scoped_ptr<Params> params(Params::Create(*args_));
+  EXTENSION_FUNCTION_VALIDATE(params);
+
+  // It's an error if the display name is empty.
+  if (params->display_name.empty()) {
+    const std::string file_system_id = "";
+
+    base::ListValue* result = new base::ListValue();
+    result->Append(new base::StringValue(file_system_id));
+    result->Append(CreateError(kSecurityErrorName,
+                               kEmptyNameErrorMessage));
+    SetResult(result);
+    SendResponse(true);
+    return true;
+  }
+
+  // TODO(satorux): Implement the real logic.
+  const std::string file_system_id = params->display_name;
+
+  base::ListValue* result = new base::ListValue();
+  result->Append(new base::StringValue(file_system_id));
+  // Don't append an error on success.
+
+  SetResult(result);
+  SendResponse(true);
+  return true;
+}
+
+}  // namespace extensions
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
new file mode 100644
index 0000000..ae14ca2
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_api.h
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PROVIDER_API_H_
+#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PROVIDER_API_H_
+
+#include "chrome/browser/extensions/chrome_extension_function.h"
+#include "chrome/common/extensions/api/file_system_provider.h"
+
+namespace extensions {
+
+class FileSystemProviderMountFunction : public ChromeAsyncExtensionFunction {
+ public:
+  DECLARE_EXTENSION_FUNCTION("fileSystemProvider.mount",
+                             FILESYSTEMPROVIDER_MOUNT)
+
+ protected:
+  virtual ~FileSystemProviderMountFunction() {}
+  virtual bool RunImpl() OVERRIDE;
+};
+
+}  // namespace extensions
+
+#endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_FILE_SYSTEM_PROVIDER_API_H_
diff --git a/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_apitest.cc b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_apitest.cc
new file mode 100644
index 0000000..8c94114
--- /dev/null
+++ b/chrome/browser/chromeos/extensions/file_system_provider/file_system_provider_apitest.cc
@@ -0,0 +1,25 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/extensions/extension_apitest.h"
+
+namespace extensions {
+
+class FileSystemProviderApiTest : public ExtensionApiTest {
+ public:
+  FileSystemProviderApiTest()
+      // Set the channel to "trunk" since this API is restricted to trunk.
+      : current_channel_(chrome::VersionInfo::CHANNEL_UNKNOWN) {
+  }
+
+ private:
+  extensions::ScopedCurrentChannel current_channel_;
+};
+
+IN_PROC_BROWSER_TEST_F(FileSystemProviderApiTest, Mount) {
+  ASSERT_TRUE(RunPlatformAppTest("file_system_provider/mount"))
+      << message_;
+}
+
+}  // namespace extensions
diff --git a/chrome/browser/extensions/extension_function_histogram_value.h b/chrome/browser/extensions/extension_function_histogram_value.h
index 5ed24f89..ba217ad 100644
--- a/chrome/browser/extensions/extension_function_histogram_value.h
+++ b/chrome/browser/extensions/extension_function_histogram_value.h
@@ -686,6 +686,7 @@
   CHROMEOSINFOPRIVATE_SET,
   BOOKMARKMANAGERPRIVATE_GETMETAINFO,
   BOOKMARKMANAGERPRIVATE_SETMETAINFO,
+  FILESYSTEMPROVIDER_MOUNT,
   ENUM_BOUNDARY // Last entry: Add new entries above.
 };