1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTION_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTION_H_
10 #include "base/files/file.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/extensions/chrome_extension_function.h"
13 #include "chrome/common/extensions/api/file_system_provider.h"
16 class DictionaryValue
;
20 namespace file_system_provider
{
25 } // namespace file_system_provider
26 } // namespace chromeos
28 namespace extensions
{
31 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions
32 extern const char kNotFoundErrorName
[];
33 extern const char kSecurityErrorName
[];
36 extern const char kEmptyNameErrorMessage
[];
37 extern const char kEmptyIdErrorMessage
[];
38 extern const char kMountFailedErrorMessage
[];
39 extern const char kUnmountFailedErrorMessage
[];
40 extern const char kResponseFailedErrorMessage
[];
42 // Creates an identifier from |error|. For FILE_OK, an empty string is returned.
43 // These values are passed to JavaScript as lastError.message value.
44 std::string
FileErrorToString(base::File::Error error
);
46 // Converts ProviderError to base::File::Error. This could be redundant, if it
47 // was possible to create DOMError instances in Javascript easily.
48 base::File::Error
ProviderErrorToFileError(
49 api::file_system_provider::ProviderError error
);
51 // Base class for internal API functions handling request results, either
52 // a success or a failure.
53 class FileSystemProviderInternalFunction
: public ChromeSyncExtensionFunction
{
55 FileSystemProviderInternalFunction();
58 ~FileSystemProviderInternalFunction() override
{}
60 // Rejects the request and sets a response for this API function. Returns true
61 // on success, and false on failure.
63 scoped_ptr
<chromeos::file_system_provider::RequestValue
> value
,
64 base::File::Error error
);
66 // Fulfills the request with parsed arguments of this API function
67 // encapsulated as a RequestValue instance. Also, sets a response.
68 // If |has_more| is set to true, then the function will be called again for
69 // this request. Returns true on success, and false on failure.
71 scoped_ptr
<chromeos::file_system_provider::RequestValue
> value
,
74 // Subclasses implement this for their functionality.
75 // Called after Parse() is successful, such that |request_id_| and
76 // |request_manager_| have been fully initialized.
77 virtual bool RunWhenValid() = 0;
79 // ChromeSyncExtensionFunction overrides.
80 bool RunSync() override
;
83 // Parses the request in order to extract the request manager. If fails, then
84 // sets a response and returns false.
88 chromeos::file_system_provider::RequestManager
* request_manager_
;
91 } // namespace extensions
93 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTION_H_