| 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_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 public: | 26 public: |
| 27 class HandlerInterface { | 27 class HandlerInterface { |
| 28 public: | 28 public: |
| 29 virtual ~HandlerInterface() {} | 29 virtual ~HandlerInterface() {} |
| 30 | 30 |
| 31 // Called when the request is created. Executes the request implementation. | 31 // Called when the request is created. Executes the request implementation. |
| 32 // Returns false in case of a execution failure. | 32 // Returns false in case of a execution failure. |
| 33 virtual bool Execute(int request_id) = 0; | 33 virtual bool Execute(int request_id) = 0; |
| 34 | 34 |
| 35 // Success callback invoked by the providing extension in response to | 35 // Success callback invoked by the providing extension in response to |
| 36 // Execute(). It may be called more than once, until |has_next| is set to | 36 // Execute(). It may be called more than once, until |has_more| is set to |
| 37 // false. | 37 // false. |
| 38 virtual void OnSuccess(int request_id, | 38 virtual void OnSuccess(int request_id, |
| 39 scoped_ptr<RequestValue> result, | 39 scoped_ptr<RequestValue> result, |
| 40 bool has_next) = 0; | 40 bool has_more) = 0; |
| 41 | 41 |
| 42 // Error callback invoked by the providing extension in response to | 42 // Error callback invoked by the providing extension in response to |
| 43 // Execute(). It can be called at most once. It can be also called if the | 43 // Execute(). It can be called at most once. It can be also called if the |
| 44 // request is aborted due to a timeout. | 44 // request is aborted due to a timeout. |
| 45 virtual void OnError(int request_id, base::File::Error error) = 0; | 45 virtual void OnError(int request_id, base::File::Error error) = 0; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 RequestManager(); | 48 RequestManager(); |
| 49 virtual ~RequestManager(); | 49 virtual ~RequestManager(); |
| 50 | 50 |
| 51 // Creates a request and returns its request id (greater than 0). Returns 0 in | 51 // Creates a request and returns its request id (greater than 0). Returns 0 in |
| 52 // case of an error (eg. too many requests). | 52 // case of an error (eg. too many requests). |
| 53 int CreateRequest(scoped_ptr<HandlerInterface> handler); | 53 int CreateRequest(scoped_ptr<HandlerInterface> handler); |
| 54 | 54 |
| 55 // Handles successful response for the |request_id|. If |has_next| is false, | 55 // Handles successful response for the |request_id|. If |has_more| is false, |
| 56 // then the request is disposed, after handling the |response|. On error, | 56 // then the request is disposed, after handling the |response|. On error, |
| 57 // returns false, and the request is disposed. | 57 // returns false, and the request is disposed. |
| 58 bool FulfillRequest(int request_id, | 58 bool FulfillRequest(int request_id, |
| 59 scoped_ptr<RequestValue> response, | 59 scoped_ptr<RequestValue> response, |
| 60 bool has_next); | 60 bool has_more); |
| 61 | 61 |
| 62 // Handles error response for the |request_id|. If handling the error fails, | 62 // Handles error response for the |request_id|. If handling the error fails, |
| 63 // returns false. Always disposes the request. | 63 // returns false. Always disposes the request. |
| 64 bool RejectRequest(int request_id, base::File::Error error); | 64 bool RejectRequest(int request_id, base::File::Error error); |
| 65 | 65 |
| 66 // Sets a custom timeout for tests. The new timeout value will be applied to | 66 // Sets a custom timeout for tests. The new timeout value will be applied to |
| 67 // new requests | 67 // new requests |
| 68 void SetTimeoutForTests(const base::TimeDelta& timeout); | 68 void SetTimeoutForTests(const base::TimeDelta& timeout); |
| 69 | 69 |
| 70 // Gets number of active requests for logging purposes. | 70 // Gets number of active requests for logging purposes. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 96 base::TimeDelta timeout_; | 96 base::TimeDelta timeout_; |
| 97 base::WeakPtrFactory<RequestManager> weak_ptr_factory_; | 97 base::WeakPtrFactory<RequestManager> weak_ptr_factory_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(RequestManager); | 99 DISALLOW_COPY_AND_ASSIGN(RequestManager); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 } // namespace file_system_provider | 102 } // namespace file_system_provider |
| 103 } // namespace chromeos | 103 } // namespace chromeos |
| 104 | 104 |
| 105 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 105 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| OLD | NEW |