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