OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTIO
N_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTIO
N_H_ |
| 7 #include <string> |
| 8 |
| 9 #include "base/files/file.h" |
| 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/extensions/chrome_extension_function.h" |
| 12 #include "chrome/common/extensions/api/file_system_provider.h" |
| 13 |
| 14 namespace base { |
| 15 class DictionaryValue; |
| 16 } // namespace base |
| 17 |
| 18 namespace chromeos { |
| 19 namespace file_system_provider { |
| 20 |
| 21 class RequestManager; |
| 22 class RequestValue; |
| 23 |
| 24 } // namespace file_system_provider |
| 25 } // namespace chromeos |
| 26 |
| 27 namespace extensions { |
| 28 |
| 29 // Error names from |
| 30 // http://www.w3.org/TR/file-system-api/#errors-and-exceptions |
| 31 extern const char kNotFoundErrorName[]; |
| 32 extern const char kSecurityErrorName[]; |
| 33 |
| 34 // Error messages. |
| 35 extern const char kEmptyNameErrorMessage[]; |
| 36 extern const char kMountFailedErrorMessage[]; |
| 37 extern const char kUnmountFailedErrorMessage[]; |
| 38 extern const char kResponseFailedErrorMessage[]; |
| 39 |
| 40 // Creates a dictionary, which looks like a DOMError. The returned dictionary |
| 41 // will be converted to a real DOMError object in |
| 42 // file_system_provier_custom_bindings.js. |
| 43 base::DictionaryValue* CreateError(const std::string& name, |
| 44 const std::string& message); |
| 45 |
| 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); |
| 50 |
| 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(); |
| 56 |
| 57 protected: |
| 58 virtual ~FileSystemProviderInternalFunction() {} |
| 59 |
| 60 // Rejects the request and sets a response for this API function. |
| 61 void RejectRequest(base::File::Error error); |
| 62 |
| 63 // Fulfills the request with parsed arguments of this API function |
| 64 // encapsulated as a RequestValue instance. Also, sets a response. |
| 65 // If |has_next| is set to true, then the function will be called again for |
| 66 // this request. |
| 67 void FulfillRequest( |
| 68 scoped_ptr<chromeos::file_system_provider::RequestValue> value, |
| 69 bool has_next); |
| 70 |
| 71 // ChromeSyncExtensionFunction overrides. |
| 72 virtual bool RunImpl() OVERRIDE; |
| 73 |
| 74 private: |
| 75 // Parses the request in order to extract the request manager. If fails, then |
| 76 // sets a response and returns false. |
| 77 bool Parse(); |
| 78 |
| 79 // Sets an error message in case of a failure. |
| 80 void SetErrorResponse(const std::string& name, const std::string& message); |
| 81 |
| 82 int request_id_; |
| 83 chromeos::file_system_provider::RequestManager* request_manager_; |
| 84 }; |
| 85 |
| 86 } // namespace extensions |
| 87 |
| 88 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNC
TION_H_ |
OLD | NEW |