Chromium Code Reviews| 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/scoped_ptr.h" | |
| 
 
hashimoto
2014/04/18 05:28:09
nit: This line is duplicated.
 
mtomasz
2014/04/18 05:56:18
Done.
 
 | |
| 15 #include "base/timer/timer.h" | |
| 14 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" | 16 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info .h" | 
| 15 | 17 | 
| 16 namespace base { | 18 namespace base { | 
| 17 class DictionaryValue; | 19 class DictionaryValue; | 
| 18 } // namespace base | 20 } // namespace base | 
| 19 | 21 | 
| 20 namespace chromeos { | 22 namespace chromeos { | 
| 21 namespace file_system_provider { | 23 namespace file_system_provider { | 
| 22 | 24 | 
| 23 typedef base::Callback<void(scoped_ptr<base::DictionaryValue> result, | 25 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, | 42 // then the request is disposed, after handling the |response|. On error, | 
| 41 // returns false, and the request is disposed. | 43 // returns false, and the request is disposed. | 
| 42 bool FulfillRequest(int request_id, | 44 bool FulfillRequest(int request_id, | 
| 43 scoped_ptr<base::DictionaryValue> response, | 45 scoped_ptr<base::DictionaryValue> response, | 
| 44 bool has_next); | 46 bool has_next); | 
| 45 | 47 | 
| 46 // Handles error response for the |request_id|. If handling the error fails, | 48 // Handles error response for the |request_id|. If handling the error fails, | 
| 47 // returns false. Always disposes the request. | 49 // returns false. Always disposes the request. | 
| 48 bool RejectRequest(int request_id, base::File::Error error); | 50 bool RejectRequest(int request_id, base::File::Error error); | 
| 49 | 51 | 
| 52 // Sets a custom timeout in milliseconds for tests. The new timeout value will | |
| 53 // be applied to new requests | |
| 54 void SetTimeoutForTests(int timeout); | |
| 55 | |
| 50 private: | 56 private: | 
| 51 struct Request { | 57 struct Request { | 
| 52 Request(); | 58 Request(); | 
| 53 ~Request(); | 59 ~Request(); | 
| 54 | 60 | 
| 61 // Timer for discarding the request during a timeout. | |
| 62 base::OneShotTimer<RequestManager> timeout_timer; | |
| 63 | |
| 55 // Callback to be called on success. | 64 // Callback to be called on success. | 
| 56 SuccessCallback success_callback; | 65 SuccessCallback success_callback; | 
| 57 | 66 | 
| 58 // Callback to be called on error. | 67 // Callback to be called on error. | 
| 59 ErrorCallback error_callback; | 68 ErrorCallback error_callback; | 
| 69 | |
| 70 private: | |
| 71 DISALLOW_COPY_AND_ASSIGN(Request); | |
| 60 }; | 72 }; | 
| 61 | 73 | 
| 62 typedef std::map<int, Request> RequestMap; | 74 typedef std::map<int, Request*> RequestMap; | 
| 75 | |
| 76 // Called when a request with |request_id| timeouts. | |
| 77 void OnRequestTimeout(int request_id); | |
| 63 | 78 | 
| 64 RequestMap requests_; | 79 RequestMap requests_; | 
| 65 int next_id_; | 80 int next_id_; | 
| 81 int timeout_; | |
| 
 
hashimoto
2014/04/18 05:28:09
Why don't you use base::TimeDelta which takes care
 
mtomasz
2014/04/18 05:56:18
Done.
 
 | |
| 66 | 82 | 
| 67 DISALLOW_COPY_AND_ASSIGN(RequestManager); | 83 DISALLOW_COPY_AND_ASSIGN(RequestManager); | 
| 68 }; | 84 }; | 
| 69 | 85 | 
| 70 } // namespace file_system_provider | 86 } // namespace file_system_provider | 
| 71 } // namespace chromeos | 87 } // namespace chromeos | 
| 72 | 88 | 
| 73 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 89 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ | 
| OLD | NEW |