| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTIO
N_H_ | 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_ | 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNCTIO
N_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // These values are passed to JavaScript as lastError.message value. | 43 // These values are passed to JavaScript as lastError.message value. |
| 44 std::string FileErrorToString(base::File::Error error); | 44 std::string FileErrorToString(base::File::Error error); |
| 45 | 45 |
| 46 // Converts ProviderError to base::File::Error. This could be redundant, if it | 46 // Converts ProviderError to base::File::Error. This could be redundant, if it |
| 47 // was possible to create DOMError instances in Javascript easily. | 47 // was possible to create DOMError instances in Javascript easily. |
| 48 base::File::Error ProviderErrorToFileError( | 48 base::File::Error ProviderErrorToFileError( |
| 49 api::file_system_provider::ProviderError error); | 49 api::file_system_provider::ProviderError error); |
| 50 | 50 |
| 51 // Base class for internal API functions handling request results, either | 51 // Base class for internal API functions handling request results, either |
| 52 // a success or a failure. | 52 // a success or a failure. |
| 53 class FileSystemProviderInternalFunction : public ChromeSyncExtensionFunction { | 53 class FileSystemProviderInternalFunction : public UIThreadExtensionFunction { |
| 54 public: | 54 public: |
| 55 FileSystemProviderInternalFunction(); | 55 FileSystemProviderInternalFunction(); |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 ~FileSystemProviderInternalFunction() override {} | 58 ~FileSystemProviderInternalFunction() override {} |
| 59 | 59 |
| 60 // Rejects the request and sets a response for this API function. Returns true | 60 // Rejects the request and returns a response for this API function. |
| 61 // on success, and false on failure. | 61 ResponseAction RejectRequest( |
| 62 bool RejectRequest( | |
| 63 std::unique_ptr<chromeos::file_system_provider::RequestValue> value, | 62 std::unique_ptr<chromeos::file_system_provider::RequestValue> value, |
| 64 base::File::Error error); | 63 base::File::Error error); |
| 65 | 64 |
| 66 // Fulfills the request with parsed arguments of this API function | 65 // Fulfills the request with parsed arguments of this API function |
| 67 // encapsulated as a RequestValue instance. Also, sets a response. | 66 // encapsulated as a RequestValue instance and returns a response. |
| 68 // If |has_more| is set to true, then the function will be called again for | 67 // 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. | 68 // this request. |
| 70 bool FulfillRequest( | 69 ResponseAction FulfillRequest( |
| 71 std::unique_ptr<chromeos::file_system_provider::RequestValue> value, | 70 std::unique_ptr<chromeos::file_system_provider::RequestValue> value, |
| 72 bool has_more); | 71 bool has_more); |
| 73 | 72 |
| 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; | |
| 78 | |
| 79 // ChromeSyncExtensionFunction overrides. | |
| 80 bool RunSync() override; | |
| 81 | |
| 82 private: | 73 private: |
| 83 // Parses the request in order to extract the request manager. If fails, then | 74 // Guarantees |request_id_| and |request_manager_| are valid. |
| 84 // sets a response and returns false. | 75 bool PreRunValidation(std::string* error) override; |
| 85 bool Parse(); | |
| 86 | 76 |
| 87 int request_id_; | 77 int request_id_; |
| 88 chromeos::file_system_provider::RequestManager* request_manager_; | 78 chromeos::file_system_provider::RequestManager* request_manager_; |
| 89 }; | 79 }; |
| 90 | 80 |
| 91 } // namespace extensions | 81 } // namespace extensions |
| 92 | 82 |
| 93 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNC
TION_H_ | 83 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_SYSTEM_PROVIDER_PROVIDER_FUNC
TION_H_ |
| OLD | NEW |