Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / chromeos / extensions / file_system_provider / provider_function.h
blob040fdac05b318c4032fd53a021ec078453ea86eb
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_
8 #include <string>
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"
15 namespace base {
16 class DictionaryValue;
17 } // namespace base
19 namespace chromeos {
20 namespace file_system_provider {
22 class RequestManager;
23 class RequestValue;
25 } // namespace file_system_provider
26 } // namespace chromeos
28 namespace extensions {
30 // Error names from
31 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions
32 extern const char kNotFoundErrorName[];
33 extern const char kSecurityErrorName[];
35 // Error messages.
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 {
54 public:
55 FileSystemProviderInternalFunction();
57 protected:
58 ~FileSystemProviderInternalFunction() override {}
60 // Rejects the request and sets a response for this API function. Returns true
61 // on success, and false on failure.
62 bool RejectRequest(
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.
70 bool FulfillRequest(
71 scoped_ptr<chromeos::file_system_provider::RequestValue> value,
72 bool has_more);
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;
82 private:
83 // Parses the request in order to extract the request manager. If fails, then
84 // sets a response and returns false.
85 bool Parse();
87 int request_id_;
88 chromeos::file_system_provider::RequestManager* request_manager_;
91 } // namespace extensions
93 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTION_H_