OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/files/file.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "chrome/browser/chromeos/file_system_provider/observer.h" |
| 15 #include "chrome/browser/chromeos/file_system_provider/provided_file_system.h" |
| 16 |
| 17 namespace base { |
| 18 class DictionaryValue; |
| 19 } // namespace base |
| 20 |
| 21 namespace chromeos { |
| 22 namespace file_system_provider { |
| 23 |
| 24 typedef base::Callback<void(scoped_ptr<base::DictionaryValue>, bool has_next)> |
| 25 SuccessCallback; |
| 26 typedef base::Callback<void(base::File::Error)> ErrorCallback; |
| 27 |
| 28 // Manages requests between the service, async utils and the providing |
| 29 // extensions. |
| 30 class RequestManager : public Observer { |
| 31 public: |
| 32 RequestManager(); |
| 33 virtual ~RequestManager(); |
| 34 |
| 35 // Creates a request and returns its request id (greater than 0). Returns 0 in |
| 36 // case of an error (eg. too many requests). The passed callbacks can be NULL. |
| 37 int CreateRequest(const ProvidedFileSystem& file_system, |
| 38 const SuccessCallback& success_callback, |
| 39 const ErrorCallback& error_callback); |
| 40 |
| 41 // Handles successful response for the |request_id|. If |has_next| is false, |
| 42 // then the request is disposed, after handling the |response|. On error, |
| 43 // returns false, and the request is disposed. |
| 44 bool FulfillRequest(const ProvidedFileSystem& file_system, |
| 45 int request_id, |
| 46 scoped_ptr<base::DictionaryValue> response, |
| 47 bool has_next); |
| 48 |
| 49 // Handles error response for the |request_id|. If handling the error fails, |
| 50 // returns false. Always disposes the request. |
| 51 bool RejectRequest(const ProvidedFileSystem& file_system, |
| 52 int request_id, |
| 53 base::File::Error error); |
| 54 |
| 55 // file_system_provider::Observer overrides. |
| 56 virtual void OnProvidedFileSystemMount(const ProvidedFileSystem& file_system, |
| 57 base::File::Error error) OVERRIDE; |
| 58 virtual void OnProvidedFileSystemUnmount( |
| 59 const ProvidedFileSystem& file_system, |
| 60 base::File::Error error) OVERRIDE; |
| 61 |
| 62 private: |
| 63 struct Request { |
| 64 // Provided file system handling the request. |
| 65 ProvidedFileSystem file_system; |
| 66 |
| 67 // Callback to be called on success. |
| 68 SuccessCallback success_callback; |
| 69 |
| 70 // Callback to be called on error. |
| 71 ErrorCallback error_callback; |
| 72 }; |
| 73 |
| 74 typedef std::map<int, Request> RequestMap; |
| 75 |
| 76 RequestMap requests_; |
| 77 int next_id_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(RequestManager); |
| 80 }; |
| 81 |
| 82 } // namespace file_system_provider |
| 83 } // namespace chromeos |
| 84 |
| 85 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_REQUEST_MANAGER_H_ |
OLD | NEW |