| 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 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file.h" | 12 #include "base/files/file.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/time/time.h" |
| 16 #include "base/timer/timer.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" | 17 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info
.h" |
| 15 | 18 |
| 16 namespace base { | 19 namespace base { |
| 17 class DictionaryValue; | 20 class DictionaryValue; |
| 18 } // namespace base | 21 } // namespace base |
| 19 | 22 |
| 20 namespace chromeos { | 23 namespace chromeos { |
| 21 namespace file_system_provider { | 24 namespace file_system_provider { |
| 22 | 25 |
| 23 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> result, | 26 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> result, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 40 // then the request is disposed, after handling the |response|. On error, | 43 // then the request is disposed, after handling the |response|. On error, |
| 41 // returns false, and the request is disposed. | 44 // returns false, and the request is disposed. |
| 42 bool FulfillRequest(int request_id, | 45 bool FulfillRequest(int request_id, |
| 43 scoped_ptr<base::DictionaryValue> response, | 46 scoped_ptr<base::DictionaryValue> response, |
| 44 bool has_next); | 47 bool has_next); |
| 45 | 48 |
| 46 // Handles error response for the |request_id|. If handling the error fails, | 49 // Handles error response for the |request_id|. If handling the error fails, |
| 47 // returns false. Always disposes the request. | 50 // returns false. Always disposes the request. |
| 48 bool RejectRequest(int request_id, base::File::Error error); | 51 bool RejectRequest(int request_id, base::File::Error error); |
| 49 | 52 |
| 53 // Sets a custom timeout for tests. The new timeout value will be applied to |
| 54 // new requests |
| 55 void SetTimeoutForTests(const base::TimeDelta& timeout); |
| 56 |
| 50 private: | 57 private: |
| 51 struct Request { | 58 struct Request { |
| 52 Request(); | 59 Request(); |
| 53 ~Request(); | 60 ~Request(); |
| 54 | 61 |
| 62 // Timer for discarding the request during a timeout. |
| 63 base::OneShotTimer<RequestManager> timeout_timer; |
| 64 |
| 55 // Callback to be called on success. | 65 // Callback to be called on success. |
| 56 SuccessCallback success_callback; | 66 SuccessCallback success_callback; |
| 57 | 67 |
| 58 // Callback to be called on error. | 68 // Callback to be called on error. |
| 59 ErrorCallback error_callback; | 69 ErrorCallback error_callback; |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(Request); |
| 60 }; | 73 }; |
| 61 | 74 |
| 62 typedef std::map<int, Request> RequestMap; | 75 typedef std::map<int, Request*> RequestMap; |
| 76 |
| 77 // Called when a request with |request_id| timeouts. |
| 78 void OnRequestTimeout(int request_id); |
| 63 | 79 |
| 64 RequestMap requests_; | 80 RequestMap requests_; |
| 65 int next_id_; | 81 int next_id_; |
| 82 base::TimeDelta timeout_; |
| 83 base::WeakPtrFactory<RequestManager> weak_ptr_factory_; |
| 66 | 84 |
| 67 DISALLOW_COPY_AND_ASSIGN(RequestManager); | 85 DISALLOW_COPY_AND_ASSIGN(RequestManager); |
| 68 }; | 86 }; |
| 69 | 87 |
| 70 } // namespace file_system_provider | 88 } // namespace file_system_provider |
| 71 } // namespace chromeos | 89 } // namespace chromeos |
| 72 | 90 |
| 73 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 91 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| OLD | NEW |